AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Code Snippets/Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=83)
-   -   ham_give_weapon and ham_strip_weapon (https://forums.alliedmods.net/showthread.php?t=56377)

XxAvalanchexX 06-12-2007 18:50

ham_give_weapon and ham_strip_weapon
 
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

stupok 06-12-2007 22:38

Re: ham_give_weapon and ham_strip_weapon
 
I think some mods don't have weapons with "weapon_" as the first 7 characters. Other than that, those look like some sweet functions.

Rolnaaba 06-12-2007 22:54

Re: ham_give_weapon and ham_strip_weapon
 
now your just bragging Ava ;)

XxAvalanchexX 06-12-2007 23:11

Re: ham_give_weapon and ham_strip_weapon
 
Quote:

Originally Posted by Rolnaaba (Post 488963)
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.

kmal2t 06-13-2007 02:04

Re: ham_give_weapon and ham_strip_weapon
 
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

XxAvalanchexX 06-13-2007 03:03

Re: ham_give_weapon and ham_strip_weapon
 
Sorry, but this thread is not about getting a weapon. It's actually for a new way to give and remove weapons from players.

kmal2t 06-13-2007 04:36

Re: ham_give_weapon and ham_strip_weapon
 
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.

Rolnaaba 06-13-2007 11:05

Re: ham_give_weapon and ham_strip_weapon
 
there is always room for scolding :P

VEN 08-08-2007 15:40

Re: ham_give_weapon and ham_strip_weapon
 
Note that bpammo needs to be reset for nades/c4.

Alka 08-10-2007 04:45

Re: ham_give_weapon and ham_strip_weapon
 
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");
}



All times are GMT -4. The time now is 11:53.

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