Announcement

Collapse
No announcement yet.

Best Way To Check And Stop Animations?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Best Way To Check And Stop Animations?

    I have a script that allows a player to type "/dance" in chat to play a dance animation. I am currently looking for a way to stop the animation if the player presses ANY key (ex. WSAD, mouse click, etc.). I am using a server script to start the animation with the players input. I'm then using CallRemoteEvent from a client script to call the server script to stop dancing if a player presses any key. I have two questions about this:

    1. Is this the correct way to implement something like this?
    2. If so, is there a good way to check if the player is dancing or playing a different animation?

    With question 2, the current implementation I have works, but every time a client presses a button a call is made to the server which would cause an unnecessary amount of calls/traffic. I'm seemingly not able to use the GetPlayerAnimation function correctly. Here is an example of my scripts:

    Server
    Code:
    --
    --Dance
    --
    AddCommand("dance", function(playerid)
        SetPlayerAnimation(playerid, "DANCE90")
        AddPlayerChat(playerid, "dancing.")
    end)
    
    AddRemoteEvent("stopit", function(playerid)
        SetPlayerAnimation(playerid, "STOP")
        AddPlayerChat(playerid, "Stopping what we are doing.")
    end)
    Client
    Code:
    AddEvent("OnKeyPress", function(key)
            CallRemoteEvent("stopit")
    end)
Working...
X