Jump to content

Please help me.. whats wrong ?


NeedSumHelp

Recommended Posts

function MoneyForWinner() 
   local alivePlayers = getAlivePlayers() 
   if #alivePlayers == 1 then  
   local playername = getPlayerName( alivePlayers[1] ) 
   local serial = getPlayerSerial(alivePlayers[1]) 
   local Cash = executeSQLSelect( "GREENTHING", "Cash","serial = '" .. serial .. "'") 
    
   Cashs = tonumber(Cash[1]["Cash"]) + 150 
    
   setElementData(alivePlayers[1] ,"data.playername",playername,true) 
   setElementData(alivePlayers[1] ,"data.Cash",Cashs,true) 
         
   executeSQLUpdate ( "GREENTHING", "Cash = '"..Cashs.."'","serial = '" .. serial .. "'") 
   end  
end 
addEventHandler("onPlayerWasted", rootElement  , MoneyForWinner) 

it says bad argument @ getplayerserial and getplayername

This should give winner 150 rubla but w/e its not doing it and im sure everything is correct.. what i should do ?

Link to comment
    function MoneyForWinner() 
       local alivePlayers = getAlivePlayers() 
       if #alivePlayers == 1 then 
for key,val in ipairs(alivePlayers) do 
      local playername = getPlayerName( val[1] ) 
      local serial = getPlayerSerial(val[1]) 
   local Cash = executeSQLSelect( "GREENTHING", "Cash","serial = '" .. serial .. "'") 
       
      Cashs = tonumber(Cash[1]["Cash"]) + 150 
        
     setElementData(val[1] ,"data.playername",playername,true) 
      setElementData(val[1] ,"data.Cash",Cashs,true) 
           
      executeSQLUpdate ( "GREENTHING", "Cash = '"..Cashs.."'","serial = '" .. serial .. "'") 
      end 
   end 
   addEventHandler("onPlayerWasted", rootElement  , MoneyForWinner) 

Or still error.. attempt to index local 'val' (a userdata value)

line

   local playername = getPlayerName( val[1] ) 

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