Raised This Month: $51 Target: $400
 12% 

Set player animation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
arbol
Junior Member
Join Date: Sep 2013
Location: Argentina
Old 05-10-2014 , 20:25   Set player animation
Reply With Quote #1

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)
arbol is offline
Oshizu
Veteran Member
Join Date: Nov 2012
Location: Warsaw
Old 05-11-2014 , 05:47   Re: Set player animation
Reply With Quote #2

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.
__________________
...

Last edited by Oshizu; 05-11-2014 at 14:28.
Oshizu is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 05-11-2014 , 14:00   Re: Set player animation
Reply With Quote #3

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();


Last edited by h3bus; 05-11-2014 at 14:04.
h3bus is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 05-11-2014 , 22:48   Re: Set player animation
Reply With Quote #4

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.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Andersso
Member
Join Date: Nov 2009
Location: E8 2A 2A 2A 2A
Old 05-12-2014 , 16:35   Re: Set player animation
Reply With Quote #5

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.
Andersso is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-12-2014 , 16:55   Re: Set player animation
Reply With Quote #6

Quote:
Originally Posted by Andersso View Post
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?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Andersso
Member
Join Date: Nov 2009
Location: E8 2A 2A 2A 2A
Old 05-12-2014 , 17:46   Re: Set player animation
Reply With Quote #7

Yeah I thought so too, perhaps it's a bug.

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

Last edited by Andersso; 05-12-2014 at 20:28.
Andersso is offline
arbol
Junior Member
Join Date: Sep 2013
Location: Argentina
Old 05-17-2014 , 18:07   Re: Set player animation
Reply With Quote #8

Quote:
Originally Posted by Andersso View Post
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 is offline
arbol
Junior Member
Join Date: Sep 2013
Location: Argentina
Old 05-17-2014 , 19:26   Re: Set player animation
Reply With Quote #9

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 !
arbol is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-18-2014 , 01:23   Re: Set player animation
Reply With Quote #10

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.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-18-2014 at 01:28.
Powerlord is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 20:40.


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