AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Grenade ammo *SOLVED* (https://forums.alliedmods.net/showthread.php?t=24395)

v3x 02-21-2006 05:07

Grenade ammo *SOLVED*
 
When the user touches a nade it gives him TWO nades instead of one. Reason being is because CS gives him the spawned nade and what not and then my plugin gives him a nade when it specifically checks if his bpammo is > 0 (already has grenade). I tried these 2 methods:

Method 1:
Code:
register_touch("armoury_entity" , "player" , "touch_player"); /* [...] */ public touch_player(pToucher , pTouched) {     if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pTouched)) {         return PLUGIN_CONTINUE;     }     new pToucherMdl[64];     entity_get_string(pToucher , EV_SZ_model , pToucherMdl , 63);     new model = check_nade_model(pToucherMdl);     if(model > -1) {         if(is_user_alive(pTouched)) {             new ammo;             ammo = cs_get_user_bpammo(pTouched , model);             new max_ammo;             switch(model) {                 case CSW_FLASHBANG: max_ammo = get_nade_num(CSW_FLASHBANG);                 case CSW_HEGRENADE: max_ammo = get_nade_num(CSW_HEGRENADE);                 case CSW_SMOKEGRENADE:  max_ammo = get_nade_num(CSW_SMOKEGRENADE);             }             if(ammo > 0 && ammo < max_ammo) { /* Checking the ammo */                 remove_entity(pToucher);                 new param[2];                 param[0] = pTouched;                 param[1] = model;                 set_task(0.1 , "give_nade" , random_num(999,9999) , param , 2);             }         }     } }
Gives nades 1 at a time ( only when you don't have the type of nade out that you just touched ).

Method 2:
Code:
register_touch("armoury_entity" , "player" , "touch_player"); /* [...] */ public touch_player(pToucher , pTouched) {     if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pTouched)) {         return PLUGIN_CONTINUE;     }     new pToucherMdl[64];     entity_get_string(pToucher , EV_SZ_model , pToucherMdl , 63);     new model = check_nade_model(pToucherMdl);     if(model > -1) {         if(is_user_alive(pTouched)) {             new ammo , ammo1 , clip , weap = get_user_weapon(pTouched , ammo1 , clip);             if(weap != CSW_FLASHBANG && weap != CSW_HEGRENADE && weap != CSW_SMOKEGRENADE) {                 ammo = cs_get_user_bpammo(pTouched , model);             } else {                 ammo = cs_get_weapon_ammo(pTouched);             }             new max_ammo;             switch(model) {                 case CSW_FLASHBANG: max_ammo = get_nade_num(CSW_FLASHBANG);                 case CSW_HEGRENADE: max_ammo = get_nade_num(CSW_HEGRENADE);                 case CSW_SMOKEGRENADE:  max_ammo = get_nade_num(CSW_SMOKEGRENADE);             }             if(ammo > 0 && ammo < max_ammo) {                 remove_entity(pToucher);                 new param[2];                 param[0] = pTouched;                 param[1] = model;                 set_task(0.1 , "give_nade" , random_num(999,9999) , param , 2);             }         }     } }

A few functions that are used in there:
Code:
public give_nade(param[]) {     new id = param[0];     new nade = param[1];     new ammo = cs_get_user_bpammo(id , nade);     cs_set_user_bpammo(id , nade , ammo + 1);     emit_sound(id, CHAN_WEAPON , "items/9mmclip1.wav" , 1.0 , ATTN_NORM , 0 , PITCH_NORM); } public check_nade_model(model[]) {     if( containi( model, "w_flashbang.mdl"    ) != -1 ) return CSW_FLASHBANG;     if( containi( model, "w_hegrenade.mdl"    ) != -1 ) return CSW_HEGRENADE;     if( containi( model, "w_smokegrenade.mdl" ) != -1 ) return CSW_SMOKEGRENADE;     return -1; } public get_nade_num(nade) {     switch(nade) {         case CSW_FLASHBANG: return get_cvar_num(CVAR_FB);         case CSW_HEGRENADE: return get_cvar_num(CVAR_HE);         case CSW_SMOKEGRENADE:  return get_cvar_num(CVAR_SG);     }     return -1; }
Gives 2 nades instead of 1 for the first one.

Also, it permanently removes the spawned nades from the map.

Help would be greatly appreciated :|

Kraugh 02-21-2006 15:55

try returning PLUGIN_HANDLED after setting your task.

if you don't want it to permanently remove it, instead of removing it try setting it so that it doesn't render (set_entity_visibility), set some flag to 1 (ie: EV_INT_iuser1 or anything else that isn't used). whenever a touch comes up, if that flag is 1, then return PLUGIN_HANDLED right away.

when the round starts go through all armoury_entity's and set their flags to 0.

v3x 02-21-2006 17:55

Ahem? :?

Kraugh 02-21-2006 18:34

this is using your example 1:

Code:
 register_touch("armoury_entity" , "player" , "touch_player"); /* [...] */ public touch_player(pToucher , pTouched) {     if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pTouched)) {         return PLUGIN_CONTINUE;     }     // if flag is set     if(entity_get_int(pToucher,EV_INT_iuser1))         return PLUGIN_HANDLED;     new pToucherMdl[64];     entity_get_string(pToucher , EV_SZ_model , pToucherMdl , 63);     new model = check_nade_model(pToucherMdl);     if(model > -1) {         if(is_user_alive(pTouched)) {             new ammo;             ammo = cs_get_user_bpammo(pTouched , model);             new max_ammo;             switch(model) {                 case CSW_FLASHBANG:    max_ammo = get_nade_num(CSW_FLASHBANG);                 case CSW_HEGRENADE:    max_ammo = get_nade_num(CSW_HEGRENADE);                 case CSW_SMOKEGRENADE:    max_ammo = get_nade_num(CSW_SMOKEGRENADE);             }             if(ammo > 0 && ammo < max_ammo) { /* Checking the ammo */                 set_entity_visibility(pToucher,0); // make it invisible                 entity_set_int(pToucher,EV_INT_iuser1,1); // set flag                 new param[2];                 param[0] = pTouched;                 param[1] = model;                 set_task(0.1 , "give_nade" , random_num(999,9999) , param , 2);                 return PLUGIN_HANDLED; // be sure that this touch does not count             }         }     }     return PLUGIN_CONTINUE; }

you would then have to hook when a round ends (or starts), cycle through all armoury_entity's and set their visibility to 1 as well as their EV_INT_iuser1 to 0.

v3x 02-21-2006 19:40

Oh, I see now.

I'll report back later with the results ;]

v3x 02-22-2006 09:27

It worked as far as spawning the nades again. It still gives the first nade though. I think this is because of cs_set_user_bpammo. Any suggestions?

Kraugh 02-22-2006 14:48

echo out the values of ammo and max_ammo right before your "Checking the ammo" if statement.

v3x 02-23-2006 00:23

Code:
public touch_player(pToucher , pTouched) {     if(!is_valid_ent(pToucher) || !is_valid_ent(pTouched) || !is_user_connected(pTouched)) {         return PLUGIN_CONTINUE;     }     if(entity_get_int(pToucher , EV_INT_iuser1)) {         return PLUGIN_HANDLED;     }     new pToucherMdl[64];     entity_get_string(pToucher , EV_SZ_model , pToucherMdl , 63);     new model = check_nade_model(pToucherMdl);     if(model > -1) {         if(is_user_alive(pTouched)) {             new ammo = cs_get_user_bpammo(pTouched , model);             new max_ammo;             switch(model) {                 case CSW_FLASHBANG: max_ammo = get_nade_num(CSW_FLASHBANG);                 case CSW_HEGRENADE: max_ammo = get_nade_num(CSW_HEGRENADE);                 case CSW_SMOKEGRENADE:  max_ammo = get_nade_num(CSW_SMOKEGRENADE);             }             new userid = get_user_userid(pTouched);             log_amx("[0] <%d> Ammo %d - Max ammo %d - Type: %d" , userid , ammo , max_ammo , model);             if(ammo > 0 && ammo < max_ammo) {                 log_amx("[1] <%d> Ammo %d - Max ammo %d - Type: %d" , userid , ammo , max_ammo , model);                 set_entity_visibility(pToucher , 0);                 entity_set_int(pToucher , EV_INT_iuser1 , 1);                 new param[2];                 param[0] = pTouched;                 param[1] = model;                 set_task(0.1 , "give_nade" , random_num(999,9999) , param , 2);                 return PLUGIN_HANDLED;             }         }     }     return PLUGIN_CONTINUE; }
Outputs:
Quote:

L 02/23/2006 - 00:22:16: [grenade_sack.amxx] [0] <16> Ammo 0 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:16: [grenade_sack.amxx] [0] <16> Ammo 1 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:16: [grenade_sack.amxx] [1] <16> Ammo 1 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:17: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:40: [grenade_sack.amxx] [0] <16> Ammo 0 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:40: [grenade_sack.amxx] [0] <16> Ammo 1 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:40: [grenade_sack.amxx] [1] <16> Ammo 1 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:53: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:53: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:53: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:53: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4
L 02/23/2006 - 00:22:53: [grenade_sack.amxx] [0] <16> Ammo 2 - Max ammo 2 - Type: 4

v3x 02-23-2006 07:42

EDIT: FIXED!

Jordan 02-23-2006 16:45

Yes! This means Dwarfs on your server should be fixed :D


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

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