Post by Gaspatcho on Aug 29, 2022 14:11:26 GMT
Let's say you have 2 weapons, silver & golden m4a1, if a player buys both he will have both and it will cause a damage increase.
If your golden m4a1 does x3 and silver m4a1 does x3 buying both will allow the player to do x9 damage.
Now you don't want that so you'd look but don't find solutions but here's one:
In each of silver/gold m4a1s there is always a variable/bool that shows if the player has the weapon,
Your best way to find it is to go to the Ham_TakeDamage function directly
As shown above, g_HasM4A1 is the bool that defines if the player has the weapon or not.
Now you will need to add 2 natives, 1 to check if the player has it or not and one that can remove it.
Create 2 functions:
Now register your natives, create plugin_natives() and list your natives.
Now you will do exactly the same for the golden m4
Now that you have all natives ready you will start using the natives.
For Silver M4a1:
Add your golden m4 natives above plugin_init as if you are adding variables:
Edit your Ham_TakeDamage function:
before your SetHamParamFloat add this
so it will be
That's all, if your player has both m4a1s and shots a bullet the other weapon gets removed. that's all if you only have 2 weapons of the same type.
If you have 3 or more the rest need a check too, for example, golden m4 check would be:
If your golden m4a1 does x3 and silver m4a1 does x3 buying both will allow the player to do x9 damage.
Now you don't want that so you'd look but don't find solutions but here's one:
In each of silver/gold m4a1s there is always a variable/bool that shows if the player has the weapon,
Your best way to find it is to go to the Ham_TakeDamage function directly
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
As above the function is the third param, fw_TakeDamage.
Go to fw_TakeDamage and see it's struct
[code]public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CSW_M4A1 && g_HasM4A1[attacker] )
{
SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
}
}
As shown above, g_HasM4A1 is the bool that defines if the player has the weapon or not.
Now you will need to add 2 natives, 1 to check if the player has it or not and one that can remove it.
Create 2 functions:
public nat_has_silver_m4(id)
{
if(g_HasM4A1[id])
return true
else return false
}
public nat_remove_silver_m4(id)
g_HasM4A1[id] = false
Now register your natives, create plugin_natives() and list your natives.
public pluugin_natives()
{
register_native("zp_has_silver_m4", "nat_has_silver_m4", 1)
register_native("zp_remove_silver_m4", "nat_remove_silver_m4", 1)
}
Now you will do exactly the same for the golden m4
public pluugin_natives()
{
register_native("zp_has_gold_m4", "nat_has_gold_m4", 1)
register_native("zp_remove_gold_m4", "nat_remove_gold_m4", 1)
}
public nat_has_gold_m4(id)
{
if(g_HasM4[id])
return true
else return false
}
public nat_remove_gold_m4(id)
g_HasM4[id] = false
Now that you have all natives ready you will start using the natives.
For Silver M4a1:
Add your golden m4 natives above plugin_init as if you are adding variables:
native zp_has_gold_m4(id)
native zp_remove_gold_m4(id)
Edit your Ham_TakeDamage function:
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CSW_M4A1 && g_HasM4A1[attacker] )
{
SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
}
}
before your SetHamParamFloat add this
if(zp_has_gold_m4(attacker))
zp_remove_gold_m4(attacker)
so it will be
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CSW_M4A1 && g_HasM4A1[attacker] )
{
if(zp_has_gold_m4(attacker))
zp_remove_gold_m4(attacker)
SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
}
}
That's all, if your player has both m4a1s and shots a bullet the other weapon gets removed. that's all if you only have 2 weapons of the same type.
If you have 3 or more the rest need a check too, for example, golden m4 check would be:
native zp_has_silver_m4(id)
native zp_remove_silver_m4(id)
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if ( is_valid_player( attacker ) && get_user_weapon(attacker) == CSW_M4A1 && g_HasM4[attacker] )
{
if(zp_has_silver_m4(attacker))
zp_remove_silver_m4(attacker)
SetHamParamFloat(4, damage * get_pcvar_float( cvar_dmgmultiplier ) )
}
}