Raised This Month: $ Target: $400
 0% 

Setting weapon ammo


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Lure.d
BANNED
Join Date: Dec 2009
Location: Lithuania->USA
Old 02-05-2010 , 14:46   Setting weapon ammo
Reply With Quote #1

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
Lure.d is offline
Send a message via Skype™ to Lure.d
master4life
Senior Member
Join Date: Mar 2006
Location: Germany
Old 02-05-2010 , 14:49   Re: Setting weapon ammo
Reply With Quote #2

Insert "engine" module.

PHP Code:
#include <engine>

[...]

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


[img]http://img714.**************/img714/8612/33726.png[/img]
master4life is offline
Send a message via ICQ to master4life Send a message via MSN to master4life Send a message via Skype™ to master4life
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-05-2010 , 14:50   Re: Setting weapon ammo
Reply With Quote #3

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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Lure.d
BANNED
Join Date: Dec 2009
Location: Lithuania->USA
Old 02-05-2010 , 14:55   Re: Setting weapon ammo
Reply With Quote #4

@ 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!

Last edited by Lure.d; 02-05-2010 at 14:59.
Lure.d is offline
Send a message via Skype™ to Lure.d
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 02-05-2010 , 15:42   Re: Setting weapon ammo
Reply With Quote #5

Quote:
Originally Posted by Lure.d View Post
@ 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.

Last edited by Seta00; 02-05-2010 at 17:50.
Seta00 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 02-05-2010 , 17:01   Re: Setting weapon ammo
Reply With Quote #6

master4life's code uses 1 more native, and i'm not sure it's safe.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod 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 07:26.


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