bartje01 Posted March 7, 2011 Share Posted March 7, 2011 Hey guys. I've learnt how to save money now. I tried the same with saving deaths. I failed For money everything works fine. But for deaths it doesn't work at all. What's wrong? This is the last thing I want to know for a while. after that I can help my self forward. Thanks MTa forum. I did it like this: function onLoginSetStats ( ) if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) if getAccountData ( account, "data.cash" ) then givePlayerMoney(source, tonumber(getAccountData(account,"data.cash"))) outputChatBox ( "Your stats are transfered back!", source ) setAccountData(account,"data.deaths",tonumber(getAccountData(account,"data.deaths"))) else setAccountData( account, "data.cash", 0 ) setAccountData( account, "data.deaths", 0 ) outputChatBox ( "Your stats will now be saved." ) end end end function onLogoutSaveStats() if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) setAccountData(account,"data.cash",tonumber(getAccountData(account,"data.cash"))+tonumber(getPlayerMoney(source))) setAccountData( account, "data.deaths", 0 ) setPlayerMoney(source,0) end end addEventHandler ( "onPlayerLogout", root, onLogoutSaveStats ) addEventHandler ( "onPlayerLogin", root, onLoginSetStats ) function myStats ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local cash = getAccountData ( account, "data.cash" ) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats: " .. tostring" Money: ".. ( cash ) , thePlayer ) end end addCommandHandler ( "cash", myStats ) function myStats2 ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats2: " .. tostring" Deaths: ".. ( deaths ) , thePlayer ) end end addCommandHandler ( "deaths", myStats2 ) /deaths doesn't work ERROR: testmode\server.lua:72: attempt to concatenate local 'deaths' (a nil value) Link to comment
Castillo Posted March 7, 2011 Share Posted March 7, 2011 function onLoginSetStats ( ) if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) if getAccountData ( account, "data.cash" ) then givePlayerMoney(source, tonumber(getAccountData(account,"data.cash"))) outputChatBox ( "Your stats are transfered back!", source ) setAccountData(account,"data.deaths",tonumber(getAccountData(account,"data.deaths"))) else setAccountData( account, "data.cash", 0 ) setAccountData( account, "data.deaths", 0 ) outputChatBox ( "Your stats will now be saved." ) end end end function onLogoutSaveStats() if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) setAccountData(account,"data.cash",tonumber(getAccountData(account,"data.cash"))+tonumber(getPlayerMoney(source))) setAccountData( account, "data.deaths", 0 ) setPlayerMoney(source,0) end end addEventHandler ( "onPlayerLogout", root, onLogoutSaveStats ) addEventHandler ( "onPlayerLogin", root, onLoginSetStats ) function myStats ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local cash = getAccountData ( account, "data.cash" ) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats: Money: ".. tostring( cash ) , thePlayer ) end end addCommandHandler ( "cash", myStats ) function myStats2 ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats2: Deaths: ".. tostring( deaths ), thePlayer ) end end addCommandHandler ( "deaths", myStats2 ) addEventHandler("onPlayerWasted",getRootElement(), function (ammo,killer) if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) setAccountData(account,"data.deaths",tonumber(getAccountData(account,"data.deaths"))+1) end end) Link to comment
bartje01 Posted March 7, 2011 Author Share Posted March 7, 2011 Hmm no errors anymore. /deaths works too but it doesn't work with my onplayerwasted Because of this I guess [code}[2011-03-07 23:07:55] ERROR: testmode\server.lua:84: attempt to perform arithmetic on a nil value[2011-03-07 23:07:55] ERROR: testmode\server.lua:114: attempt to perform arithmetic on local 'getPlayerCash' (a boolean value)[/code] function onWasted ( ) local getPlayerDeaths = getElementData ( source, "data.deaths" ) local getPlayerCash = getElementData ( source, "data.cash" ) setTimer( spawnPlayer, 2000, 1, source, 1187.19,-1324.01,13.55 ) outputChatBox ( "You've paid 100$ for medical bill.", source ) setElementData ( source, "data.cash", getPlayerCash - 100 ) setElementData ( source, "data.deaths", getPlayerDeaths + 1 ) end addEventHandler ( "onPlayerWasted", root, onWasted ) Link to comment
Castillo Posted March 7, 2011 Share Posted March 7, 2011 function onWasted (ammo, killer) local account = getPlayerAccount(source) local getPlayerDeaths = getAccountData(account, "data.deaths" ) local getPlayerCash = getAccountData(account, "data.cash" ) setTimer( spawnPlayer, 2000, 1, source, 1187.19,-1324.01,13.55 ) outputChatBox ( "You've paid 100$ for medical bill.", source ) setAccountData ( account, "data.cash", tonumber(getPlayerCash) - 100 ) setAccountData ( account, "data.deaths", tonumber(getPlayerDeaths) + 1 ) end addEventHandler ( "onPlayerWasted", root, onWasted ) Try it. Link to comment
bartje01 Posted March 7, 2011 Author Share Posted March 7, 2011 It works for the cash now. But deaths says: nil So not a number. : o Link to comment
Castillo Posted March 8, 2011 Share Posted March 8, 2011 function onLoginSetStats ( ) if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) if getAccountData ( account, "data.cash" ) then givePlayerMoney(source, tonumber(getAccountData(account,"data.cash"))) outputChatBox ( "Your stats are transfered back!", source ) else setAccountData( account, "data.cash", 0 ) setAccountData( account, "data.deaths", 0 ) outputChatBox ( "Your stats will now be saved." ) end end end function onLogoutSaveStats() if not isGuestAccount ( getPlayerAccount ( source ) ) then account = getPlayerAccount(source) setAccountData(account,"data.cash",tonumber(getAccountData(account,"data.cash"))+tonumber(getPlayerMoney(source))) setAccountData( account, "data.deaths", 0 ) setPlayerMoney(source,0) end end addEventHandler ( "onPlayerLogout", root, onLogoutSaveStats ) addEventHandler ( "onPlayerLogin", root, onLoginSetStats ) function myStats ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local cash = getAccountData ( account, "data.cash" ) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats: Money: ".. tostring( cash ) , thePlayer ) end end addCommandHandler ( "cash", myStats ) function myStats2 ( thePlayer ) if not isGuestAccount ( getPlayerAccount ( thePlayer ) ) then account = getPlayerAccount(thePlayer) local deaths = getAccountData ( account, "data.deaths" ) outputChatBox ( "Stats2: Deaths: ".. tostring( deaths ), thePlayer ) end end addCommandHandler ( "deaths", myStats2 ) function onWasted (ammo, killer) local account = getPlayerAccount(source) local getPlayerDeaths = getAccountData(account, "data.deaths" ) if getPlayerDeaths then local getPlayerCash = getAccountData(account, "data.cash" ) setTimer( spawnPlayer, 2000, 1, source, 1187.19,-1324.01,13.55 ) outputChatBox ( "You've paid 100$ for medical bill.", source ) setAccountData ( account, "data.cash", tonumber(getPlayerCash) - 100 ) setAccountData ( account, "data.deaths", tonumber(getPlayerDeaths) + 1 ) else setAccountData ( account, "data.deaths", 1 ) end end addEventHandler ( "onPlayerWasted", root, onWasted ) Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 It almost works now. no errors no warnings. It shows me how many deaths I have and such things. But when I type /cash or /deaths it shows me the message two times Link to comment
Moderators Citizen Posted March 8, 2011 Moderators Share Posted March 8, 2011 Maybe you have two times the same function in your code. Make a search with "function myStats2" and "function myStats" Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 Lol ye thanks I failed damn bad I excidently copied and not removed the other cmds So I had them twice. Thanks for the help guys. Btw: I've made a NPC. But can someone send me a good wiki page of how I can make them walk around LS? I couldn't find it on wiki bad enough Link to comment
Moderators Citizen Posted March 8, 2011 Moderators Share Posted March 8, 2011 Lol it's not simple to code an Artificial Intelligence but it's my speciality ^^ ( I very like this ) I made a NPC who can walk around LS yeah but I don't give you the code But I can explain you how I made it: This system use only the server-side ! I took the position of all angles of pavements ( I have 490 positions or something like that but I don't took everything ) and I store this positions in a database with an ID for each marker. Then I create the first marker and the NPC, and I make him walk. When he arrived to the marker, I make a random of 3 IDs of marker where he can go( only 3 because the 4th is the marker that he comes from ), I create the new marker and I set his rotation in the direction of this new marker etc... Do you understand my system ? I gonna make you a little video to show my NPC walker, today or tomorrow Link to comment
bartje01 Posted March 8, 2011 Author Share Posted March 8, 2011 I understand your steps. But not how I'll script it Anyways. Could you show me how I can let him walk just 5 steps or something? I only want to know how to make it move Link to comment
Moderators Citizen Posted March 8, 2011 Moderators Share Posted March 8, 2011 Yeah of course begin with this script: function pedWalk(thePlayer, commandName) local pedwalk = createPed(184, 1790.5603515625, -1724.337890625, 13.5) -- I create the NPC setElementID(pedwalk,"pedwalker") -- I give him an ID setPedRotation(pedwalk,(90)) -- set his rotation local nextmarker = createMarker( 1757.421875, -1724.625, 12.55, "cylinder", 1.4, 255, 000, 000 ) -- I create the marker for the NPC addEventHandler( "onMarkerHit", nextmarker, yourFunction ) -- execute yourFunction when the marker is hit setElementID(nextmarker,"mf2")-- all my markers for the NPC have an ID like this mf1, mf2, mf3, ... mf495 ^^ setPedAnimation(pedwalk, "ped", "WALK_civi", -1, 1, 1, 0) -- The ped walk now end addCommandHandler( "testAI", pedWalk, false, false ) And if you can't find my ped take this code: function gotToPedWalker( thePlayer, commandName ) local thePed = getElementByID( "pedwalker" ) if ( thePed ) then local x, y, z = getElementPosition( thePed ) setElementPosition( thePlayer, x, y-1, z ) outputChatBox("You were teleported to the Ped Walker", thePlayer ) else outputChatBox("The Ped Walker doesn't exist !", thePlayer, 180, 0, 0 ) end end addCommandHandler( "gotoAI", gotToPedWalker, false, false ) I gonna make the video now Link to comment
Moderators Citizen Posted March 9, 2011 Moderators Share Posted March 9, 2011 (edited) This is the video of my NPC who walk in LS: https://www.youtube.com/watch?v=T43nQMRyfs0 Thanks for watching and leave comments please EDIT: change NPX to NPC Edited March 9, 2011 by Guest Link to comment
bartje01 Posted March 9, 2011 Author Share Posted March 9, 2011 Wow thanks. That looks awesome 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