MultiNo Posted July 21, 2014 Share Posted July 21, 2014 can someone help me? local armour = { } local timee = 10000 addCommandHandler ( "armour", function ( source ) if ( armour [ source ] ) then return outputChatBox ( "Wait 10 seconds to use this command again", source, 225, 0, 0 ) end local money = getPlayerMoney ( thePlayer ) if money >= 499 then outputChatBox ('' .. getPlayerName(source) .. 'Bought A Armour (/armour)', root, 255, 255, 255, true) setPedArmor( source, 100 ) takePlayerMoney ( source, 500 ) else outputChatBox("you do not have enough money!",thePlayer, 255, 0, 0) end armour [ source ] = true setTimer ( function ( ) armour [ source ] = false end , timee, 1 ) end ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( armour [ source ] ) then armour [ source ] = nil end end ) Link to comment
12p Posted July 21, 2014 Share Posted July 21, 2014 I wonder why do I even bother. Please read this link and post again once you're done. Also, /debugscript 3 Type that command in the chat when you test your scripts. Link to comment
MultiNo Posted July 21, 2014 Author Share Posted July 21, 2014 Seben said: I wonder why do I even bother. Please read this link and post again once you're done.Also, /debugscript 3 Type that command in the chat when you test your scripts. I want to add getPlayerMoney, but I always got the error: "attempt to compare number with boolean" I do not know what it I'm doing wrong, before that everything works perfectly Link to comment
Max+ Posted July 21, 2014 Share Posted July 21, 2014 ---ServerSide local armour = { } local timee = 10000 addCommandHandler ( "armour", function ( ) if ( armour [ source ] ) then return outputChatBox ( "Wait 10 seconds to use this command again", source, 225, 0, 0 ) end local money = getPlayerMoney ( source ) if money >= 499 then outputChatBox ('' .. getPlayerName(source) .. 'Bought A Armour (/armour)', root, 255, 255, 255, true) setPedArmor( source, 100 ) takePlayerMoney ( source, 500 ) else outputChatBox("you do not have enough money!",source, 255, 0, 0) end armour [ source ] = true setTimer ( function ( ) armour [ source ] = false end , timee, 1 ) end ) addEventHandler ( "onPlayerQuit", root, function ( ) if ( armour [ source ] ) then armour [ source ] = nil end end ) Link to comment
MultiNo Posted July 21, 2014 Author Share Posted July 21, 2014 .lua:9: attempt to compare number with boolean Link to comment
12p Posted July 21, 2014 Share Posted July 21, 2014 For once, I have the time and I'm feeling like it: I'll explain step by step. I hope you understand the process and learn to do it on your own Let's do it! MultiNo said: .lua:9: attempt to compare number with boolean This the line that throws the error if money >= 499 then "money"? That value is declared in this line local money = getPlayerMoney ( source ) But, why is it a boolean (true/false)? According to the wiki, getPlayerMoney (kindly click the blue-highlighted function above to see by yourself): "Returns an integer with the amount of money the specified player has, false if the player is invalid." So,You have an invalid player... "source"? Where does it come from? addCommandHandler ( "armour", function ( ) Nowhere? That's because commands don't give a "source" value. From the wiki (click the blue-highlighted addCommandHandler function above): Quote These are the parameters for the handler function that is called when the command is used.player playerSource, string commandName, [string arg1, string arg2, ...] playerSource: The player who triggered the command. If not triggered by a player (e.g. by admin), this will be false. So, this should fix it... addCommandHandler ( "armour", function (playerSource) Wait, how is this supposed to work when everything within that command handler function still uses "source"? Obvious solution! Replace it all with this new player parameter! Go on, fix it. I even told you what to do, so it shouldn't be bothersome. If you still don't understand, you probably shouldn't be doing this sort of scripts yet. Remember to always search in the wiki for documentation! Link to comment
MultiNo Posted July 21, 2014 Author Share Posted July 21, 2014 aah, got it, thank you <3 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