AlliedModders

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

Lure.d 02-05-2010 14:46

Setting weapon ammo
 
Hi there, i need your help now.
Lets look at my menu's case 4(which give glock).
PHP Code:

case 4: { //menu option 5 -- glock with 10 ammo
     
give_item(id"weapon_glock18"); // gives the glock18 pistol to a player
     
cs_set_user_bpammo(idCSW_GLOCK180); // we set backpack ammo to 0
     
cs_set_weapon_ammo(id10);
     ...


Allright, the ... mean nothing to the code that sets the ammo.
So i've succesfully gave myself a nice glock18.
Also successfully set my back pack ammo to 0.
But when i try to set the weapons, hmm primary ammo?, it spits an error whilst in debug.
Look:
Code:

[AMXX]Run time error 10: native error (native "cs_set_weapon_ammo")
Did i use it wrong, please help me if you can since i don't know anything about the primary ammo :P

master4life 02-05-2010 14:49

Re: Setting weapon ammo
 
Insert "engine" module.

PHP Code:

#include <engine>

[...]

cs_set_weapon_ammo(id10); - > cs_set_weapon_ammofind_ent_by_owner( -1"weapon_glock18"id ), 10 ); 


ConnorMcLeod 02-05-2010 14:50

Re: Setting weapon ammo
 
You have to pass the weapon entity index, not the player index.

PHP Code:

case 4: { //menu option 5 -- glock with 10 ammo
     
new iWeapon give_item(id"weapon_glock18"); // gives the glock18 pistol to a player
     
if( iWeapon )
     {
         
cs_set_user_bpammo(idCSW_GLOCK180); // we set backpack ammo to 0
         
cs_set_weapon_ammo(iWeapon10);
     }
     ...


If the player already has a glock, give_item will fail.

Lure.d 02-05-2010 14:55

Re: Setting weapon ammo
 
@ master 4 life
Thanks! Since im sort of newbie(just bout month of coding and only 1 plugin of 1 approved),
i dont use engine and i certainly don't know anything about engine commands.
I prefer i shall learn it. Again thanks a lot :)
@ connor
Your way is better i guess in some cases, but i prefer master4life's way:
[+] Shorter code
[+] Simplier
[-] Extra module usage
And your code:
[+] Single-module usage(non cstrike + engine)
[-] Bit longer

Again THANKS EVERYONE!

Seta00 02-05-2010 15:42

Re: Setting weapon ammo
 
Quote:

Originally Posted by Lure.d (Post 1079572)
@ connor
Your way is better i guess in some cases, but i prefer master4life's way:
[+] Shorter code
[+] Simplier
[-] Extra module usage
And your code:
[+] Single-module usage(non cstrike + engine)
[-] Bit longer

Again THANKS EVERYONE!

Connor's code is simpler, safer and faster, you should use it.

ConnorMcLeod 02-05-2010 17:01

Re: Setting weapon ammo
 
master4life's code uses 1 more native, and i'm not sure it's safe.


All times are GMT -4. The time now is 07:26.

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