Ryuto Posted November 27, 2023 Share Posted November 27, 2023 Hello, thanks for entering my post. I have a question... Is it possible to create a bind system that when pressing, for example, the "X" key repeatedly, different animations are played? I give an example: I press the "X" key for the first time, doing so plays a dance animation. Then I press the "X" again for the second time and doing so plays the vomiting animation. And so on. Link to comment
KhaledX Posted November 30, 2023 Share Posted November 30, 2023 (edited) Yes it Possible , and this a code for that .. local player = getLocalPlayer() local animIndex = 1 local lastPress = 0 -- list of animations local animations = { {"DANCING", "dnce_M_a"}, {"DANCING", "dnce_M_b"}, {"DANCING", "dnce_M_c"}, {"DANCING", "dnce_M_d"}, {"DANCING", "dnce_M_e"}, {"DANCING", "dnce_M_f"}, {"DANCING", "dnce_M_g"}, {"DANCING", "dnce_M_h"}, {"DANCING", "dnce_M_i"}, {"DANCING", "dnce_M_j"} } function cycleAnimation() local currentTime = getTickCount() if currentTime - lastPress < 500 then setPedAnimation(player) else local anim = animations[animIndex] setPedAnimation(player, anim[1], anim[2]) animIndex = animIndex % #animations + 1 end lastPress = currentTime end bindKey("x", "down", cycleAnimation) if you bind x it will change the Animation .. if you bind double x quickly it will stop the animation Edited November 30, 2023 by KhaledX Link to comment
Ryuto Posted December 2, 2023 Author Share Posted December 2, 2023 On 30/11/2023 at 00:00, KhaledX said: Yes it Possible , and this a code for that .. local player = getLocalPlayer() local animIndex = 1 local lastPress = 0 -- list of animations local animations = { {"DANCING", "dnce_M_a"}, {"DANCING", "dnce_M_b"}, {"DANCING", "dnce_M_c"}, {"DANCING", "dnce_M_d"}, {"DANCING", "dnce_M_e"}, {"DANCING", "dnce_M_f"}, {"DANCING", "dnce_M_g"}, {"DANCING", "dnce_M_h"}, {"DANCING", "dnce_M_i"}, {"DANCING", "dnce_M_j"} } function cycleAnimation() local currentTime = getTickCount() if currentTime - lastPress < 500 then setPedAnimation(player) else local anim = animations[animIndex] setPedAnimation(player, anim[1], anim[2]) animIndex = animIndex % #animations + 1 end lastPress = currentTime end bindKey("x", "down", cycleAnimation) if you bind x it will change the Animation .. if you bind double x quickly it will stop the animation Thank you very much, it has worked very well for me. I want to ask how I can run the animations server-side so everyone can see them. Link to comment
KhaledX Posted December 11, 2023 Share Posted December 11, 2023 (edited) On 02/12/2023 at 05:36, Ryuto said: Thank you very much, it has worked very well for me. I want to ask how I can run the animations server-side so everyone can see them. Sorry for late , Code ( Client Side ) : local player = getLocalPlayer() local animIndex = 1 local lastPress = 0 -- list of animations local animations = { {"DANCING", "dnce_M_a"}, {"DANCING", "dnce_M_b"}, {"DANCING", "dnce_M_c"}, {"DANCING", "dnce_M_d"}, {"DANCING", "dnce_M_e"}, {"DANCING", "dnce_M_f"}, {"DANCING", "dnce_M_g"}, {"DANCING", "dnce_M_h"}, {"DANCING", "dnce_M_i"}, {"DANCING", "dnce_M_j"} } function cycleAnimation() local currentTime = getTickCount() if currentTime - lastPress < 500 then setPedAnimation(player) triggerServerEvent("stopAnimation", player) else local anim = animations[animIndex] setPedAnimation(player, anim[1], anim[2]) triggerServerEvent("applyAnimation", player, anim[1], anim[2]) animIndex = animIndex % #animations + 1 end lastPress = currentTime end bindKey("x", "down", cycleAnimation) Code ( Server Side ) : addEvent("applyAnimation", true) addEventHandler("applyAnimation", root, function(block, anim) setPedAnimation(source, block, anim) end) addEvent("stopAnimation", true) addEventHandler("stopAnimation", root, function() setPedAnimation(source) end) Edited December 11, 2023 by KhaledX 1 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