AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Set player animation (https://forums.alliedmods.net/showthread.php?t=240210)

arbol 05-10-2014 20:25

Set player animation
 
Hello Modders,
I want to write a simple plugin which sets the player animation to any of the default existing animations.
I tried with this code from Andersso:

Code:

#include <sourcemod>
#include <sdktools>

public OnPluginStart()
{
   
AddTempEntHook("PlayerAnimEvent", OnPlayerAnimEvent);
   
   
RegConsoleCmd("test_playeranimevent", Command_TestPlayerAnimEvent);
}

public
Action:OnPlayerAnimEvent(const String:te_name[], const Players[], numClients, Float:delay)
{
    new
client    = TE_ReadNum("m_hPlayer");
    new
event    = TE_ReadNum("m_iEvent");
    new
data    = TE_ReadNum("m_nData");
   
   
PrintToChatAll("AnimEvent: Player: %i, Event: %i, Data: %i", client, event, data);
}

public
Action:Command_TestPlayerAnimEvent(client, args)
{
   
decl String:arg1[64], String:arg2[64], String:arg3[64];
   
   
GetCmdArg(1, arg1, sizeof(arg1));
   
GetCmdArg(2, arg2, sizeof(arg2));
   
GetCmdArg(3, arg3, sizeof(arg3));
   
   
TE_Start("PlayerAnimEvent");
   
   
TE_WriteNum("m_hPlayer", StringToInt(arg1));
   
TE_WriteNum("m_iEvent", StringToInt(arg2));
   
TE_WriteNum("m_nData", StringToInt(arg3));
   
   
TE_SendToAll();

And tested it on my servers, and worked ! but there is a big problem with this code: It doesn't tell me the client number (from the server perspective)
Example: client=0 is the server itself, client=1 is usually the first player entering game, etc.

I would like to write a simple function that sets a client (argument by clientId) animation to any of the default ones (like crouching, knife, etc)

Oshizu 05-11-2014 05:47

Re: Set player animation
 
From what i remember PlayerAnimEvent seems to be a little buggy
Sometimes it works, sometimes it does not!

Might need multiple firing to work aswell.

h3bus 05-11-2014 14:00

Re: Set player animation
 
The client index seems to be in arg1 and is converted from string to int...

If I understand well you just need to rip out the TE_ part and make it use function args
PHP Code:

stock sendPlayerAnimToAll(clienteventdata)
{
    
TE_Start("PlayerAnimEvent");
    
    
TE_WriteNum("m_hPlayer"client);
    
TE_WriteNum("m_iEvent"event);
    
TE_WriteNum("m_nData"data);
    
    
TE_SendToAll();



friagram 05-11-2014 22:48

Re: Set player animation
 
Aes depend on what the client expects the model to do, if it expects another sequence to play over what was just played, or to blend with that, you wont see the event issued.

Andersso 05-12-2014 16:35

Re: Set player animation
 
I believe the m_hPlayer property is the entity handle of the client, not index.

If I recall correctly, you can do index->ref->handle like this:
PHP Code:

new entityHandle EntIndexToEntRef(entityIndex) & 0x7FFF

And vice versa:
PHP Code:

new entityIndex EntRefToEntIndex(entityHandle | ~0x7FFF); 

What it does is to mask in/out the negative bit-flag of the integer value

Not tested, just out of my head, so I excuse myself if I got this wrong.

Powerlord 05-12-2014 16:55

Re: Set player animation
 
Quote:

Originally Posted by Andersso (Post 2136913)
I believe the m_hPlayer property is the entity handle of the client, not index.

If I recall correctly, you can do index->ref->handle like this:
PHP Code:

new entityHandle EntIndexToEntRef(entityIndex) & 0x7FFF

And vice versa:
PHP Code:

new entityIndex EntRefToEntIndex(entityHandle | ~0x7FFF); 

What it does is to mask in/out the negative bit-flag of the integer value

Not tested, just out of my head, so I excuse myself if I got this wrong.

Isn't creating these types of refs what MakeCompatEntRef is for?

Andersso 05-12-2014 17:46

Re: Set player animation
 
Yeah I thought so too, perhaps it's a bug.

EDIT: Tested it again, and it works. Probably missed something out last time

arbol 05-17-2014 18:07

Re: Set player animation
 
Quote:

Originally Posted by Andersso (Post 2136929)
Yeah I thought so too, perhaps it's a bug.

EDIT: Tested it again, and it works. Probably missed something out last time

Hi Andersso
Would you provide another code for setting a player's animation by clientid?

It would help a lot ! And this issue is a very important one (i guess) , useful in many different mods.

arbol 05-17-2014 19:26

Re: Set player animation
 
Modders:

So far this is what i've got

new clId = MakeCompatEntRef(client);

The command above transforms a big number (for example: 25231361) into a legible Client Id (1 for the first player, 2 for the next one, etc., probably 0 for the server but the server doesn't execute animations so it doesn't matter)

I need the reverse transform, the one that would transform a Client Id into the big number that appears in "m_hPlayer"

OR

A function that, given the ClientId, returns the "m_hPlayer" number (the big number above)


HELP NEEDED HERE, WOULD BE VERY GLAD IF WE CAN FINALLY BUILD SOMETHING THAT CAN CHANGE PLAYER ANIMATION !

Powerlord 05-18-2014 01:23

Re: Set player animation
 
What animations are you trying to do anyway?

The player object's SetAnimation can already do any of these:

Code:

        PLAYER_IDLE,
        PLAYER_WALK,
        PLAYER_JUMP,
        PLAYER_SUPERJUMP,
        PLAYER_DIE,
        PLAYER_ATTACK1,
        PLAYER_IN_VEHICLE,

        // TF Player animations
        PLAYER_RELOAD,
        PLAYER_START_AIMING,
        PLAYER_LEAVE_AIMING,

Alternately, the player object's SetActivity can do that, but you'll likely need to call both SetActivity and ResetSequence instead... but it's not clear where you get the sequence values for ResetSequence.


All times are GMT -4. The time now is 03:41.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.