Jump to content

addStat()


#Paper

Recommended Posts

Posted

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 

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted
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 
  

http://vk.com/the_kenix

Вопросы задавайте на форуме, не пишите мне в личку.

Please don't pm me.

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted

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 

Sorry for my bad english(

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

Posted

I guess you are using both functions, right? addStat and onPlayerWins.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

  • Moderators
Posted
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 

The rEvolution is coming ...

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

mtaubluascripter.png

My skype: skiper964

I helped you? Help me! ^^

Help me bro! ^^

  • Moderators
Posted

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

The rEvolution is coming ...

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