.:HyPeX:. Posted October 23, 2013 Share Posted October 23, 2013 hello guys, i got a problem, i'm getting 2 erros wich i cant manage to fix, can someone help me? Line 38 - bad argument@getAccountData - expected string at argument 2, got nil. Line 46 - attempt to compare number with boolean ZombieCap = {} ZombieArena = getTeamFromName ( "ZombieArena" ) Lobby = getTeamFromName ( "Lobby" ) function getaPlayer() local RandomPlayer = getRandomPlayer() local RandomPlayerTeam = getPlayerTeam(RandomPlayer) if RandomPlayerTeam == ZombieArena then g_Player = RandomPlayer if not ZombieCap[g_Player] then ZombieCap[g_Player] = 0 setTimer ( ZombieToEnemy, 50, 1 ) else outputChatBox("ZombieCap is already defined!") setTimer ( ZombieToEnemy, 50, 1 ) end else if g_ErrorMSG_1 == 0 then outputChatBox("RandomPlayerTeam is not == ZombieArena") g_ErrorMSG_1 = 1 elseif g_ErrorMSG == 1 then return end end end setTimer(getaPlayer, 1000, 0) function ZombieToEnemy(Player) if ZombieCap[thePlayer] == 20 then return end local RandomPlayer = getRandomPlayer() local thePlayer = getPlayerName( RandomPlayer ) local thePlayerAcc = getPlayerAccount( RandomPlayer ) local IsEnemy = getPlayerTeam( RandomPlayer ) if getAccountData( thePlayerAcc, ZombiesKilled ) == nil then outputChatBox("Welcome to the Zombie Arena, each zombie killed will give you $500", source) outputChatBox("If you recived this message it means its your first time in the Zombie Arena", source) outputChatBox("This also means there's a Zombie spawning near you. You can spend the money in the lobby", source) setAccountData( thePlayerAcc, ZombiesKilled, 0) else outputChatBox("a zombie spawned near you, warning!", source) end if not ZombieCap[thePlayerAcc] > 20 then if IsEnemy == ZombieArena then ZombieCap[thePlayerAcc] = tonumber(ZombieCap[thePlayerAcc])+1 local X,Y,Z = getElementPosition( thePlayer ) local Rot = getElementRotation( thePlayer ) spawnBot( tonumber(X)+10, tonumber(Y)+10, tonumber(Z), tonumber(Rot), 10, 0, 0, nil, 0, "chasing", thePlayer) else outputChatBox("".. thePlayer .." is not into ZombieArena team, Zombie spawning failed!") end else outputChatBox("" .. thePlayer .." has reached the cap of Zombies allowed!") end end function ZombieKilled(attacker, weapon, bodypart) local thePlayer = getPlayerName( attacker ) local thePlayerAcc = getPlayerAccount( attacker ) if ( not ZombieCap[thePlayerAcc] ) then ZombieCap[thePlayerAcc] = 0 end ZombieCap[thePlayerAcc] = tonumber(ZombieCap[thePlayerAcc])-1 local account = thePlayerAcc local money = getPlayerMoney( attacker ) local KilledZombies = getAccountData( account, ZombiesKilled) setPlayerMoney( tonumber(money)+500 ) setAccountData( account, ZombiesKilled, tonumber(KilledZombies)+1) outputChatBox("".. thePlayer .." has killed a zombie and $500 were added to his account!") end addEventHandler("onBotWasted", getRootElement(), ZombieKilled) Link to comment
HoLsTeN Posted October 23, 2013 Share Posted October 23, 2013 you must use string to save the account .. setAccountData( thePlayerAcc, "ZombiesKilled", 0) and the error in 46 i think the problem was from setAccountData .. Link to comment
yvadfulck Posted October 24, 2013 Share Posted October 24, 2013 maybe like this: function ZombieKilled(attacker, weapon, bodypart) if getElementType(attacker)=="player" then local thePlayer = getPlayerName( attacker ) local thePlayerAcc = getPlayerAccount( attacker ) if ( not ZombieCap[thePlayerAcc] ) then ZombieCap[thePlayerAcc] = 0 end ZombieCap[thePlayerAcc] = tonumber(ZombieCap[thePlayerAcc])-1 local account = thePlayerAcc local money = getPlayerMoney( attacker ) local KilledZombies = getAccountData( account, ZombiesKilled) setPlayerMoney( tonumber(money)+500 ) setAccountData( account, ZombiesKilled, tonumber(KilledZombies)+1) outputChatBox("".. thePlayer .." has killed a zombie and $500 were added to his account!") end end addEventHandler("onBotWasted", getRootElement(), ZombieKilled) Link to comment
.:HyPeX:. Posted October 24, 2013 Author Share Posted October 24, 2013 nonon, just got the problem, i should use the key with "" to make it as a string. getAccountData( thePlayerAcc, "ZombiesKilled" ) Link to comment
yvadfulck Posted October 24, 2013 Share Posted October 24, 2013 the fix i send is when the bot would die when there is no,or another bot as attacker as it would seek a non existing account??? Link to comment
.:HyPeX:. Posted October 24, 2013 Author Share Posted October 24, 2013 the fix i send is when the bot would die when there is no,or another bot as attackeras it would seek a non existing account??? i wont be creating any other bots, and the bots created are in chase mode of a player, so its not possible. Link to comment
rain_gloom Posted October 24, 2013 Share Posted October 24, 2013 there is no ZombiesKilled variable, you need to use a string as a key in a regular table it would be like this asd = {"foo",function () end, 123} --calling with the index itself: print(asd[1])--it's a number here, but in MTA's data functions, you use strings and what you were doing and shoulda done myTable = {asd=1,foo=42,bar="asdf"} --we don't define myKey print(myTable[myKey])--nil --now we define it myKey = "foo" print(myTable[myKey])--42 good luck Link to comment
.:HyPeX:. Posted October 24, 2013 Author Share Posted October 24, 2013 there is no ZombiesKilled variable, you need to use a string as a key in a regular table it would be like this asd = {"foo",function () end, 123} --calling with the index itself: print(asd[1])--it's a number here, but in MTA's data functions, you use strings and what you were doing and shoulda done myTable = {asd=1,foo=42,bar="asdf"} --we don't define myKey print(myTable[myKey])--nil --now we define it myKey = "foo" print(myTable[myKey])--42 good luck wait what..? i use zombieskilled as account data (setAccountData(user, "ZombiesKilled", number) function getZombies() local playeracc = getPlayerAccount( source ) local killedzombies = getAccountData(playeracc, "ZombiesKilled") outputchatbox("Total zombies killed: '".. killedzombies .."' !", source, 255,255,255,true) end addCommandHandler("KZombies", getZombies) Link to comment
yvadfulck Posted October 24, 2013 Share Posted October 24, 2013 the fix i send is when the bot would die when there is no,or another bot as attackeras it would seek a non existing account??? i wont be creating any other bots, and the bots created are in chase mode of a player, so its not possible. its still possible in some cases... i always specifie the elementtype to be shur on those things Link to comment
rain_gloom Posted October 28, 2013 Share Posted October 28, 2013 from the wiki bool setAccountData ( account theAccount, [b]string key[/b], string value ) you were using a variable that was never created (declared), that's exactly what the error says: Line 38 - bad argument@getAccountData - expected string at argument 2, got nil. --a variable foo --a string "foo" --so: setAccountData(getRandomPlayer(),"mykey",someData) the key is clearly a string while standard Lua tables support any type of key, MTA's setElementData and setAccountData and the respective get functions only support strings. I would suggest you play around with Lua a bit outside MTA to discover what you can and can't do. With some modules you can even use MTA functions, like the XML functions or toJSON/fromJSON. And some typechecks and errors in the code could help you discover what is going wrong. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now