Jump to content

One last question. element data deaths


bartje01

Recommended Posts

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
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

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
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
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

Lol ye thanks I failed damn bad xD I excidently copied and not removed the other cmds xD 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

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 :twisted:

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 :lol: ) 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 :roll: ), 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
  • Moderators

Yeah of course :wink: 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 :mrgreen:

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...