#Paper Posted April 30, 2011 Share Posted April 30, 2011 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
Kenix Posted April 30, 2011 Share Posted April 30, 2011 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
#Paper Posted April 30, 2011 Author Share Posted April 30, 2011 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
Dre-+- Posted April 30, 2011 Share Posted April 30, 2011 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
Castillo Posted April 30, 2011 Share Posted April 30, 2011 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
#Paper Posted April 30, 2011 Author Share Posted April 30, 2011 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
Castillo Posted April 30, 2011 Share Posted April 30, 2011 I guess you are using both functions, right? addStat and onPlayerWins. Link to comment
#Paper Posted April 30, 2011 Author Share Posted April 30, 2011 yes... i trigger the onPlayerWins() func by the race gm... and then i trigger the addStat func Link to comment
Moderators Citizen Posted May 1, 2011 Moderators Share Posted May 1, 2011 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
#Paper Posted May 1, 2011 Author Share Posted May 1, 2011 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 Citizen Posted May 2, 2011 Moderators Share Posted May 2, 2011 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 ) Link to comment
#Paper Posted May 2, 2011 Author Share Posted May 2, 2011 Ohhh, i understand, ty City 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