GTX Posted February 5, 2012 Share Posted February 5, 2012 Here seems to be wrong this: if getElementData(source, "state") == "dead" then... I can't get it... It's working fine if I delete that code Code: function earnMoney() local position = getAliveRacePlayers() local acc = getPlayerAccount(source) if getElementData(source, "state") == "dead" then else if not (position <= 0) then if getPlayerCount() >= count then local pAlive = getAliveRacePlayers() local pDead = getDeadRacePlayers() local maxCash = 21*(pAlive+pDead) -- Total cash available to earn. local portion = 0 local finalCash = 0 if not (position == 1) then portion = math.ceil(maxCash/(pAlive+pDead-1)) -- The amount to multiply by the number of dead players to later return the money value. finalCash = math.ceil(portion*(pDead)) -- Calculate the final money value. else finalCash = maxCash end local playerCash = getAccountData(acc,"Cash") or 0 outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. finalCash .. "!",source,255,255,255,true) setAccountData(acc,"Cash", tostring(playerCash) + finalCash) outputDebugString("Final cash for player "..getPlayerName(source)..": "..finalCash) else outputChatBox("#FFFFFF>> #ff0000Need atleast " .. count .. " players to affect the stats!", source, 255, 255, 255, true) return end scoreboardRefresh(source) end end end addEventHandler("onPlayerWasted", getRootElement(), earnMoney) Link to comment
GanJaRuleZ Posted February 5, 2012 Share Posted February 5, 2012 function earnMoney(old, new) if old == "alive" and new == "dead" then local position = getAliveRacePlayers() local acc = getPlayerAccount(source) -- Missing part? else if not (position <= 0) then if getPlayerCount() >= count then local pAlive = getAliveRacePlayers() local pDead = getDeadRacePlayers() local maxCash = 21*(pAlive+pDead) -- Total cash available to earn. local portion = 0 local finalCash = 0 if not (position == 1) then portion = math.ceil(maxCash/(pAlive+pDead-1)) -- The amount to multiply by the number of dead players to later return the money value. finalCash = math.ceil(portion*(pDead)) -- Calculate the final money value. else finalCash = maxCash end local playerCash = getAccountData(acc,"Cash") or 0 outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. finalCash .. "!",source,255,255,255,true) setAccountData(acc,"Cash", tostring(playerCash) + finalCash) outputDebugString("Final cash for player "..getPlayerName(source)..": "..finalCash) else outputChatBox("#FFFFFF>> #ff0000Need atleast " .. count .. " players to affect the stats!", source, 255, 255, 255, true) return end scoreboardRefresh(source) end end end addEventHandler("onPlayerWasted", getRootElement(), earnMoney) Try it Btw , your ingame nick is : GTX ? Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 function earnMoney( ) local position = getAliveRacePlayers( ) local acc = getPlayerAccount( source ) if not getElementData( source, "state" ) == "dead" then if not isGuestAccount( acc ) then if type( count ) == 'number' then if not position <= 0 then if getPlayerCount( ) >= count then local pAlive = getAliveRacePlayers( ) local pDead = getDeadRacePlayers( ) local maxCash = 21*( pAlive + pDead ) -- Total cash available to earn. local portion = 0 local finalCash = 0 if not position == 1 then portion = math.ceil( maxCash/( pAlive+pDead-1 ) ) -- The amount to multiply by the number of dead players to later return the money value. finalCash = math.ceil( portion*( pDead ) ) -- Calculate the final money value. else finalCash = maxCash end local playerCash = getAccountData( acc,"Cash" ) or 0 outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) else outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) return end scoreboardRefresh( source ) end else outputChatBox( 'count variable is not number' ) end end end end addEventHandler( "onPlayerWasted", root, earnMoney ) /debugscript 3 use pls. Link to comment
GTX Posted February 5, 2012 Author Share Posted February 5, 2012 Both codes don't work. And no, my in-game nick is GTX# Link to comment
Castillo Posted February 5, 2012 Share Posted February 5, 2012 What is the "count" variable? is it defined somewhere else in your script or just not defined? Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 Test it and say what output. function earnMoney( ) local position = getAliveRacePlayers( ) outputChatBox( 'var:position '..tostring( position ) ) local acc = getPlayerAccount( source ) outputChatBox( 'var:acc '..tostring( acc ) ) outputChatBox( 'var:count '..tostring( count ) ) if not getElementData( source, "state" ) == "dead" then outputChatBox( 'state == dead ' ) if not isGuestAccount( acc ) then outputChatBox( ' not guest account ' ) if type( count ) == 'number' then outputChatBox( 'var:count == number' ) if not position <= 0 then outputChatBox( 'not positon <= 0' ) if getPlayerCount( ) >= count then outputChatBox( 'getPlayerCount( ) >= count' ) local pAlive = getAliveRacePlayers( ) local pDead = getDeadRacePlayers( ) outputChatBox( 'var:pAlive '..tostring( pAlive ) ) outputChatBox( 'var:pDead '..tostring( pDead ) ) local maxCash = 21*( pAlive + pDead ) -- Total cash available to earn. local portion = 0 local finalCash = 0 if not position == 1 then portion = math.ceil( maxCash/( pAlive+pDead-1 ) ) -- The amount to multiply by the number of dead players to later return the money value. finalCash = math.ceil( portion*( pDead ) ) -- Calculate the final money value. else finalCash = maxCash end local playerCash = getAccountData( acc,"Cash" ) or 0 outputChatBox( 'var:playerCash '..tostring( playerCash ) ) outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) else outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) return end scoreboardRefresh( source ) end else outputChatBox( 'count variable is not number' ) end else outputChatBox( 'guest account ' ) end end end addEventHandler( "onPlayerWasted", root, earnMoney ) Link to comment
GTX Posted February 5, 2012 Author Share Posted February 5, 2012 var:position 2 var:acc userdata: 0x90d5e90 var:count 2 Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 (edited) Can you explain data name 'state' and value 'dead'? Edited February 5, 2012 by Guest Link to comment
GTX Posted February 5, 2012 Author Share Posted February 5, 2012 I got 'state' from race resource, so if player's state is 'dead' then... Link to comment
Kenix Posted February 5, 2012 Share Posted February 5, 2012 I got 'state' from race resource, so if player's state is 'dead' then... You want check if player not dead but dead? function earnMoney( ) local position = getAliveRacePlayers( ) outputChatBox( 'var:position '..tostring( position ) ) local acc = getPlayerAccount( source ) outputChatBox( 'var:acc '..tostring( acc ) ) outputChatBox( 'var:count '..tostring( count ) ) --if getElementData( source, "state" ) == "dead" then outputChatBox( 'state == dead ' ) if not isGuestAccount( acc ) then outputChatBox( ' not guest account ' ) if type( count ) == 'number' then outputChatBox( 'var:count == number' ) if not position <= 0 then outputChatBox( 'not positon <= 0' ) if getPlayerCount( ) >= count then outputChatBox( 'getPlayerCount( ) >= count' ) local pAlive = getAliveRacePlayers( ) local pDead = getDeadRacePlayers( ) outputChatBox( 'var:pAlive '..tostring( pAlive ) ) outputChatBox( 'var:pDead '..tostring( pDead ) ) local maxCash = 21*( pAlive + pDead ) -- Total cash available to earn. local portion = 0 local finalCash = 0 if not position == 1 then portion = math.ceil( maxCash/( pAlive+pDead-1 ) ) -- The amount to multiply by the number of dead players to later return the money value. finalCash = math.ceil( portion*( pDead ) ) -- Calculate the final money value. else finalCash = maxCash end local playerCash = getAccountData( acc,"Cash" ) or 0 outputChatBox( 'var:playerCash '..tostring( playerCash ) ) outputChatBox("#FFFFFF>> #ff8600You have recieved $" .. tostring( finalCash ) .. "!",source,255,255,255,true) setAccountData( acc,"Cash", tostring( playerCash ) + finalCash ) outputDebugString( "Final cash for player "..getPlayerName( source )..": "..tostring( finalCash ) ) else outputChatBox( "#FFFFFF>> #ff0000Need atleast " .. tostring( count ).. " players to affect the stats!", source, 255, 255, 255, true) return end scoreboardRefresh( source ) end else outputChatBox( 'count variable is not number' ) end else outputChatBox( 'guest account ' ) end --end end addEventHandler( "onPlayerWasted", root, earnMoney ) You not need check it Code updated. 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