SkrillexX Posted May 19, 2013 Share Posted May 19, 2013 Hi , i wanted to make a script that gives to the player an RPG when he types /rpg and he will loose 6000$. idk why it doesn't wprk , anyways , here's my code. Client-Side. function consoleGive ( thePlayer, rpg, 35, 1 ) local status = giveWeapon ( thePlayer, 35, 1, true ) -- attempt to give the weapon, forcing it as selected weapon if ( not status ) then -- if it was unsuccessful outputConsole ( "Failed to give weapon.", thePlayer ) -- tell the player end end addCommandHandler ( "rpg", consoleGive ) Server-Side. function payme() takePlayerMoney (6000 ,player) end addEventHandler ("OnPlayerCommand", player) Any help wuld be welcomed. Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 -- # Server Side function consoleGive ( thePlayer ) if getPlayerMoney ( thePlayer ) >= 6000 then takePlayerMoney ( thePlayer,6000 ) giveWeapon ( thePlayer, 35, 1, true ) else outputChatBox(" You don't have money",thePlayer) end end addCommandHandler ( "rpg", consoleGive ) Not tested yet . Link to comment
SkrillexX Posted May 19, 2013 Author Share Posted May 19, 2013 Means the problem is only in the serverside ? Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 No there's some elements not defined like player ..etc and you have to check the player money because if you don't check the player money will be a negative money . Link to comment
SkrillexX Posted May 19, 2013 Author Share Posted May 19, 2013 Ok , /debugscript 3 don't tell me any error anyways here are my server/client side codes. Serverside. function consoleGive ( thePlayer ) if getPlayerMoney ( thePlayer ) >= 6000 then takePlayerMoney ( thePlayer,6000 ) if not getPlayerMoney ( thePlayer ) >= 6000 then outputChatBox ("You do not have enough money!") giveWeapon ( thePlayer, 35, 1, true ) else outputChatBox(" You don't have money",thePlayer) end end addCommandHandler ( "rpg", consoleGive ) And the Clientside function consoleGive ( thePlayer, rpg, 35, 1 ) local status = giveWeapon ( thePlayer, 35, 1, true ) if ( not status ) then outputConsole ( "Failed to give weapon.", thePlayer ) end end addCommandHandler ( "rpg", consoleGive ) Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 giveWeapon function server side only any way try this server side : function consoleGive ( thePlayer ) if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then outputChatBox ("You do not have enough money!") return end giveWeapon ( thePlayer, 35, 1, true ) takePlayerMoney ( thePlayer,6000 ) end addCommandHandler ( "rpg", consoleGive ) Link to comment
SkrillexX Posted May 19, 2013 Author Share Posted May 19, 2013 Really thanks. it works /lock Link to comment
Castillo Posted May 19, 2013 Share Posted May 19, 2013 giveWeapon function server side only any way try this server side : function consoleGive ( thePlayer ) if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then outputChatBox ("You do not have enough money!") return end giveWeapon ( thePlayer, 35, 1, true ) takePlayerMoney ( thePlayer,6000 ) end addCommandHandler ( "rpg", consoleGive ) There's no need to convert a number to a number. Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 giveWeapon function server side only any way try this server side : function consoleGive ( thePlayer ) if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then outputChatBox ("You do not have enough money!") return end giveWeapon ( thePlayer, 35, 1, true ) takePlayerMoney ( thePlayer,6000 ) end addCommandHandler ( "rpg", consoleGive ) There's no need to convert a number to a number. But why some times i get a error something say attempt to something to string a number ? And when i use tonumber every thing fine ? Link to comment
Castillo Posted May 19, 2013 Share Posted May 19, 2013 6000 is already a number, use logic, why would you need to convert it to a number? Link to comment
iPrestege Posted May 19, 2013 Share Posted May 19, 2013 I Don't know but sometimes just get this fuck error and use tonumber and every thing fine . Link to comment
Castillo Posted May 19, 2013 Share Posted May 19, 2013 It's obviously with a different script, since with that one is not required. addCommandHandler ( "money", function ( thePlayer, _, amount ) if ( getPlayerMoney ( thePlayer ) >= amount ) then -- Here it'll cause an error because 'amount' is a string and not a number. takePlayerMoney ( thePlayer, amount ) end end ) Read the comment, there you must use tonumber to convert 'amount' which is a string to a number. 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