How to resolve problem with es_extended Fivem (Lua) - lua

i have a problem with es_extended.
I have this error :
SCRIPT ERROR: #es_extended/client/main.lua:64: attempt to index a nil value (field 'coords')
Thank you in advance.

This could be fixed by checking if the coordinates have a value before attempting to teleport the player.
if playerData.coords == nil and playerData.coords.x == nil then playerData.coords = {x = -1070.906250, y = -2972.122803, z = 13.773568} end
ESX.Game.Teleport(PlayerPedId(), {
x = playerData.coords.x,
y = playerData.coords.y,
z = playerData.coords.z + 0.25
}, function()
TriggerServerEvent('esx:onPlayerSpawn')
TriggerEvent('esx:onPlayerSpawn')
TriggerEvent('playerSpawned') -- compatibility with old scripts, will be removed soon
TriggerEvent('esx:restoreLoadout')
Citizen.Wait(3000)
ShutdownLoadingScreen()
FreezeEntityPosition(PlayerPedId(), false)
DoScreenFadeIn(10000)
StartServerSyncLoops()
end)

Related

How can I create a textbox class in love2d that can input data to calculate?

How can I make a text box to be able to enter numbers using them to calculate in love2d ?
steps:
(optional) capture mouse / touch location
store input, in a string variable
sanitize input, make sure there aren't unexpected chars
calculate results, use load(str) then execute that ()
print results
Capturing mouse is optional, only required if your app has more than one function. If it's a single-use app that only calculates what you type in, there's no need for that first step. However, if there are other selectable locations on the screen, you'll need a way to determine that the user desires that input area. There are a few GUI libs that help with this, or you can simply test if it's within the expected screen x,y region.
function love.load()
fontsize = 16
fontname = "font.ttf"
font = love.graphics.newFont( fontname, fontsize )
input_x_min = 20
input_x_max = 400
input_y_min = 20
input_y_max = input_y_min +fontsize *2
allowed_chars = "1234567890()+-*/"
love.keyboard.setTextInput( false )
input_text = "result=" -- for storing input
result = nil -- empty placeholder for now
output_x = 20
output_y = 40
output_limit = 400
end
function love.update(dt)
local x, y = love.mouse.getPosition()
-- could also capture mouseclicks here, and/or get touch events
if x >= input_x_min and x <= input_x_max
and y >= input_y_min and y <= input_y_max then
love.keyboard.setTextInput( true )
else
love.keyboard.setTextInput( false )
input_text = "result=" -- no longer selected, reset input
end
end
function love.textinput(t)
for i = 1, #allowed_chars do -- sanitize input
if allowed_chars :sub(i,i) == t then -- if char is allowed
input_text = input_text ..t -- append what was typed
generate_result, err = load( input_text ) -- "result=3+(2*2)"
if err then print( err )
else generate_result() -- function() return result=3+(2*2) end
end
end
end
end
function love.draw()
love.graphics.printf( input_text, output_x, output_y, input_limit )
love.graphics.printf( result, output_x, output_y, output_limit )
end

Attempting to edit array that contains specific key

So I am trying to edit my config list where it has to edit robbed to true when entity is equal to entity in the list (entities get generated when my script is starting)
Config file
Config.location = {
[1] = {
x = 24.39,
y = -1345.776,
z = 29.49,
h = 267.58,
robbed = false,
entity = nil
},
[2] = {
x = -47.7546,
y = -1759.276,
z = 29.421,
h = 48.035,
robbed = false,
entity = nil
},
}
So this list gets loaded - When [1] has been robbed it should change robbed in [1] if the entity matches.
I would imagine i should do a for loop but i'm still clueless.
As Config.list is a sequence with positive integer keys starting from 1 you can conveniently use the iparis iterator in combination with a generic for loop to check every entry in your list.
for i,v in ipairs(Config.location) do
v.robbed = v.entity == someOtherEntity and true or false
end
Of course your entity entries shouldn't be nil as this wouldn't make sense.

RunState: LUA_ERROR: [string "devils_catacomb"]:1: attempt to call field `get_devil_base' (a nil value)

Hi my english is bad I have a problem
ERROR
SYSERR: Apr 11 14:16:12 :: RunState: LUA_ERROR: [string "devils_catacomb"]:1: attempt to call field `get_devil_base' (a nil value)
SYSERR: Apr 11 14:16:12 :: WriteRunningStateToSyserr: LUA_ERROR: quest >devils_catacomb.start click
SYSERR: Apr 11 14:12:32 :: RunState: LUA_ERROR: >locale/turkey/quest/object/state/deviltower_zone:1: attempt to indexglobal`positions' (a nil value)
SYSERR: Apr 11 14:12:32 :: WriteRunningStateToSyserr: LUA_ERROR: quest >deviltower_zone.start click
my deviltower_zone.lua
////////Error formed location/////////
function get_4floor_stone_pos()
local positions,j,t = {{368, 629}, {419, 630}, {428, 653}, {422, 679},
{395, 689}, {369, 679}, {361, 658},},number(i,7), positions[i];
for i = 1, 6 do
if (i != j) then
local t = positions[i];
positions[i] = positions[j];
positions[j] = t;
end
end
return positions
end
when 8016.kill with pc.get_map_index() >= 660000 and pc.get_map_index() <
670000 begin
d.setf("level", 4)
local positions,vid = deviltower_zone.get_4floor_stone_pos()
,d.spawn_mob(8017, positions[7][1], positions[7][2])
for i = 1, 6 do d.set_unique("fake" .. i , d.spawn_mob(8017,
positions[i][1], positions[i][2])) end
d.set_unique("real", vid)
server_loop_timer('devil_stone4_update', 10, pc.get_map_index())
server_timer('devil_stone4_fail1', 5*60, pc.get_map_index())
notice_multiline(gameforge.deviltower_zone._50_dNotice,d.notice)
end
There are a couple of places where you use the positions table in the right hand side of an attribution to local positions. Lua always evaluates the right hand side fully before the left hand side, so in this context, positions refers to a global variable.
First occurrence: in the line:
local positions,j,t = {{368, 629}, {419, 630}, {428, 653}, {422, 679}, {395, 689}, {369, 679}, {361, 658},},number(i,7), positions[i];
you probably meant:
local positions = {{368, 629}, {419, 630}, {428, 653}, {422, 679}, {395, 689}, {369, 679}, {361, 658},}
local j, t = number(i,7), positions[i]
(although this won't work 100% because i does not exist yet -- it's probably better to just not use the t variable.)
And in this line:
local positions,vid = deviltower_zone.get_4floor_stone_pos(), d.spawn_mob(8017, positions[7][1], positions[7][2])
You probably meant to do something like:
local positions = deviltower_zone.get_4floor_stone_pos()
local vid = d.spawn_mob(8017, positions[7][1], positions[7][2])

for loop help and sprite addition

I have two questions. what I am
trying to do is every time I shoot a enemy/vine it should be
removed and a explosion should occur. the removal works perfect
but the sprite is not called to explode
What's this in the for loop #sections[sectInt]["vines"] ?
Are they parent/ child references? Can someone break this
down to the letter even telling me what the # is?
How can I use my explosion sprite after each vine is destroyed?
I am having a difficult time figuring out how to call every x and y
vine in the for loop to explode when removed.
Code:
local sections = require("sectionData")
local lastSection = 0
function createSection()
--Create a random number. If its eqaul to the last one, random it again.
local sectInt = mR(1,#sections)
if sectInt == lastSection then sectInt = mR(1,#sections) end
lastSection = sectInt
--Get a random section from the sectionData file and then
--Loop through creating everything with the right properties.
local i
-- the random creation of vines throughout the screen
for i=1, #sections[sectInt]["vines"] do
local object = sections[sectInt]["vines"][i]
local vine = display.newImageRect(objectGroup, "images/vine"..object["type"]..".png", object["widthHeight"][1], object["widthHeight"][2])
vine.x = object["position"][1]+(480*object["screen"]); vine.y = object["position"][2]; vine.name = "vine"
local rad = (vine.width*0.5)-8; local height = (vine.height*0.5)-8
local physicsShape = { -rad, -height, rad, -height, rad, height, -rad, height }
physics.addBody( vine, "static", { isSensor = true, shape = physicsShape } )
end
end
-- explosion sprite
options1 =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet1 = graphics.newImageSheet( "images/explosion.png", options1)
playerSprite1 = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
explode = display.newSprite(playerSheet1, playerSprite1)
explode.anchorX = 0.5
explode.anchorY = 1
--player:setReferencePoint(display.BottomCenterReferencePoint)
-- i want to reference the for loop position if each vine so it plays sprite when they are removed
explode.x = "vine.x" ; explode.y = "vine .y"
explode.name = "explode"
explode.position=1
extraGroup:insert(explode)
1) What's this in the for loop #sections[sectInt]["vines"] ? Are they parent/ child references? Can someone break this down to the letter even telling me what the # is?
As I said in my comment the # is table length.
The loop is looping over each bit of "vine" data in the selected segment data (whatever that means exactly in terms of the game) and then creates the objects for those vines.
When it's time to make your vine explode, you play the sprite. If you want to explode every vine, you would have something like:
sheetOptions =
{
width = 96, height = 96,
numFrames = 16,
sheetContentWidth = 480,
sheetContentHeight = 384
}
playerSheet = graphics.newImageSheet( "images/explosion.png", sheetOptions)
spriteSequence = {
{name="explosion", start=1, count=16, time = 400, loopCount = 1 },
}
for i, vine in ipairs(objectGroup) do
local explode = display.newSprite(playerSheet, spriteSequence)
explode.anchorX = 0.5
explode.anchorY = 1
explode.x = vine.x
explode.y = vine.y
explode.name = "explode"
explode.position=1
explode:play()
extraGroup:insert(explode)
end
Note: not tested, let me know of if any issues you can't resolve.
ok so, this is what i did to get my object to have a explosion, for anybody that is having the same issue.
function isShot( event )
print('shot!!!')
if (event.other.class == "enemy") then
if (event.other.name == "limitLine") then
event.target:doRemove() --remove bullet if hits the limitLine
elseif (event.other.name == "vine") then
event.other:doRemove()
spriteExplode(event.other.x, event.other.y) -- this function calls itself & runs the sprite
if event.other.name == "vine" then
if event.other.name == "explode" then
event.other:doRemove() --this removes the explosion sprite
end
end
end
-- remove the bullet & explosion sprite
timer.performWithDelay( 5000, function(event) explode:doRemove(); end, 1 )
event.target:doRemove()
end
return true
end
function spriteExplode( x, y)
explode.isVisible = true
explode:play()
print("play explode")
if (x and y) then -- this is the code that keeps my sprite updating upon removal of vine
explode.x, explode.y = x, y
end
function explode:doRemove(event)
timer.performWithDelay(
1,
function(event)
display.remove(self)
self= nil
end,
1 )
end
end
i added the isShot function eventListener inside of the Bullet function
bullet:addEventListener("collision", isShot) & a bullet:doRemove function is inside the bullet function as well.
hope this helps.

How do I randomly generate numbers with Lua for Corona SDK

I have this simple game that generates a math problem from this, but it is very inefficient as I have to manually make all the problems myself.
Does anyone know some code better than this or direct me to a good tutorial on how to set this up? Thank you.
local M = {}
M["times"] = {
{
question="6 x 5", --The question.
answers={"30", "11", "29", "20"}, --Array of possible answers.
answer=1 --Which one from the above array is the correct answer.
},
}
return M
Update:
{
a = math.random( 1, 20 ),
b = math.random( 1, 20 ),
question = a * b,
answer = math.random( m, n )
}
I thought this would work, but I get this error in the console:
mathQuestions.lua:55: attempt to perform arithmetic on global 'a' (a nil value)
Update #2
--mathQuestions.lua
M["times"] = {
local rnd = function (x) return math.random(1,x) end
M.times = {}
local numQuestions = 10 -- how many questions in your database
for i=1,numQuestions do
local obj =
{
left=math.random(1,10),
right=math.random(1,10),
answers={rnd(100), rnd(100), rnd(100), rnd(100)},
answerIndex=rnd(4) -- will override answer[answerIndex] later
}
obj.answer = obj.left * obj.right
obj.answers[obj.answerIndex] = obj.answer
M.times[i] = obj
end
}
I get this error:
ERROR: Failed to execute new ( params ) function on 'game'
mathQuestions.lua:121: unexpected symbol near 'local'
Try this:
local rnd = function (x) return math.random(1,x) end
M.times = {}
local numQuestions = 10 -- how many questions in your database
for i=1,numQuestions do
local obj =
{
left=math.random(1,10),
right=math.random(1,10),
answers={rnd(100), rnd(100), rnd(100), rnd(100)},
answerIndex=rnd(4) -- will override answer[answerIndex] later
}
obj.answer = obj.left * obj.right
obj.answers[obj.answerIndex] = obj.answer
M.times[i] = obj
end
The only tricky part there is obj.answer: you can't do the multiplication inside the table definition (like answer = a*b in your updated question) because left and right (a and b) are then globals that do not exist, and if you did answer = obj.a*obj.b then you also have problem that obj does not yet exist (it hasn't been created yet).

Resources