Raised This Month: $32 Target: $400
 8% 

ham_give_weapon and ham_strip_weapon


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-12-2007 , 18:50   ham_give_weapon and ham_strip_weapon
Reply With Quote #1

Code:
// gives a player a weapon efficiently stock ham_give_weapon(id,weapon[]) {     if(!equal(weapon,"weapon_",7)) return 0;     new wEnt = engfunc(EngFunc_CreateNamedEntity,engfunc(EngFunc_AllocString,weapon));     if(!pev_valid(wEnt)) return 0;     set_pev(wEnt,pev_spawnflags,SF_NORESPAWN);     dllfunc(DLLFunc_Spawn,wEnt);         if(!ExecuteHamB(Ham_AddPlayerItem,id,wEnt))     {         if(pev_valid(wEnt)) set_pev(wEnt,pev_flags,pev(wEnt,pev_flags) | FL_KILLME);         return 0;     }     ExecuteHamB(Ham_Item_AttachToPlayer,wEnt,id)     return 1; }   // takes a weapon from a player efficiently stock ham_strip_weapon(id,weapon[]) {     if(!equal(weapon,"weapon_",7)) return 0;     new wId = get_weaponid(weapon);     if(!wId) return 0;     new wEnt;     while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}     if(!wEnt) return 0;     if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);     if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;     ExecuteHamB(Ham_Item_Kill,wEnt);     set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));     // this block should be used for Counter-Strike:     /*if(wId == CSW_C4)     {         cs_set_user_plant(id,0,0);         cs_set_user_bpammo(id,CSW_C4,0);     }     else if(wId == CSW_SMOKEGRENADE || wId == CSW_FLASHBANG || wId == CSW_HEGRENADE)         cs_set_user_bpammo(id,wId,0);*/     return 1; }

There is an alternative function to strip a user's weapon by ConnorMcLeod posted here:
http://forums.alliedmods.net/showpos...7&postcount=42

The differences between my function and his are explained by him here:
http://forums.alliedmods.net/showpos...1&postcount=44
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS

Last edited by XxAvalanchexX; 06-21-2011 at 20:10.
XxAvalanchexX is offline
stupok
Veteran Member
Join Date: Feb 2006
Old 06-12-2007 , 22:38   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #2

I think some mods don't have weapons with "weapon_" as the first 7 characters. Other than that, those look like some sweet functions.
stupok is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 06-12-2007 , 22:54   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #3

now your just bragging Ava ;)
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-12-2007 , 23:11   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #4

Quote:
Originally Posted by Rolnaaba View Post
now your just bragging Ava ;)
I was looking to share this as a resource and also get scolded by VEN about what I am doing wrong.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
kmal2t
BANNED
Join Date: Apr 2006
Old 06-13-2007 , 02:04   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #5

Personally I've found the best universal way to get a weapon for any mod is with this: http://forums.alliedmods.net/showthr...ght=amx_msglog

It's not as great as giving the actual name and all and you have to use something like this:
new ammo, clip, weapon = get_user_weapon(id,clip,ammo);
if( (weapon == 20) , but it's still effective
kmal2t is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-13-2007 , 03:03   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #6

Sorry, but this thread is not about getting a weapon. It's actually for a new way to give and remove weapons from players.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
kmal2t
BANNED
Join Date: Apr 2006
Old 06-13-2007 , 04:36   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #7

I was referring to stupok's comment that not all mods preceed their weapons with weapon_, wpn_, or CSW_ which is important for having a universal way of getting/checking the weapon before giving/stripping.
kmal2t is offline
Rolnaaba
Veteran Member
Join Date: May 2006
Old 06-13-2007 , 11:05   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #8

there is always room for scolding
__________________
DO NOT PM me about avp mod.
Rolnaaba is offline
VEN
Veteran Member
Join Date: Jan 2005
Old 08-08-2007 , 15:40   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #9

Note that bpammo needs to be reset for nades/c4.
VEN is offline
Old 08-10-2007, 04:16
Doc-Holiday
This message has been deleted by Doc-Holiday. Reason: got my awnser
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-10-2007 , 04:45   Re: ham_give_weapon and ham_strip_weapon
Reply With Quote #10

Must have fakemeta and hamsandwich! And this is a stock! All you need tot do is to copy ham_give_weapon() or ham_strip_weapon() once in you'r plugin and use it:

Code:
ham_give_weapon(id, "weapon_ak47");
 
if(user_has_weapon(id, CSW_M4A1))
{
    ham_strip_weapon(id, "weapon_m4a1");
}
Alka 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 10:53.


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