AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Regarding several Ham Functions (https://forums.alliedmods.net/showthread.php?t=299438)

Depresie 07-14-2017 13:16

Regarding several Ham Functions
 
Ham_RemovePlayerItem

- Isn't this hookable ?
- If it is hooked shouldn't it be triggered when a player drops or gets stripped of a weapon ?

Ham_Item_Drop

- Isn't this hookable ?
- If it is hooked shouldn't it be triggered when a player drops a weapon ?

Ham_Weapon_RetireWeapon

- Shouldn't this be triggered when player is switching or dropping weapons ?

gabuch2 07-14-2017 13:39

Re: Regarding several Ham Functions
 
All Ham functions are hookable, but it doesn't mean it's safe to supercede them.

Ham_RemovePlayerItem happens when you strip an item from the player.

Ham_Item_Drop when you drop a weapon (unsure)

Ham_Weapon_RetireWeapon, in Half-Life you will automatically change to a "better weapon", determined by weight, after you ran out of ammo of certain weapons(throwables) thus calling this method.

Depresie 07-14-2017 14:25

Re: Regarding several Ham Functions
 
Ham_RemovePlayerItem
- Hooked, seems to be never called, even after calling it with ExecuteHamB

Ham_Item_Drop
- Hooked, seems to be never called

Ham_Weapon_RetireWeapon
- Hooked, seems to be called only when using it with ExecuteHamB

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
//register_clcmd("say weapon", "cmdweapons")

    
register_clcmd("say 1""CommandGetWeapon")
    
register_clcmd("say 2""CommandWeaponStrip")

    
RegisterHam(Ham_Weapon_RetireWeapon"weapon_ak47""fw_HamWeaponRetire_Post"1)
    
RegisterHam(Ham_Item_Drop"weapon_ak47""fw_HamItemDrop_Post"1)
    
RegisterHam(Ham_RemovePlayerItem"weapon_ak47""fw_HamRemovePlayerItem_Post"1)

}

public 
CommandGetWeapon(iPlayer)
{
    
give_item(iPlayer"weapon_ak47")
}


public 
CommandWeaponStrip(iPlayer)
{
    new 
iWeaponID CSW_AK47

    
new iWeapon cs_get_user_weapon_entity(iPlayer)

    
ExecuteHamB(Ham_Weapon_RetireWeaponiWeapon)

    
ExecuteHamB(Ham_RemovePlayerItemiPlayeriWeapon)


    
ExecuteHamB(Ham_Item_KilliWeapon)
    
set_pev(iPlayerpev_weaponspev(iPlayerpev_weapons) & ~ (1<<iWeaponID))
}

public 
fw_HamWeaponRetire_Post(iWeapon)
{
    
client_print(0print_chat"RETIRE WEAPON")
}

public 
fw_HamItemDrop_Post(iWeapon)
{
    
client_print(0print_chat"DROP WEAPON")
}

public 
fw_HamRemovePlayerItem_Post(iWeapon)
{
    
client_print(0print_chat"REMOVE WEAPON")



klippy 07-14-2017 15:24

Re: Regarding several Ham Functions
 
Ham_RemovePlayerItem is called on "player" entities when a client sends "drop" or when the game (in many different cases it looks like) forces a player to drop an item, like when a player dies.

Ham_Item_Drop is called only in a few cases it looks like and it actually destroys the weapon entity. There is CBasePlayerItem:Kill which does the same. I don't really get the logic behind this function, but it shouldn't be used to hook when a weapon is dropped.

Ham_Weapon_RetireWeapon is called when a weapon should be holstered and the next best weapon should be deployed. That happens for example when you throw a flashbang or run out of ammo.


All times are GMT -4. The time now is 22:45.

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