AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   Shield Tutorial (https://forums.alliedmods.net/showthread.php?t=6254)

Freecode 09-25-2004 14:03

Shield Tutorial
 
Heres a new way of getting whether a person has shield.
By sequence
Code:
#include <amxmodx> #include <amxmisc> #include <engine> public plugin_init() {     register_plugin("Shield","1.0","default");     register_clcmd("get_shield","shield",ADMIN_LEVEL_A,": name") } public shield(id) {     new arg[32]     read_argv(1,arg,31)         new vid = cmd_target(id,arg,8);         new seq = entity_get_int(vid,EV_INT_sequence);         new name[32]     get_user_name(vid,name,31);         //SEQUENCCE 89 = Shield + Knife     //SEQUENCE 94 = Shield + Pistol     //SEQUENCE 98 = Shield only (right clicked)             if(seq == 89)     {         client_print(0,3,"%s has shield and a knife",name);     }     else if(seq == 94)     {         client_print(0,3,"%s has shield and a pistol",name);     }     else if(seq == 98)     {         client_print(0,3,"%s has shield",name);     }         client_print(0,3,"Sequence: %d",seq);         return PLUGIN_HANDLED }

Freecode 09-25-2004 14:53

Another one. Originaly posted by Ryan on AMX forums.

Code:
#include <amxmodx> #include <engine> new bool:gotShield[33] public pfn_touch(ptr, ptd) {     new entId   = ptr     new id      = ptd     if ( id < 0 || id > 32 || !is_user_alive(id) || gotShield[id] )         return PLUGIN_CONTINUE     new modelName[32]     entity_get_string(entId, EV_SZ_model, modelName, 31)     if ( containi(modelName,"w_shield.mdl") != -1 ) {         new parm[1]         parm[0] = id         remove_task(2200 + id,0)         set_task(0.1,"check_shield",2200 + id,parm,1)     }     return PLUGIN_CONTINUE } public check_shield(parm[1]) {     new id = parm[0]     new modelName[32]     entity_get_string(id, EV_SZ_viewmodel, modelName, 31)     if ( containi(modelName,"v_shield_") != -1 ) {         // Do some stuff in here. It's found!     }             return PLUGIN_HANDLED }

Freecode 09-26-2004 13:48

Hmm the shield Offset in CS is 494. Only a few bugs with it though. (engine problem of-course)
Im gonna do a few more tests and let you now about it

Ryan 09-26-2004 18:58

The problem is finding an efficient way of getting the shield (ie- a forward).. having to listen to too many events for different parts makes for big and sloppy code to find out one simple thing! and setting a milisecond timer (task) is a no no.

the only ways to detect shield are...

client command: shield (whatever buys it right out)
menu command: equipment menu, key 8
touch event when walking over it to pick it up
hideweapon event -OR- curweapon event... just in case any of the above were missed.

however, many plugins give players shields via the give_item function, which does not trigger any of the above events.

it's too bad valve (ming) didnt make this easier for scripters to detect.

SidLuke 09-26-2004 19:23

so you need shield_pickup , shield_drop forwards...
I did a look at messages when you drop/pickup shiled but none of them was send (even hide weapon and current weapon do not detect shield ... ). I will try to find another way but I can't promise you anything...

Freecode 09-26-2004 21:56

the offset works fine but the engine seems to be messing up sometimes. i think i found a fix for it but dont noe yet. I got a custume edited cstrike with get_user_shield(id) native added and it seems to be working.

Geesu 09-27-2004 08:06

Quote:

Originally Posted by Freecode
the offset works fine but the engine seems to be messing up sometimes. i think i found a fix for it but dont noe yet. I got a custume edited cstrike with get_user_shield(id) native added and it seems to be working.


ewww sounds yummy....

Johnny got his gun 09-30-2004 04:09

Code:
/* Returns 1 when user has a primary weapon OR a shield in inventory, else 0.  */ native cs_get_user_hasprim(index);

If it returns 0 you can be sure user has no shield...

Geesu 10-24-2004 22:44

but sometimes we JUST want to know if it is a shield, like weapon reincarnation in war3 :)

Also, why is this needed:

new arg[32]
read_argv(1,arg,31)

new vid = cmd_target(id,arg,8);

Geesu 11-30-2004 09:44

Freecode ever get anywhere on that offset thing?


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

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