Raised This Month: $ Target: $400
 0% 

Grenade ammo *SOLVED*


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-21-2006 , 05:07   Grenade ammo *SOLVED*
Reply With Quote #1

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
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 02-21-2006 , 15:55  
Reply With Quote #2

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.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-21-2006 , 17:55  
Reply With Quote #3

Ahem?
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 02-21-2006 , 18:34  
Reply With Quote #4

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.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-21-2006 , 19:40  
Reply With Quote #5

Oh, I see now.

I'll report back later with the results ;]
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-22-2006 , 09:27  
Reply With Quote #6

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?
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Kraugh
Senior Member
Join Date: Jan 2006
Location: barrington, ri
Old 02-22-2006 , 14:48  
Reply With Quote #7

echo out the values of ammo and max_ammo right before your "Checking the ammo" if statement.
__________________
"You can not restrain a fool from speaking, but nothing obliges you to listen."
Kraugh is offline
Send a message via AIM to Kraugh
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-23-2006 , 00:23  
Reply With Quote #8

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
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
v3x
Veteran Member
Join Date: Oct 2004
Location: US
Old 02-23-2006 , 07:42  
Reply With Quote #9

EDIT: FIXED!
__________________
What am I doing these days? Well, I run my own Rust server. It's heavily modded. If you'd like to join, the ip is 167.114.101.67:28116

I also created a website called Rust Tools. It will calculate and tell you the raw amounts of resources needed to craft items.
v3x is offline
Jordan
Veteran Member
Join Date: Aug 2005
Old 02-23-2006 , 16:45  
Reply With Quote #10

Yes! This means Dwarfs on your server should be fixed
Jordan 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:17.


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