BieHDC Posted May 20, 2013 Posted May 20, 2013 I have a problem with my self made Script, which should give Players with Ranks money. This script schould run on my DD Server. But the debug log says, that it couldnt get Player Rank It says: ERROR: call: failed to call "race:getPlayerRank"[string "?"] Please help me function win(Player) local pRank = exports["race"]:getPlayerRank(player) if pRank == 1 then givePlayerMoney(source, 1000) elseif pRank == 2 then givePlayerMoney(source, 900) elseif pRank == 3 then givePlayerMoney(source, 800) elseif pRank == 4 then givePlayerMoney(source, 700) elseif pRank == 5 then givePlayerMoney(source, 600) elseif pRank == 6 then givePlayerMoney(source, 500) elseif pRank == 7 then givePlayerMoney(source, 400) elseif pRank == 8 then givePlayerMoney(source, 300) elseif pRank == 9 then givePlayerMoney(source, 200) elseif pRank == 10 then givePlayerMoney(source, 100) else return end end addEventHandler("onClientPlayerWasted", getRootElement(), win(Player) )
PaiN^ Posted May 20, 2013 Posted May 20, 2013 function win( ) local pRank = exports["race"]:getPlayerRank( source) if pRank == 1 then givePlayerMoney(source, 1000) elseif pRank == 2 then givePlayerMoney(source, 900) elseif pRank == 3 then givePlayerMoney(source, 800) elseif pRank == 4 then givePlayerMoney(source, 700) elseif pRank == 5 then givePlayerMoney(source, 600) elseif pRank == 6 then givePlayerMoney(source, 500) elseif pRank == 7 then givePlayerMoney(source, 400) elseif pRank == 8 then givePlayerMoney(source, 300) elseif pRank == 9 then givePlayerMoney(source, 200) elseif pRank == 10 then givePlayerMoney(source, 100) end end addEventHandler("onClientPlayerWasted", getRootElement(), win )
Tete omar Posted May 20, 2013 Posted May 20, 2013 P.S. I recommend you to make a table and store ranks & money in it, for abridgement.
BieHDC Posted May 20, 2013 Author Posted May 20, 2013 Why i should create and How to create a table? And i get the same error again when getting wasted
iPrestege Posted May 20, 2013 Posted May 20, 2013 -- # Client Side ! local Ranks = { -- argument = -- { rank,amount } {1,1000}, {2,900}, {3,800}, {4,700}, {5,600}, {6,500}, {7,400}, {8,300}, {9,200}, {10,100} } addEventHandler("onClientPlayerWasted",localPlayer, function ( ) for _,v in ipairs ( Ranks ) do if ( exports["race"]:getPlayerRank( source ) == v[1] ) then givePlayerMoney ( v[2] ) end end end ) Make sure you have a exported function called 'getPlayerRank' On the race gamemode .
iPrestege Posted May 20, 2013 Posted May 20, 2013 Which error i think it's the export you don't have this function exported yet open the race gamemode meta and check if there's a function exported called 'getPlayerRank' Or no ?
BieHDC Posted May 20, 2013 Author Posted May 20, 2013 Oh thats the fail What i have to write in and where?
iPrestege Posted May 20, 2013 Posted May 20, 2013 Oh Sorry i get it now the get rank it's already exported but it's a server side use this : -- # Server Side ! local Ranks = { {1,1000}, {2,900}, {3,800}, {4,700}, {5,600}, {6,500}, {7,400}, {8,300}, {9,200}, {10,100} } addEventHandler("onPlayerWasted",root, function ( ) for _,v in ipairs ( Ranks ) do if ( exports["race"]:getPlayerRank( source ) == v[1] ) then givePlayerMoney ( source,v[2] ) end end end )
iPrestege Posted May 20, 2013 Posted May 20, 2013 Yes only server side because the exported function server side only ..
BieHDC Posted May 20, 2013 Author Posted May 20, 2013 ok the errors are gone, but i also dont get money. Will this need admin rigts? edit: It needed admin rigts now working perfect Thank you very much for helping me
Jacob Lenn Posted May 20, 2013 Posted May 20, 2013 Try to debug script, i mean check if u get rank: addEventHandler("onPlayerWasted",root, function ( ) outputChatBox(exports["race"]:getPlayerRank( source )) for _,v in ipairs ( Ranks ) do if ( exports["race"]:getPlayerRank( source ) == v[1] ) then givePlayerMoney ( source,v[2] ) end end end ) After pasting this code into your script check what is showing on chat after wasted.
iPrestege Posted May 20, 2013 Posted May 20, 2013 ok the errors are gone, but i also dont get money.Will this need admin rigts? edit: It needed admin rigts now working perfect Thank you very much for helping me You're welcome .. .
BieHDC Posted May 20, 2013 Author Posted May 20, 2013 If i meet you in reallife you will get a beer from me Its austrian tradition^^
Castillo Posted May 20, 2013 Posted May 20, 2013 There's no point on looping the table, it can be done like this: local ranks = { 1000, 900, 800, 700, 600, 500, 400, 300, 200, 100 } addEventHandler ( "onPlayerWasted", root, function ( ) local reward = ranks [ exports [ "race" ]:getPlayerRank ( source ) ] if ( reward ) then givePlayerMoney ( source, reward ) end end )
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