Raised This Month: $ Target: $400
 0% 

ClipInfo - Infinite ammo - XxAvalanchexX saved the day


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
stupok
Veteran Member
Join Date: Feb 2006
Old 10-30-2006 , 00:08   ClipInfo - Infinite ammo - XxAvalanchexX saved the day
Reply With Quote #1

(For The Specialists)

I tried logging ClipInfo (Message 101) with the message logger and it didn't log anything.

So, I went to my own methods, and did this:
Code:
register_event("ClipInfo", "clip_info", "b") public clip_info() {     new id = read_data(0)     new clip = read_data(1)         client_print(0, print_chat, "ClipInfo, 0:%i 1:%i", id, clip)     message_begin(MSG_ONE, 101, {0,0,0}, id)     write_byte(id)     write_byte(clip)     message_end() }
The event only sends two args, and the first is id and second is amount of ammo remaining in the gun. However, the server crashes with something like: "Fatal error, User msg ClipInfo sent 2 bytes, expecting 1".

I imagine I can't do infinite ammo this way, or I am doing something wrong. Please point out any errors or give some suggestions as to what I can do to make a nice infinite ammo plugin.

I really don't like the method implemented by Seather here, he just forces the client to drop the weapon and gives the client the same weapon again, so it's not fluid at all and it requires running a relatively lengthy function every 0.5 seconds.

ClipInfo is the only event that I found that changes when the ammo goes down. WeaponInfo is called on reload, though.

Last edited by stupok; 11-05-2006 at 15:51.
stupok is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 10-30-2006 , 00:34   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #2

You don't need to send the id as a byte, it's included as the message header. Only send the ammo amount. But all this will do is update the client's HUD, it won't actually change their amount of ammo.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 10-30-2006 , 00:45   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #3

__________________
stupok is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 10-30-2006 , 10:03   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #4

PHP Code:
register_event("ClipInfo""clip_info""b")
public 
clip_info()
{
    new 
id read_data(0)
    
give_item(idAMMO_NAME)

wouldnt work?
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 10-30-2006 , 12:52   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #5

Not for clip ammo. You need to use Mod Specific natives. Like for cs you would use cs_set_weapon_ammo and you have to find the Weapon Entity Index for the player you want to set the ammo too. Since ammo clip is on the Weapon Entity Index Private Data.

Here a small script I did for Counter-Strike though.

Code:
#include <amxmodx> #include <engine> #include <fakemeta> #include <cstrike> #define SLOT_PRIMARY    1 #define SLOT_SECONDARY  2 #define SLOT_KNIFE      3 #define SLOT_GRENADE    4 #define SLOT_C4         5 // Weapon CSW_* new PrimarySlot[33]; new PrimaryWeapIndex[33]; new SecondarySlot[33]; new SecondaryWeapIndex[33]; //---------------------------------------------------------------------------------------------- #define sh_getMaxBPAmmo(%1) _sh_getMaxBPAmmo[%1] stock _sh_getMaxBPAmmo[] = {     0,     52, //CSW_P228     0,     90, //CSW_SCOUT     1//CSW_HEGRENADE     32, //CSW_XM1014     1//CSW_C4     100,//CSW_MAC10     90, //CSW_AUG     1//CSW_SMOKEGRENADE     120,//CSW_ELITE     100,//CSW_FIVESEVEN     100,//CSW_UMP45     90, //CSW_SG550     90, //CSW_GALIL     90, //CSW_FAMAS     100,//CSW_USP     120,//CSW_GLOCK18     30, //CSW_AWP     120,//CSW_MP5NAVY     200,//CSW_M249     32, //CSW_M3     90, //CSW_M4A1     120,//CSW_TMP     90, //CSW_G3SG1     2//CSW_FLASHBANG     35, //CSW_DEAGLE     90, //CSW_SG552     90, //CSW_AK47     0//CSW_KNIFE     100 //CSW_P90 } #define sh_getMaxClipAmmo(%1)   _sh_getMaxClipAmmo[%1] stock _sh_getMaxClipAmmo[] = {     0,     13, //CSW_P228     0,     10, //CSW_SCOUT     0//CSW_HEGRENADE     7//CSW_XM1014     0//CSW_C4     30,//CSW_MAC10     30, //CSW_AUG     0//CSW_SMOKEGRENADE     15,//CSW_ELITE     20,//CSW_FIVESEVEN     25,//CSW_UMP45     30, //CSW_SG550     35, //CSW_GALIL     25, //CSW_FAMAS     12,//CSW_USP     20,//CSW_GLOCK18     10, //CSW_AWP     30,//CSW_MP5NAVY     100,//CSW_M249     8//CSW_M3     30, //CSW_M4A1     30,//CSW_TMP     20, //CSW_G3SG1     0//CSW_FLASHBANG     7//CSW_DEAGLE     30, //CSW_SG552     30, //CSW_AK47     0//CSW_KNIFE     50//CSW_P90 } stock g_WeaponSlots[] = {     0,     2//CSW_P228     0,     1//CSW_SCOUT     4//CSW_HEGRENADE     1//CSW_XM1014     5//CSW_C4     1//CSW_MAC10     1//CSW_AUG     4//CSW_SMOKEGRENADE     2//CSW_ELITE     2//CSW_FIVESEVEN     1//CSW_UMP45     1//CSW_SG550     1//CSW_GALIL     1//CSW_FAMAS     2//CSW_USP     2//CSW_GLOCK18     1//CSW_AWP     1//CSW_MP5NAVY     1//CSW_M249     1//CSW_M3     1//CSW_M4A1     1//CSW_TMP     1//CSW_G3SG1     4//CSW_FLASHBANG     2//CSW_DEAGLE     1//CSW_SG552     1//CSW_AK47     3//CSW_KNIFE     1   //CSW_P90 }; stock g_WeapNames[31][] = {     "",     "weapon_p228",//CSW_P228     "",     "weapon_scout", //CSW_SCOUT     "",     //CSW_HEGRENADE     "weapon_xm1014",    //CSW_XM1014     "",     //CSW_C4     "weapon_mac10", //CSW_MAC10     "weapon_aug",   //CSW_AUG     "",     //CSW_SMOKEGRENADE     "weapon_elite",//CSW_ELITE     "weapon_fiveseven",//CSW_FIVESEVEN     "weapon_ump45", //CSW_UMP45     "weapon_sg550", //CSW_SG550     "weapon_galil", //CSW_GALIL     "weapon_famas", //CSW_FAMAS     "weapon_usp",//CSW_USP     "weapon_glock18",//CSW_GLOCK18     "weapon_awp",   //CSW_AWP     "weapon_mp5navy",   //CSW_MP5NAVY     "weapon_m249"//CSW_M249     "weapon_m3",    //CSW_M3     "weapon_m4a1"//CSW_M4A1     "weapon_tmp",   //CSW_TMP     "weapon_g3sg1", //CSW_G3SG1     "",     //CSW_FLASHBANG     "weapon_deagle",//CSW_DEAGLE     "weapon_sg552", //CSW_SG552     "weapon_ak47"//CSW_AK47     "",     //CSW_KNIFE     "weapon_p90"    //CSW_P90 } public plugin_init() {     register_event("CurWeapon", "hook_CurWeapon", "be", "1=1") } public hook_CurWeapon(id) {     new wp = read_data(2);     // Check if weapon is different from the stored slot when ammo is 2.     // Weapon should reload when the ammo clip is 1.     if(read_data(3) >  3)         return;     new Slot = g_WeaponSlots[wp];     if(Slot == SLOT_PRIMARY || Slot == SLOT_SECONDARY)     {         if(PrimarySlot[id] != wp || SecondarySlot[id] != wp)         {             new index;             switch(Slot)             {                 case SLOT_PRIMARY:                 {                     index = find_weapon_index_by_name(id, g_WeapNames[wp])                     if(index)                     {                         PrimarySlot[id] = wp;                         PrimaryWeapIndex[id] = index;                     }                 }                 case SLOT_SECONDARY:                 {                     index = find_weapon_index_by_name(id, g_WeapNames[wp]) // Find Weapon Index                     if(index)                     {                         SecondarySlot[id] = wp;                         SecondaryWeapIndex[id] = index;                     }                 }             }         } else {             cs_set_weapon_ammo((Slot == SLOT_PRIMARY) ? PrimaryWeapIndex[id] : SecondaryWeapIndex[id], _sh_getMaxClipAmmo[wp]) // Reload Clip Ammo         }     } } // Using Find entity in sphere might be better here.. stock find_weapon_index_by_name(id, const WeaponName[]) {     new Index = -1     while ((Index = engfunc(EngFunc_FindEntityByString, Index, "classname", WeaponName)) != 0)     {         if(id == pev(Index, pev_owner))         {             return Index         }     }     return 0; }
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
stupok
Veteran Member
Join Date: Feb 2006
Old 10-30-2006 , 18:28   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #6

@teame06
Well, theres no native for TS for setting clip ammo, so I don't think your code really helps to make a plugin for TS. Also, correct me if I'm wrong, but I don't think CurWeapon is executed in TS. But it's nice to see how its done in CS.

I don't understand some of the code.

Code:
#define sh_getMaxBPAmmo(%1) _sh_getMaxBPAmmo[%1]

Whats up with that?

@XxAvalanchexX
I just changed the code to look like this:
Code:
register_event("ClipInfo", "clip_info", "b") public clip_info() {     new id = read_data(0)     new clip = read_data(1)     message_begin(MSG_ONE, 101, {0,0,0}, id)     write_byte(clip)     message_end() }
And it doesn't cause the amount of ammo I see in my clip to stay at a given value, it doesn't seem to do anything at all. It doesn't crash with fatal errors at least. Are you 100% sure this should only affect the number on the hud and not the amount of ammo a user has?

EDIT: I just realized the above code will read the value that the game sends and send the same message the game would normally send if the plugin didn't even exist. Doh.
I changed the write_byte(clip) to write_byte(id) and it set my ammo to my id number, but I did not have unlimited ammo, just didn't know how many bullets I had left... so you're right XxAvalanchexX.

How did you know about ClipInfo? I didn't find it in any documentation.

Last edited by stupok; 10-30-2006 at 18:46.
stupok is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 11-05-2006 , 00:53   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #7

I'd still like some answers to the questions above , but I also have another question.

Can I use set_entity_edict or int, or some other method to change a weapon entity's clip ammo value? I don't think I can, but if theres some way to do that besides writing a module myself, I didn't find it.

I might get desperate and learn write my own ts module to make ts_set_weapon_ammo() an actual native. Any good documentation I should read before I get started on that?
stupok is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 11-05-2006 , 03:18   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #8

Let me clear this up a bit.
First of all you should understand that the message doesn't change the actual ammo value, it just updates the HUD or whatever on the client side.
Second: you do not need to write a module, you just have to find where the value exactly is stored and then alter it with existing modules fakemeta/engine/memhack etc.

The ammo value may be stored in the entity pdata, or even in the pev structure. I've heard from Greenberet that he wrote the pdata scanner, but i think he never released it, maybe he wanted to keep it private or still planning to release it later - don't know.

The worst thing that can be, is that the ammo value is stored in the memory block that can't be accessed through standard methods, then the only way would be the memory hacking.

Last edited by VEN; 11-05-2006 at 03:29.
VEN is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 11-05-2006 , 03:37   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #9

Let me know if these work for you. This is a clean up of my old modify weapon ammo function, and a brand new modify weapon clip function. The offset values are for Windows 32-bit servers. I don't know the offsets for 64-bit servers, and I'm not 100% sure that my +4 for Linux servers is accurate.

EDIT: file moved to http://forums.alliedmods.net/showthread.php?p=400113
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 11-05-2006 at 16:33.
XxAvalanchexX is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 11-05-2006 , 13:32   Re: ClipInfo - Infinite ammo - I think it can't be done...
Reply With Quote #10

@VEN
I already knew that it changed only HUD, but thanks for the extra info


XxAvalanchexX, I don't know where you got the information to make that...

Just to clarify: Is ava_ts.inc called a module? or do you just call that an include file? Does a module necessarily use a .dll?


But anyway, to the testing. (I run Windows 32-bit)
The ts_set_weapon_clip does the same thing as sending a ClipInfo message with whatever integer you want for the clip. It doesn't actually modify the gun's clip, just the HUD display.

The ts_set_weapon_ammo works beautifully, with no problem. I call the function on WeaponInfo and the backpack ammo is set just fine.
stupok 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 04:50.


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