Jump to content

[Help]Storing Armor Script


Recommended Posts

hello,

I am trying to make a script that stores armor if it's undamaged but i got some warnings in the line 10 in the client side 

here is the script ,it's very simple 

--Client Side
function storeArmor ( )
    local armor = getPedArmor( player )
    if ( armor == 100 ) then return
    function ()    
    triggerServerEvent("setdaarmor",true)
    outputChatBox( "Your armor got stored",255,255,255,true ) 
            end
        end
    end      
 addCommandHandler ( "storearmor", showArmor )

--------------------------------------------------------------------------

addEvent("setdaarmor",true)
addEventHandler("setdaarmor", resourceRoot,
function()
setPedArmor( 0, player )
end)

thank you ,notice if i forgot something.

Link to comment
--Client Side
function storeArmor ( )
    local armor = getPedArmor(localPlayer)
    if (armor == 100) then return
    function()  
    triggerServerEvent("setdaarmor",true)
    outputChatBox("Your armor got stored",255,255,255,true) 
            end
        end
    end      
 addCommandHandler ("storearmor", storeArmor)

 

Link to comment
4 minutes ago, Dimos7 said:

--Client Side
function storeArmor ( )
    local armor = getPedArmor(localPlayer)
    if (armor == 100) then return
    function()  
    triggerServerEvent("setdaarmor",true)
    outputChatBox("Your armor got stored",255,255,255,true) 
            end
        end
    end      
 addCommandHandler ("storearmor", storeArmor)

 

still not working ..no warnings or errors.

Link to comment

That's not possible, you are definitely getting errors... You have this:

setPedArmor( 0, player )

setPedArmor takes a player element first. So you are getting element expected, got number error.

player is not defined in your code. When triggering from client to server and localPlayer is the source element, you can use 'client' variable server side to get the player element.

triggerServerEvent("setdaarmor",true)

You should use the wiki if you are new to scripting, triggerServerEvent takes an element as the 2nd argument, not a boolean. Try to look at wiki examples, they should help you out.

Edited by pa3ck
Link to comment
3 minutes ago, pa3ck said:

That's not possible, you are definitely getting errors... You have this:


setPedArmor( 0, player )

setPedArmor takes a player element first. So you are getting element expected, got number error.

player is not defined in your code. When triggering from client to server and localPlayer is the source element, you can use 'client' variable server side to get the player element.


triggerServerEvent("setdaarmor",true)

You should use the wiki if you are new to scripting, triggerServerEvent takes an element as the 2nd argument, not a boolean. Try to look at wiki examples, they should help you out.

you mean i should use getElementType?

sorry if i missed understanding you

Link to comment
function setPlayersArmor(p, cmd)
	if ( getPedArmor(p) < 100 ) then
		setPedArmor(p, 100)
		outputChatBox("Your armor was restored", p)
	end  
end
addCommandHandler("setarmor", setPlayersArmor)

You can do all of this server side, there's no need to trigger from the client.

Edited by pa3ck
Link to comment
4 minutes ago, pa3ck said:

function setPlayersArmor(p, cmd)
	if ( getPedArmor(p) < 100 ) then
		setPedArmor(p, 100)
		outputChatBox("Your armor was restored", p)
	end  
end
addCommandHandler("setarmor", setPlayersArmor)

You can do all of this server side, there's no need to trigger from the client.

actually it worked ..thank you for this inspiration .

i tried to compare if the armor between 1 and 100

but i failed ,can you tell me about that ?

   if amount and tonumber(amount) >= 1 or tonumber(amount) <= 100 then 

 

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