Jump to content

addStat()


#Paper

Recommended Posts

In the debugscript there isn't any error...

And the stat doesn't set in the scoreboard...

function addStat(thePlayer, theStat, theValue) 
local getActualPoints = getElementData(thePlayer, "Points") 
local getActualCash = getElementData(thePlayer, "Cash") 
if theStat == cash then 
    setElementData(thePlayer, "Cash", getActualCash + theValue) 
elseif theStat == points then 
    setElementData(thePlayer, "Points", getActualPoints + theValue) 
end 
end 
  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local cash = players * 7 
addStat(thePlayer, points, points) 
addStat(thePlayer, cash, cash) 
end 

Link to comment
In the debugscript there isn't any error...

And the stat doesn't set in the scoreboard...

function addStat(thePlayer, theStat, theValue) 
local getActualPoints = getElementData(thePlayer, "Points") 
local getActualCash = getElementData(thePlayer, "Cash") 
if theStat == cash then 
    setElementData(thePlayer, "Cash", getActualCash + theValue) 
elseif theStat == points then 
    setElementData(thePlayer, "Points", getActualPoints + theValue) 
end 
end 
  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local cash = players * 7 
addStat(thePlayer, points, points) 
addStat(thePlayer, cash, cash) 
end 

may be this?

  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local cash = players * 7 
addStat(source, points, points) 
addStat(source, cash, cash) 
end 
  

Link to comment
In the debugscript there isn't any error...

And the stat doesn't set in the scoreboard...

function addStat(thePlayer, theStat, theValue) 
local getActualPoints = getElementData(thePlayer, "Points") 
local getActualCash = getElementData(thePlayer, "Cash") 
if theStat == cash then 
    setElementData(thePlayer, "Cash", getActualCash + theValue) 
elseif theStat == points then 
    setElementData(thePlayer, "Points", getActualPoints + theValue) 
end 
end 
  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local cash = players * 7 
addStat(thePlayer, points, points) 
addStat(thePlayer, cash, cash) 
end 

may be this?

  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local cash = players * 7 
addStat(source, points, points) 
addStat(source, cash, cash) 
end 
  

no... the "player" variable is the right...

Link to comment

I hope now work)

function addStat(thePlayer, theStat, theValue) 
local getActualPoints = getElementData(thePlayer, "Points") 
local getActualCash = getElementData(thePlayer, "Cash") 
if theStat ==  "Cash" then 
    setElementData(thePlayer, "Cash", getActualCash + theValue) 
elseif theStat == "Points" then 
    setElementData(thePlayer, "Points", getActualPoints + theValue) 
end 
end 
  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local pointsstat = "Points" 
local cash = players * 7 
local cashstat = "Cash" 
addStat(thePlayer, pointsstat, points) 
addStat(thePlayer, cashstat, cash) 
end 

or easier:

function addStat(thePlayer, theStat, theValue) 
    setElementData(thePlayer, theStat, getElementData(thePlayer,theStat) + theValue) 
end 
  
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local pointsstat = "Points" 
local cash = players * 7 
local cashstat = "Cash" 
addStat(thePlayer, pointsstat, points) 
addStat(thePlayer, cashstat, cash) 
end 

Link to comment

Doesn't make any sense, you are passing 'thePlayer' as player argument, but in your function you are using 'player'.

function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local pointsstat = "Points" 
local cash = players * 7 
local cashstat = "Cash" 
addStat(player, pointsstat, points) 
addStat(player, cashstat, cash) 
end 

Link to comment
Doesn't make any sense, you are passing 'thePlayer' as player argument, but in your function you are using 'player'.
function onPlayerWins(player) 
local players = getPlayerCount() 
local points = players * 1.3 
local pointsstat = "Points" 
local cash = players * 7 
local cashstat = "Cash" 
addStat(player, pointsstat, points) 
addStat(player, cashstat, cash) 
end 

there aren't any error... but the scoreboard still be to 0... doesn't change

Link to comment
  • Moderators
function addStat(thePlayer, theStat, theValue) 
    local getActualPoints = getElementData(thePlayer, "Points") 
    local getActualCash = getElementData(thePlayer, "Cash") 
    outputChatBox( "addStat: "..getActualPoints..", "..getActualCash) -- test 
    if theStat == "cash" then 
        setElementData(thePlayer, "Cash", getActualCash + theValue) 
    elseif theStat == "points" then 
        setElementData(thePlayer, "Points", getActualPoints + theValue) 
    end 
    outputChatBox( "Current datas: "..getElementData(thePlayer, "Points")..", "..getElementData(thePlayer, "Cash") )-- test 
end 
      
function onPlayerWins(player) 
    local players = getPlayerCount() 
    local points = players * 1.3 
    local cash = players * 7 
    outputChatBox( "onPlayerWins: "..players..", "..points..", "..cash )-- test 
    addStat(player, "points", points) 
    addStat(player, "cash", cash) 
end 

Link to comment
function addStat(thePlayer, theStat, theValue) 
    local getActualPoints = getElementData(thePlayer, "Points") 
    local getActualCash = getElementData(thePlayer, "Cash") 
    outputChatBox( "addStat: "..getActualPoints..", "..getActualCash) -- test 
    if theStat == "cash" then 
        setElementData(thePlayer, "Cash", getActualCash + theValue) 
    elseif theStat == "points" then 
        setElementData(thePlayer, "Points", getActualPoints + theValue) 
    end 
    outputChatBox( "Current datas: "..getElementData(thePlayer, "Points")..", "..getElementData(thePlayer, "Cash") )-- test 
end 
      
function onPlayerWins(player) 
    local players = getPlayerCount() 
    local points = players * 1.3 
    local cash = players * 7 
    outputChatBox( "onPlayerWins: "..players..", "..points..", "..cash )-- test 
    addStat(player, "points", points) 
    addStat(player, "cash", cash) 
end 

Thanks bro!

But can you explain why mine version doesn't works?

Link to comment
  • Moderators

Sure,

So here,

if theStat == cash then 

the script want to check if theStat is equal to cash ( not the name cash but the value of this variable ), the variable cash is not defined so cash = nil so the script make that:

if theStat == nil then 

Also, you made:

addStat(player, points, points) 

here, you send 2 times the value of the variable points and theStat receive the 1st variable points ( so a number and not the name cash )

(I'm sorry if you don't understand but I can't explain better why your script can't work :| , but I can explain why my script works :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...