PDA

View Full Version : player setAnim(string);



filthy_freak_
1st July 2015, 02:41
With this function you can force a player to play a specified animation using gsc. It can also be used to force a bot to change stance.

http://killtube.org/downloads/filthy_freak/setanim.gif

Usage:


player setAnim("pb_crouch_run_forward");
player setAnim("none"); //reset back to normal


It is recommended doing the following on player connect to ensure there are no conflicts;


self setAnim("none");


Installation:
Open gsc.cpp, CTRL + F and search for "setweaponfiremeleedelay". Then add the following on a new line;


{"setanim" , gsc_player_set_anim , 0},


Open gsc_player.hpp, CTRL + F and search for "void gsc_player_setweaponfiremeleedelay(int id);". Then add the following on a new line;


void gsc_player_set_anim(int id);


Open gsc_player.cpp, CTRL + F and search for "// entity functions". Then add the following on a new line;


void gsc_player_set_anim(int id)
{
char* animation;

if ( ! stackGetParams("s", &animation)) {
printf("scriptengine> ERROR: gsc_player_set_anim(): param \"animation\"[1] has to be an string!\n");
stackPushUndefined();
return;
}

#if COD_VERSION == COD2_1_0
int anim_offset = 0x080D46AC;
#elif COD_VERSION == COD2_1_2
int anim_offset = 0x080D6C8C;
#elif COD_VERSION == COD2_1_3
int anim_offset = 0x080D6DD0;
#endif

int (*BG_AnimationIndexForString)(char *src);
*(int *)&BG_AnimationIndexForString = anim_offset;

int animationIndex = 0;
extern int custom_animation[64];

if(strcmp(animation, "none"))
animationIndex = BG_AnimationIndexForString(animation);

custom_animation[id] = (animationIndex);
}


Open libcod.cpp, CTRL + F and search for "void hook_SV_WriteDownloadToClient(int cl, int msg)". Then add the following function before "void hook_SV_WriteDownloadToClient(int cl, int msg)";


int clientaddress_to_num(int client);
int custom_animation[64] = {0};
cHook *hook_set_anim;
int set_anim(int a1, int a2, signed int a3, int a4, int a5, int a6, int a7)
{
int clientnum = clientaddress_to_num(a1);
extern int playerinfo_base, playerinfo_size;

if(*(int*)(*(int*)playerinfo_base + clientnum * playerinfo_size) == 4 && custom_animation[clientnum])
{
a2 = custom_animation[clientnum];
a4 = 0;
a5 = 1;
a6 = 0;
a7 = 1;
}

hook_set_anim->unhook();
int (*sig)(int a1, int a2, signed int a3, int a4, int a5, int a6, int a7);
*(int *)&sig = hook_set_anim->from;
int ret = sig(a1, a2, a3, a4, a5, a6, a7);
hook_set_anim->hook();

return ret;
}


Also while in libcod.cpp, search and add the following new lines depending on your version;

1.0;
Search for "cracking_hook_call(0x080707C3, (int)Scr_GetCustomMethod);"
Add the following on a new line;


hook_set_anim = new cHook(0x080D69B2, (int)set_anim);
hook_set_anim->hook();


1.2;
Search for "cracking_hook_call(0x08070D3F, (int)Scr_GetCustomMethod);"
Add the following on a new line;


hook_set_anim = new cHook(0x080D8F92, (int)set_anim);
hook_set_anim->hook();


1.3;
Search for "cracking_hook_call(0x08070E0B, (int)Scr_GetCustomMethod);"
Add the following on a new line;


hook_set_anim = new cHook(0x080D90D6, (int)set_anim);
hook_set_anim->hook();


Compile your libcod version and you are done.

Or download the attached file and compile.

maxdamage99
12th August 2015, 14:10
Good work :)

Ni3ls
4th September 2015, 15:26
How do you know all anims? Where are they listed?

php
4th September 2015, 15:35
for cod2 in iw_07.iwd in file mp\playeranim.script or animtrees\multiplayer.atr