Jump to content

[HELP] Binds with different animations


Ryuto

Recommended Posts

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?

 

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

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 by KhaledX
Link to comment
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
  • 2 weeks later...

 

  

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 by KhaledX
  • Thanks 1
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...