Jump to content

[HELP] Script


MultiNo

Recommended Posts

can someone help me? :oops:

ezimba18771615640304.png

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

---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

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!

.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):

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...