Hi,
I am trying to make a script to save how much pizzas the player found.
But i am getting some errors.
This is my code:
--server-side
function onPlayerQuit()
local playerAccount = getPlayerAccount(source)
if (playerAccount) then
for iii = 1, #nPizzaFound do
setAccountData(playerAccount, "xtreme.pizza" .. iii, nPizzaFound[iii])
end
end
end
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit)
function onPlayerLogin()
local playerAccount = getPlayerAccount(source)
if (playerAccount) then
for iii = 1, #nPizzaFound do
local playerPizzas = getAccountData(playerAccount, "xtreme.pizza" .. iii)
if (playerPizzas) then
nPizzaFound[iii] = playerPizzas
end
end
end
end
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin)
nPizzaFound is definied in cliente-side
--cliente-side
local nPizzaPickup = {
createPickup ( -1088.5999755859, 428.20001220703, 13.60000038147, 3, 1582 ),
createPickup ( -1067.5, 407.20001220703, 13.60000038147, 3, 1582 )
}
--------------------------------------------------------------------------------------
nPizzaFound = {}
local nTotalFound = 0
---------------------
function createPizzaPickup ( )
outputChatBox ( "Find the pizzas!" )
end
addEventHandler ( "onClientResourceStart", getResourceRootElement ( getThisResource ( ) ), createPizzaPickup )
--------------------------------------------------------------------------------------------------------------
function onPlayerPickupPizza ( thePickup )
for iii = 1, #nPizzaPickup do
if thePickup == nPizzaPickup[iii] then
if nPizzaFound[iii] == true then
outputChatBox ( "You already found this pizza." )
return true
end
outputChatBox ( "You found the pizza " .. iii .. ". Here, have some money." )
givePlayerMoney ( 500 )
nPizzaFound[iii] = true
nTotalFound = nTotalFound + 1
if nTotalFound == #nPizzaFound then
outputChatBox ( "Congratulations! You found all pizzas. Here, have more money." )
givePlayerMoney ( 1500 )
end
end
end
end
addEventHandler ( "onClientPlayerPickupHit", localPlayer, onPlayerPickupPizza )
and this is the error i am facing:
findPizzaMG_S.lua:5: attempt to get length of global 'nPizzaFound' (a nil value)
Thanks for any help.