Deep thinker Posted May 11, 2017 Share Posted May 11, 2017 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
pa3ck Posted May 11, 2017 Share Posted May 11, 2017 function storeArmor ( ) -> your function name addCommandHandler ( "storearmor", showArmor ) -> your commandHandler should be addCommandHandler ( "storearmor", storeArmor) Link to comment
Deep thinker Posted May 11, 2017 Author Share Posted May 11, 2017 oh actually ,i didn't notice that ,1 sec i will test it thank you i got warning at line 2 Bad Argument and Expected Ped at argument ,got nil 7 minutes ago, pa3ck said: function storeArmor ( ) -> your function name addCommandHandler ( "storearmor", showArmor ) -> your commandHandler should be addCommandHandler ( "storearmor", storeArmor) not working Link to comment
Dimos7 Posted May 11, 2017 Share Posted May 11, 2017 --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
Deep thinker Posted May 11, 2017 Author Share Posted May 11, 2017 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
pa3ck Posted May 11, 2017 Share Posted May 11, 2017 (edited) 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 May 11, 2017 by pa3ck Link to comment
Deep thinker Posted May 11, 2017 Author Share Posted May 11, 2017 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
pa3ck Posted May 11, 2017 Share Posted May 11, 2017 (edited) 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 May 11, 2017 by pa3ck Link to comment
Deep thinker Posted May 11, 2017 Author Share Posted May 11, 2017 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
Deep thinker Posted May 11, 2017 Author Share Posted May 11, 2017 5 minutes ago, pa3ck said: Is amount defined anywhere? i tried to define it on if getPedArmor == amount and tonumber(amount) >= 1 or tonumber(amount) <= 100 then but certainly failed Link to comment
pa3ck Posted May 11, 2017 Share Posted May 11, 2017 No, that is not how it works. getPedArmor is a function that need arguments, you can't just compare it to other values like that. I suggest you to go and check out this topic: And this section: https://forum.multitheftauto.com/forum/123-tutorials/ 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