JeViCo Posted January 25, 2018 Share Posted January 25, 2018 Hi everyone! I can't understand at least one thing here: When player press button "0" his weapon slot switch to fist. I almost made it. I don't know how to import slot number from client side I made like this pressedkey = weap_slot and then setPedWeaponSlot(source,button) // variable button is undefined and then i triggered client event. I have no ideas. If i trigger client, engine looks like client(setPedWeaponSlot)->server(call client slot variable)->client(returns)->server(execute)->client or i can do it in eazier way? Link to comment
pa3ck Posted January 25, 2018 Share Posted January 25, 2018 I don't understand at least one thing here. What are you trying to achieve? client-server-client-server-client, that is not communication between server and client, that's a whole conversation.. Link to comment
JeViCo Posted January 25, 2018 Author Share Posted January 25, 2018 1 hour ago, pa3ck said: I don't understand at least one thing here. What are you trying to achieve? client-server-client-server-client, that is not communication between server and client, that's a whole conversation.. just trying to switch weapons by pressing numbers on keyboard and that's it Link to comment
pa3ck Posted January 25, 2018 Share Posted January 25, 2018 Oh, I see, what do you have so far? Post your full code Link to comment
JeViCo Posted January 25, 2018 Author Share Posted January 25, 2018 49 minutes ago, pa3ck said: Oh, I see, what do you have so far? Post your full code client function PressedKey(button, press) if (press) and button=="1" then outputChatBox("Seems to work") // detect button press triggerServerEvent("weap_change",localPlayer,button) end end addEventHandler("onClientKey", root, PressedKey) server addEvent("weap_change",true) addEventHandler("weap_change",root,function () setPedWeaponSlot(source,button) // button not found in here end ) I'm going to make 0-9 numbers action Link to comment
kieran Posted January 25, 2018 Share Posted January 25, 2018 https://wiki.multitheftauto.com/wiki/BindKey https://wiki.multitheftauto.com/wiki/GetPedWeaponSlot https://wiki.multitheftauto.com/wiki/SetPedWeaponSlot This will eliminate the need for the client side file altogether, use bindKey instead and bind each key to set the players weapon slot, getPedWeaponSlot is just there too because it might be useful, depends what errors happen, I never used keys for weapons before.... You can also use all 3 of those client side, eliminating the need for server file and freeing up space on your server/host, but I do not know if that changes only for local player or for all players. Link to comment
Scripting Moderators thisdp Posted January 26, 2018 Scripting Moderators Share Posted January 26, 2018 (edited) addEvent("weap_change",true) addEventHandler("weap_change",root,function (button) setPedWeaponSlot(source,tonumber(button)) end ) Edited January 26, 2018 by thisdp Link to comment
JeViCo Posted January 26, 2018 Author Share Posted January 26, 2018 (edited) thanks, now it works, but now i have 2 problems. onClientKey event makes this script work twice - when key is pressed and whet it released(with the exception of key "0"). Also i don't know how to make this conditions less: button=="0" or button=="1" or button=="2" or button=="3" or button=="4" or button=="5" or button=="6" or button=="7" or button=="8" or button=="9" then How can i fix that all? Edited January 26, 2018 by JeViCo Link to comment
kieran Posted January 27, 2018 Share Posted January 27, 2018 Right, first when you find something on the wiki, read the parameters!!! Parameters are very useful, in your case, with the onClientKey handler the parameters are (button) and (pressed) so it returns 3 things in total... "button" is the button pressed, "pressed" is true if the key is down, FALSE if the key is up So instead of doing this: function PressedKey(button, press) if (press) and button=="1" then Try this: function PressedKey(button, press) if (press == true) and button=="1" then Hope this helps.... In theory, if checks if a value is true, so if (press) should only happen when your key is pressed, if this doesn't work, look into using bindKey instead and bind each different key to set the weapon slot. Link to comment
JeViCo Posted January 27, 2018 Author Share Posted January 27, 2018 6 hours ago, kieran said: Right, first when you find something on the wiki, read the parameters!!! Parameters are very useful, in your case, with the onClientKey handler the parameters are (button) and (pressed) so it returns 3 things in total... "button" is the button pressed, "pressed" is true if the key is down, FALSE if the key is up nope if (press) and button=="0" or (press) and button=="1" or (press) and button=="2" or (press) and button=="3" or (press) and button=="4" or (press) and button=="5" or (press) and button=="6" or (press) and button=="7" or (press) and button=="8" or (press) and button=="9" then i tried this and it works, but it's so long. Have no ideas to make this part of code less Link to comment
Jayceon Posted January 27, 2018 Share Posted January 27, 2018 (edited) local isNumKey = tonumber(button) if press and (isNumKey and isNumKey >= 0 and isNumKey <= 9) then --trigger or something end Edited January 27, 2018 by Jayceon 1 1 Link to comment
JeViCo Posted January 27, 2018 Author Share Posted January 27, 2018 2 hours ago, Jayceon said: local isNumKey = tonumber(button) if press and (isNumKey and isNumKey >= 0 and isNumKey <= 9) then --trigger or something end 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