-.Paradox.- Posted March 7, 2014 Share Posted March 7, 2014 (edited) SOLVED Edited April 22, 2014 by Guest Link to comment
Dealman Posted March 7, 2014 Share Posted March 7, 2014 If it has many errors, it would indeed help us if you could post said errors. Link to comment
Moderators Citizen Posted March 7, 2014 Moderators Share Posted March 7, 2014 Everything is explained with commentaries: local reputations = { [-1095] = "demon", [-195] = "evil", [-55] = "bad", [0] = "normal", [55] = "good1", [195] = "good2", [1095] = "hero" } -- this function will return the reputation name giving him the reputation points -- i.e getReputationName(-120) will return "evil" function getReputationName( points ) for reppoints, repname in ipairs ( reputations ) do -- loop over all reputations result = repname --stop the loop if the rep from the table is higher than the rep of the player if reppoints > points then return result --we found it, so let's return it end end end -- this function will update the reputation name of the player -- if the player has -120, getElementData on "Reputation.status" will return "evil" function updateReputationName( player ) local repPoints = getElementData(killer, "Reputation.points") or 0 local newRepName = getReputationName( repPoints ) setElementData(player, "Reputation.status", newRepName) end function reputation(ammo, killer, weapon, bodypart) if killer and killer ~= source then --Reputation points of the guy who died local dRPoints = getElementData(source, "Reputation.points") or 0 --Reputation points of the guy who killed him local kRPoints = getElementData(killer, "Reputation.points") or 0 if dRPoints < 0 then -- the guy who died was a bad guy kRPoints = kRPoints + 5 else --was a good guy kRPoints = kRPoints - 5 end setElementData(killer, "Reputation.points", updateReputationName( killer ) -- update the reputation name for the killer end end addEventHandler( "onPlayerWasted", getRootElement(), reputation) function onLogin (_, account) local defaultPoints = 0 --you can change the default points a guy should have here local defaultRepName = getReputationName( defaultPoints ) --do not modify here setElementData(source, "Reputation.status", getAccountData(account, "rep") or defaultRepName) setElementData(source, "Reputation.points", getAccountData(account, "re.p") or defaultPoints) end addEventHandler ("onPlayerLogin", root, onLogin) function saveData(thePlayer, theAccount) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "rep", getElementData(thePlayer, "Reputation.status")) setAccountData (theAccount, "re.p", getElementData(thePlayer, "Reputation.points")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) I didn't test it so if it works, please post the errors if there is any. Link to comment
Dealman Posted March 8, 2014 Share Posted March 8, 2014 Everything is explained with commentaries That's besides the point, though. I'm here to help, but I'm not gonna read through it all and try to spot mistakes when simply providing the errors and/or warnings would make it easier for us all Link to comment
Moderators Citizen Posted March 8, 2014 Moderators Share Posted March 8, 2014 Everything is explained with commentaries That's besides the point, though. I'm here to help, but I'm not gonna read through it all and try to spot mistakes when simply providing the errors and/or warnings would make it easier for us all You are totally right ! By the way this script has only 30 lines so yeah I just worked into it even if he didn't post the errors/warning. The rules are here but no one read it so yeah, we (moderators) should probably start to lock a topic untill it's ok. What information should my question contain?- What is the reason you make new topic? Whether it's problem with your script or need help with something else. - Explain what is wrong? Tell us what happens when you test your script and what is that you want it to do. - Give us some of your code so that we can help you correct it. - Tell us if you get any error or warning messages and what they are. We can determine what causes the script not to work quicker. Link to comment
-.Paradox.- Posted March 8, 2014 Author Share Posted March 8, 2014 okay i will try it, and sorry i was busy this day, because it's my birthday and i'm planning for a party Link to comment
-.Paradox.- Posted March 9, 2014 Author Share Posted March 9, 2014 Not working, when i kill somebody my rep is still the same (normal) and i still got 0, i got no errors in debugscript 3 Link to comment
Moderators Citizen Posted March 9, 2014 Moderators Share Posted March 9, 2014 Made a typo, replace line 44 with this: setElementData(killer, "Reputation.points", kRPoints) Dunno how nor why I stopped to write the end of this line lol Link to comment
-.Paradox.- Posted March 19, 2014 Author Share Posted March 19, 2014 (edited) Solved Edited April 18, 2014 by Guest Link to comment
NeO_DUFFMAN Posted March 19, 2014 Share Posted March 19, 2014 Replace line 28 with the following: local repPoints = getElementData(player, "Reputation.points") or 0 And also, i didn't get your second issue. Sorry, i've just got back from the hospital lol. My head's still in bad shape :3 Link to comment
-.Paradox.- Posted March 20, 2014 Author Share Posted March 20, 2014 (edited) solved Edited April 22, 2014 by Guest Link to comment
Castillo Posted March 20, 2014 Share Posted March 20, 2014 local reputations = { [-1095] = "demon", [-795] = "evil", [-10] = "bad2", [-5] = "bad1", [0] = "normal", [5] = "good1", [10] = "good2", [795] = "good3", [1095] = "hero" } -- this function will return the reputation name giving him the reputation points -- i.e getReputationName(-120) will return "evil" function getReputationName( points ) for reppoints, repname in ipairs ( reputations ) do -- loop over all reputations result = repname --stop the loop if the rep from the table is higher than the rep of the player if reppoints > points then return result --we found it, so let's return it end end end -- this function will update the reputation name of the player -- if the player has -120, getElementData on "Reputation.status" will return "evil" function updateReputationName( player ) local repPoints = getElementData(killer, "Reputation.points") or 0 local newRepName = getReputationName( repPoints ) setElementData(player, "Reputation.status", newRepName) end function reputation(ammo, killer, weapon, bodypart) if killer and killer ~= source then --Reputation points of the guy who died local dRPoints = getElementData(source, "Reputation.points") or 0 --Reputation points of the guy who killed him local kRPoints = getElementData(killer, "Reputation.points") or 0 if ( dRPoints < 0 or dRPoints == kRPoints ) then -- the guy who died was a bad guy kRPoints = kRPoints + 5 else --was a good guy kRPoints = kRPoints - 5 end setElementData(killer, "Reputation.points", kRPoints) updateReputationName( killer ) -- update the reputation name for the killer end end addEventHandler( "onPlayerWasted", getRootElement(), reputation) function onLogin (_, account) local defaultPoints = 0 --you can change the default points a guy should have here local defaultRepName = getReputationName( defaultPoints ) --do not modify here setElementData(source, "Reputation.status", getAccountData(account, "rep") or defaultRepName) setElementData(source, "Reputation.points", getAccountData(account, "re.p") or defaultPoints) end addEventHandler ("onPlayerLogin", root, onLogin) function saveData(thePlayer, theAccount) if (theAccount and not isGuestAccount(theAccount)) then setAccountData (theAccount, "rep", getElementData(thePlayer, "Reputation.status")) setAccountData (theAccount, "re.p", getElementData(thePlayer, "Reputation.points")) end end addEventHandler ("onPlayerQuit", root, function () saveData(source, getPlayerAccount(source)) end) addEventHandler ("onPlayerLogout", root, function (prev) saveData(source, prev) end) Link to comment
-.Paradox.- Posted March 22, 2014 Author Share Posted March 22, 2014 (edited) solved Edited April 22, 2014 by Guest Link to comment
Castillo Posted March 22, 2014 Share Posted March 22, 2014 That's because there is a typo at "updateReputationName" function, instead of "player" it says "killer". function updateReputationName( player ) local repPoints = getElementData(player, "Reputation.points") or 0 local newRepName = getReputationName( repPoints ) setElementData(player, "Reputation.status", newRepName) end Use that. Link to comment
Moderators Citizen Posted March 23, 2014 Moderators Share Posted March 23, 2014 I also rechecked my function getReputationName which was totally wrong. Run this code and see the result https://ideone.com/zLMTY5 So after you did the Solidsnake's fix, change your code to be like this: local reputations = { {-1095 , "demon" }, {-795 , "evil" }, {-10 , "bad2" }, {-5 , "bad1" }, {0 , "normal" }, {5 , "good1" }, {10 , "good2" }, {795 , "good3" }, {1095 , "hero" } } function getReputationName( points ) local _, data = next( reputations ) local result = data[2] for k, repdata in ipairs ( reputations ) do if repdata[1] <= points then result = repdata[2] else break end end return result end Link to comment
-.Paradox.- Posted March 23, 2014 Author Share Posted March 23, 2014 (edited) Okay gonna try Edited April 22, 2014 by Guest Link to comment
Castillo Posted March 23, 2014 Share Posted March 23, 2014 I also rechecked my function getReputationName which was totally wrong.Run this code and see the result https://ideone.com/zLMTY5 So after you did the Solidsnake's fix, change your code to be like this: local reputations = { {-1095 , "demon" }, {-795 , "evil" }, {-10 , "bad2" }, {-5 , "bad1" }, {0 , "normal" }, {5 , "good1" }, {10 , "good2" }, {795 , "good3" }, {1095 , "hero" } } function getReputationName( points ) local _, data = next( reputations ) local result = data[2] for k, repdata in ipairs ( reputations ) do if repdata[1] <= points then result = repdata[2] else break end end return result end I kinda thought it was wrong, but since I thought it was already tested I didn't try to change it. Link to comment
-.Paradox.- Posted March 23, 2014 Author Share Posted March 23, 2014 (edited) solved Edited April 22, 2014 by Guest Link to comment
Moderators Citizen Posted March 23, 2014 Moderators Share Posted March 23, 2014 I kinda thought it was wrong, but since I thought it was already tested I didn't try to change it. Hehe, I never test them because I too lazy to start a server, but I should test it in ideone, I know But this time my function has been tested and is workign fine now: https://ideone.com/q3wLNF now when i kill somebody my points are 5 but status is still normal By the way, now you didn't apply the Solidsnake's fix right ? The only reason for that bug is that the following lisne is returning false: local repPoints = getElementData(player, "Reputation.points") or 0 So I think you didn't replaced killer by player as Solidsnake told you. Try this again but with an output like this: function updateReputationName( player ) local repPoints = getElementData(player, "Reputation.points") or 0 local newRepName = getReputationName( repPoints ) outputChatBox( repPoints.." => "..newRepName) setElementData(player, "Reputation.status", newRepName) end And tell us what's written in the chabox when you kill someone. I'm also pretty sure you aren't using /debugscript 3 to be able to see client side errors. You won't see them in the server's console. If it's still not working show us the code you have now since we did a lot of modifications. I want to see if you did them correctly. Link to comment
-.Paradox.- Posted March 24, 2014 Author Share Posted March 24, 2014 (edited) Solved Edited April 18, 2014 by Guest Link to comment
-.Paradox.- Posted March 24, 2014 Author Share Posted March 24, 2014 (edited) solved Edited April 22, 2014 by Guest Link to comment
Castillo Posted March 24, 2014 Share Posted March 24, 2014 My reputation.status dont change it's stil 'nil', and when i have 0 in reputation.points i see in status "normal" I killed a player and got reputation status "good1", then I killed another and my reputation status went back to "normal". Link to comment
-.Paradox.- Posted March 25, 2014 Author Share Posted March 25, 2014 (edited) solved Edited April 22, 2014 by Guest 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