AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED] Setting weapon ammo... (https://forums.alliedmods.net/showthread.php?t=54464)

bwgrubbs1 04-26-2007 13:57

[SOLVED] Setting weapon ammo...
 
Ok I have everything just fine...but for some reason when I use this code.

Code:
public rndWEPS(id) {     new rnd     rnd = random_num(0,100)     if( rnd <= 5)     {         give_item(id, "weapon_awp")     cs_set_user_bpammo(id, CSW_AWP, 0)     cs_set_weapon_ammo(CSW_AWP, 3)     client_print(id, print_chat, "You got an awp with 3 bullets! (1/20 Chance)")     }     else if(rnd > 5 && rnd <= 15)     {         give_item(id, "weapon_p228")     cs_set_user_bpammo(id, CSW_P228, 0)     cs_set_weapon_ammo(CSW_P228, 2)     client_print(id, print_chat, "You got a P228 with 2 bullets! (1/10 Chance)")     }     else if(rnd > 15 && rnd <= 30)     {         give_item(id, "item_shield")     client_print(id, print_chat, "You got a Shield! (1/6 Chance)")     }     else if(rnd > 30 && rnd <= 60)     {         give_item(id, "weapon_hegrenade")     client_print(id, print_chat, "You got a HE Grenade! (1/3 Chance)")     } }

For some unknown reason it gives the awp 10 bullets...or the p228 a full chamber and none in the clip...I want just 3 bullets for awp... what am I doing wrong ?

teame06 04-26-2007 14:05

Re: Setting weapon ammo...
 
cs_set_weapon_ammo requires the Weapon Entity Index. Not the Weapon Id Constant.

So your going to have to find the entity by owner. Ie .. "weapon_awp". Then use that Weapon Entity Index.

bwgrubbs1 04-26-2007 14:15

Re: Setting weapon ammo...
 
so if i did something like this ?

Code:
public rndWEPS(id) {     new rnd     new players[32], num     new i     get_players(players, num)     rnd = random_num(0,100)     if( rnd <= 100)     {         for (i=0; i < num; i++)         {         give_item(player[i], "weapon_csw_awp")         cs_set_user_bpammo(player[i], CSW_AWP, 0)         cs_set_weapon_ammo(player[i], 3)         }         client_print(player[i], print_chat, "You got an awp with 3 bullets! (1/20 Chance)")     }     else if(rnd >5 && rnd <= 15)     {         give_item(id, "weapon_csw_p228")     cs_set_user_bpammo(id, CSW_P228, 0)     cs_set_weapon_ammo(CSW_P228, 2)     client_print(id, print_chat, "You got a P228 with 2 bullets! (1/10 Chance)")     }     else if(rnd >15 && rnd <= 30)     {         give_item(id, "weapon_csw_shield")     client_print(id, print_chat, "You got a Shield! (1/6 Chance)")     }     else if(rnd >30 && rnd <= 60)     {         give_item(id, "weapon_csw_hegrenade")     client_print(id, print_chat, "You got a HE Grenade! (1/3 Chance)")     }     else(rnd >60)     {         give_item(id, "weapon_p228")     cs_set_user_bpammo(id, CSW_P228, 0)     cs_set_weapon_ammo(CSW_P228, 2)     client_print(id, print_chat, "You got a P228 with 2 bullets! (1/10 Chance)")     } }

teame06 04-26-2007 14:35

Re: Setting weapon ammo...
 
No.

Not player index. Each weapon a player has a specific entity index.

Usage for engine you would do
Code:
new WeapEntIndex = find_ent_by_owner(-1, "weapon_awp", player[i], 0); if(is_ent_valid(WeapEntIndex)) {     cs_set_weapon_ammo(WeapEntIndex, 3); }

bwgrubbs1 04-26-2007 14:48

Re: Setting weapon ammo...
 
just a bit of a problem

Code:
    new players[32], num         new i         get_players(players, num)           new rnd     rnd = random_num(0,100)         if( rnd <= 100)         {             give_item(id, "weapon_awp")         new WeapEntIndex = find_ent_by_owner(-1, "weapon_awp", players[i], 0);         if(is_ent_valid(WeapEntIndex))         {             cs_set_weapon_ammo(WeapEntIndex, 3);         }             client_print(players[i], print_chat, "You got an awp with 3 bullets! (1/20 Chance)")         i++         }

/home/groups/amxmodx/tmp3/phpKRstlI.sma(599) : error 017: undefined symbol "is_ent_valid"

teame06 04-26-2007 15:11

Re: Setting weapon ammo...
 
change that to is_valid_ent

bwgrubbs1 04-26-2007 15:11

Re: Setting weapon ammo...
 
OK I have this and it works...some of the time...

Code:
    new players[32], num         new i         get_players(players, num)           new rnd     rnd = random_num(0,100)         if( rnd <= 100)         {             give_item(id, "weapon_awp")         new WeapEntIndex = find_ent_by_owner(-1, "weapon_awp", players[i], 0);         cs_set_weapon_ammo(WeapEntIndex, 3);             client_print(players[i], print_chat, "You got an awp with 3 bullets! (1/20 Chance)")         i++         }     else if(rnd > 5 && rnd <= 15)     {             give_item(id, "weapon_p228")         new WeapEntIndex = find_ent_by_owner(-1, "weapon_p228", players[i], 0);         cs_set_weapon_ammo(WeapEntIndex, 2);         client_print(id, print_chat, "You got a P228 with 2 bullets! (1/10 Chance)")         i++     }     else if(rnd > 15 && rnd <= 30)     {         give_item(id, "item_shield")         client_print(id, print_chat, "You got a Shield! (1/6 Chance)")     }     else if(rnd >30 && rnd <= 60)     {             give_item(id, "weapon_hegrenade")         client_print(id, print_chat, "You got a HE Grenade! (1/3 Chance)")     }     else if(rnd > 60 && rnd <= 100)     {         give_item(id, "weapon_p228")         client_print(id, print_chat, "...")     } }

teame06 04-26-2007 15:19

Re: Setting weapon ammo...
 
It possible you need to delay the setting weapon clip ammo because of the player hasn't gotten the weapon yet.

bwgrubbs1 04-26-2007 15:25

Re: Setting weapon ammo...
 
OK i changed it to this...and it wont change the bullets...still gives 10

Code:
    new players[32], num         new i         get_players(players, num)           new rnd     rnd = random_num(0,100)         if( rnd <= 100)         {             give_item(id, "weapon_awp")         new WeapEntIndex = find_ent_by_owner(-1, "weapon_awp", players[i], 0);                     if(is_valid_ent(WeapEntIndex))             {             cs_set_weapon_ammo(WeapEntIndex, 3);                 client_print(players[i], print_chat, "You got an awp with 3 bullets! (1/20 Chance)")             i++             }     }     else if(rnd > 5 && rnd <= 15)     {             give_item(id, "weapon_p228")         new WeapEntIndex = find_ent_by_owner(-1, "weapon_p228", players[i], 0);                 if(is_valid_ent(WeapEntIndex))             {             cs_set_weapon_ammo(WeapEntIndex, 2);             client_print(id, print_chat, "You got a P228 with 2 bullets! (1/10 Chance)")             i++             }     }     else if(rnd > 15 && rnd <= 30)     {         give_item(id, "item_shield")         client_print(id, print_chat, "You got a Shield! (1/6 Chance)")     }     else if(rnd >30 && rnd <= 60)     {             give_item(id, "weapon_hegrenade")         client_print(id, print_chat, "You got a HE Grenade! (1/3 Chance)")     }     else if(rnd > 60 && rnd <= 100)     {         give_item(id, "weapon_p228")         client_print(id, print_chat, "...")     }

bwgrubbs1 04-26-2007 15:26

Re: Setting weapon ammo...
 
ok...i see what you mean, so just insert a wait...or some sort of pause


All times are GMT -4. The time now is 06:38.

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