AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Runtime 10 on cs_set_weapon_ammo (0.20 RC5) (https://forums.alliedmods.net/showthread.php?t=5973)

jtp10181 09-18-2004 10:48

Runtime 10 on cs_set_weapon_ammo (0.20 RC5)
 
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...

BAILOPAN 09-18-2004 11:31

cs_set_weapon_ammo() does not take a player entity, it takes a weapon entity

jtp10181 09-18-2004 11:56

might want to note that in the include :P

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 09-18-2004 21:36

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?

BAILOPAN 09-18-2004 21:40

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 :)

jtp10181 09-18-2004 22:14

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 } //----------------------------------------------------------------------------------------------

Mugwump 09-19-2004 00:19

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

Freecode 09-22-2004 19:50

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

after
Code:
get_weaponname(wpnid,wpn,31)

jtp10181 09-22-2004 20:33

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.


All times are GMT -4. The time now is 17:16.

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