Raised This Month: $ Target: $400
 0% 

Runtime 10 on cs_set_weapon_ammo (0.20 RC5)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-18-2004 , 10:48   Runtime 10 on cs_set_weapon_ammo (0.20 RC5)
Reply With Quote #1

I cannot for the life of me figure out why this is getting a runtime error....

cs_set_weapon_ammo(id, 5)

I did a server print also to make sure the "id" was correct and it came back as "1" which is my ID since I'm the only one in the server (my test server).

I tried changing the ammo ammount, at first I was using another function to return the max ammo but then I just changed it to 5 and its still doing it.

Also I tried
cs_set_user_bpammo(id, wpnid, 5)

but that apparently doesn't do anything..... no error no nothing....

Im confused...
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
BAILOPAN
Join Date: Jan 2004
Old 09-18-2004 , 11:31  
Reply With Quote #2

cs_set_weapon_ammo() does not take a player entity, it takes a weapon entity
__________________
egg
BAILOPAN is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-18-2004 , 11:56  
Reply With Quote #3

might want to note that in the include

it just says "index" like every other command in there, I assumed that meant player index.

So.... best way to do that then is to find out the entity ID of the weapon the player is holding then use that?
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-18-2004 , 21:36  
Reply With Quote #4

uhhh.... do weapons in players hand even have entity ids?

I tried using this function on a weapon on the ground and it doesn't runtime, but I can't really tell its doing anything.

Is it possible to find the entity ID of a weapon a player is holding (I don't think it even has one.... :/)

So.... what exactly would be the purpose of this function?
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
BAILOPAN
Join Date: Jan 2004
Old 09-18-2004 , 21:40  
Reply With Quote #5

You can get the entity of a weapon id on a player by getting the name of the weapon and searching for it by classname. if the entity_get_edict of the EV_ENT_owner is the player, then you have a match
__________________
egg
BAILOPAN is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-18-2004 , 22:14  
Reply With Quote #6

THANKS BAILOPAN

that was just the little hint I needed. I figured it out and its mostly working.... cept I'm setting the clip full of the max ammo you can carry with the gun (looks funny having 90 ammo in the clip). I think I just want to set it to the max clip ammo for each gun. Anyway.... I'll post code when I'm done so other people can borrow it.
------------------
Here is a sample plugins to see how it all works out.
I included and extra stock I had that is related, some people might have a use for it for other things.

This plugin basically would give everyone on the server unlimited ammo for every gun (not grenades)

Code:
#include <amxmodx> #include <engine> #include <cstrike> //---------------------------------------------------------------------------------------------- public plugin_init() {     register_event("CurWeapon","changeWeapon","be","1=1") } //---------------------------------------------------------------------------------------------- public changeWeapon(id) {     new iWPNidx = -1     new clip, ammo, wpn[32]     new wpnid = get_user_weapon(id, clip, ammo)     if ( wpnid == CSW_C4 || wpnid == CSW_HEGRENADE || wpnid == CSW_SMOKEGRENADE || wpnid == CSW_FLASHBANG || wpnid == CSW_KNIFE ) return     // Never Run Out of Ammo!     if ( clip == 0 ) {         get_weaponname(wpnid,wpn,31)         while ((iWPNidx = find_ent_by_class(iWPNidx, wpn)) != 0){             if (id == entity_get_edict(iWPNidx, EV_ENT_owner)) {                 cs_set_weapon_ammo(iWPNidx, getMaxClipAmmo(wpnid))                 break             }         }     } } //---------------------------------------------------------------------------------------------- stock getMaxBPAmmo(wpnid) {     new bpammo = 0     switch (wpnid) {         case CSW_P228           : bpammo = 52         case CSW_SCOUT          : bpammo = 90         case CSW_HEGRENADE      : bpammo = 1         case CSW_XM1014     : bpammo = 32         case CSW_MAC10          : bpammo = 100         case CSW_AUG            : bpammo = 90         case CSW_SMOKEGRENADE   : bpammo = 1           case CSW_ELITE          : bpammo = 120         case CSW_FIVESEVEN      : bpammo = 100         case CSW_UMP45          : bpammo = 100         case CSW_SG550          : bpammo = 90           case CSW_GALIL          : bpammo = 90           case CSW_FAMAS          : bpammo = 90           case CSW_USP            : bpammo = 100         case CSW_GLOCK18        : bpammo = 120         case CSW_AWP            : bpammo = 30           case CSW_MP5NAVY        : bpammo = 120         case CSW_M249           : bpammo = 200         case CSW_M3         : bpammo = 21           case CSW_M4A1           : bpammo = 90           case CSW_TMP            : bpammo = 120         case CSW_G3SG1          : bpammo = 90           case CSW_FLASHBANG      : bpammo = 2           case CSW_DEAGLE     : bpammo = 35           case CSW_SG552          : bpammo = 90           case CSW_AK47           : bpammo = 90           case CSW_P90            : bpammo = 100     }                                   return bpammo                 }                                     //---------------------------------------------------------------------------------------------- stock getMaxClipAmmo(wpnid) {                                                   new clipammo = 0                     switch (wpnid) {                         case CSW_P228           : clipammo = 13         case CSW_SCOUT          : clipammo = 10         case CSW_HEGRENADE      : clipammo = 0         case CSW_XM1014     : clipammo = 7         case CSW_MAC10          : clipammo = 30         case CSW_AUG            : clipammo = 30         case CSW_SMOKEGRENADE   : clipammo = 0         case CSW_ELITE          : clipammo = 15         case CSW_FIVESEVEN      : clipammo = 20         case CSW_UMP45          : clipammo = 25         case CSW_SG550          : clipammo = 30         case CSW_GALIL          : clipammo = 35         case CSW_FAMAS          : clipammo = 25         case CSW_USP            : clipammo = 12         case CSW_GLOCK18        : clipammo = 20         case CSW_AWP            : clipammo = 10         case CSW_MP5NAVY        : clipammo = 30         case CSW_M249           : clipammo = 100         case CSW_M3         : clipammo = 8         case CSW_M4A1           : clipammo = 30         case CSW_TMP            : clipammo = 30         case CSW_G3SG1          : clipammo = 20         case CSW_FLASHBANG      : clipammo = 0         case CSW_DEAGLE     : clipammo = 7         case CSW_SG552          : clipammo = 30         case CSW_AK47           : clipammo = 30         case CSW_P90            : clipammo = 50     }     return clipammo } //----------------------------------------------------------------------------------------------
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Mugwump
Senior Member
Join Date: May 2004
Old 09-19-2004 , 00:19  
Reply With Quote #7

jtp, this is something I'd love to incorporate into a plugin I am working on, but the code here doesn't work for me (using the TP4 version of amxx 0.20)...

I added variable dump comments to every step of the changeWeapon routine and everything looks right, the ids are all correct and it gets to the point where the weapon I have _should_ be getting its clip set, but it doesnt. I even hardcoded in the number 12 for the USP I was testing with instead of using the clip lookup routine and it didnt change anything, the cs_set_weapon_ammo() just doesn't do anything for me.

What amxx platform have you tested this on? If 0.20 did you test with TP4 ? If its a matter of just installing the latest nightly build I have no problem doing that, was hoping to wait until the final release of 0.20 ...

Thanks!
-Mug
Mugwump is offline
Freecode
Never Fall Asleep
Join Date: Jan 2004
Old 09-22-2004 , 19:50  
Reply With Quote #8

FIX:
add this line
Code:
format(wpnn,31,"weapon_%s",wpnn);

after
Code:
get_weaponname(wpnid,wpn,31)
Freecode is offline
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 09-22-2004 , 20:33  
Reply With Quote #9

Quote:
Originally Posted by Mugwump
jtp, this is something I'd love to incorporate into a plugin I am working on, but the code here doesn't work for me (using the TP4 version of amxx 0.20)...

I added variable dump comments to every step of the changeWeapon routine and everything looks right, the ids are all correct and it gets to the point where the weapon I have _should_ be getting its clip set, but it doesnt. I even hardcoded in the number 12 for the USP I was testing with instead of using the clip lookup routine and it didnt change anything, the cs_set_weapon_ammo() just doesn't do anything for me.

What amxx platform have you tested this on? If 0.20 did you test with TP4 ? If its a matter of just installing the latest nightly build I have no problem doing that, was hoping to wait until the final release of 0.20 ...

Thanks!
-Mug
I belive I did this on RC5, the exact code I posted I compiled as a plugin and tried it, it worked perfectly.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
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 17:16.


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