Raised This Month: $ Target: $400
 0% 

Weapon Pickup / Set AK47 & M4A1 to 50 bullets clip.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hebusletroll
Senior Member
Join Date: Apr 2006
Old 04-17-2006 , 15:15   Weapon Pickup / Set AK47 & M4A1 to 50 bullets clip.
Reply With Quote #1

Dear friends

Actually, i have any trouble to define 50 bullets per clip (when weapon picked up).

My problem is that when i set the ammo count, this is not for the current picked up weapon, but the previous used weapon.

My code :

Code:
public plugin_init() 
{
                register_plugin("PowerWeapons", "1.0", "Hebusletroll")
                register_event("WeapPickup","weapon_pickup","be")
}

public weapon_pickup(id)
{
	new clip,ammo
	new weapon = get_user_weapon(id,clip,ammo)
	cs_set_weapon_ammo(get_weaponid(id,weapon),50)
}

public get_weaponid(pid,wid)
{
	new wpn[32],weapon_index = -1 
	get_weaponname(wid,wpn,31) 
	while ((weapon_index = find_ent_by_class(weapon_index, wpn)) != 0)
		{
		if (pid == entity_get_edict(weapon_index, EV_ENT_owner))
			{
			return weapon_index
		}
	}
	return -1
}


My plugins (PowerWeapons), add (not replace !), many new weapons like :

Silver Kalachnikov,
Colt Carabine M4M203,
Magnum 44,
Molotov cocktail,
Canister,
Poisonned grenade,
Sawed off,
Rocket launcher,
Minigun.

All without DLL servers side supplement (like WTF, etc). and no client modification.

And more features.

Actually i'm blocked with this 50 bullets features.
hebusletroll is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 04-18-2006 , 11:45  
Reply With Quote #2

Up,

I have tried another solution, but not working, always previous selected weapon will set ammo to 50

hihi
hebusletroll is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 04-18-2006 , 12:09  
Reply With Quote #3

Code:
public weapon_pickup(id,weapon) {    cs_set_weapon_ammo(get_weaponid(id,weapon),50) }

(or use read_data(1) to get the weapon)
__________________
plop
p3tsin is offline
nordy
Senior Member
Join Date: Apr 2006
Location: Latvia
Old 04-18-2006 , 12:47  
Reply With Quote #4

good idea just finish this well
nordy is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 04-19-2006 , 15:04  
Reply With Quote #5

Quote:
I have tried another solution, but not working, always previous selected weapon will set ammo to 50
Because when that event is called player still not have that weapon.

You should note that this method is exploitable.
It's possible to reload weapon and gain 20 extra ammo (50-30) then drop and collect weapon again and repeat given steeps.

Take a look on the code below, it does not have such exploit.
Code:
#include <amxmodx> #include <engine> #include <cstrike> // should be greater than corresponding standard #define CLIP_AMMO 50 public plugin_init() {     register_event("WeapPickup", "event_weapon_pickup", "be") } public event_weapon_pickup(id) {     // get id of collected weapon     new wid = read_data(1)     if (wid == CSW_AK47 || wid == CSW_M4A1) { // if ak47 or m4a1         new param[1]         param[0] = wid         // wait a bit since weapon entity not created yet         set_task(0.1, "task_set_ammo", id, param, 1)     } } public task_set_ammo(param[1], id) {     new wid = param[0], wname[20]     // weapon name is the same as weapon entity classname     get_weaponname(wid, wname, 19)     // find weapon entity index by it's classname and owner     new went = find_ent_by_owner(-1, wname, id)     if (!went) // if weapon entity isn't found         return     // get amount of ammo in clip of collected weapon     new clip = cs_get_weapon_ammo(went)     if (clip >= CLIP_AMMO) // if ammo addition isn't required         return     // get amount of player's pack ammo for collected weapon     new pack = cs_get_user_bpammo(id, wid)     if (!pack) // if player have no ammo for that weapon         return     // total available amount of ammo for collected weapon     new total = clip + pack     // here will be stored result ammo amount for clip and pack     new clip2, pack2     // if total ammo greater than or equal to defined clip ammo     if (total >= CLIP_AMMO) {         clip2 = CLIP_AMMO         pack2 = total - CLIP_AMMO     }     else {         clip2 = total         pack2 = 0     }     // set new clip and pack ammo amount for collected weapon     cs_set_weapon_ammo(went, clip2)     cs_set_user_bpammo(id, wid, pack2) }

But you also should note that this method will not redefine clip capacity.
It only will set 50 ammo for collected weapon's clip and nothing more.

To complete that you need to figure out when weapon is reloaded and perfor similar steeps.
VEN 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 05:02.


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