Author Topic: Modifying damage to specific shotgun fires  (Read 685 times)

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Modifying damage to specific shotgun fires
« on: January 27, 2016, 11:06:02 PM »
Hi guys,

Working on a skill that when you fire weapon, damage is modified by 1.5, but then any other shots for the next 10 seconds, are normal damage.  Then cycle repeats.

Here's what i've been using, which works perfectly for everything except the shotgun.  I'm assuming it's not working due to the shotgun firing 8 slugs, and the way that it calculates the total damage?

Code: [Select]
public OnW3TakeDmgAllPre(victim,attacker,Float:damage)
{
if(ValidPlayer(victim, true) && ValidPlayer(attacker) && attacker!=victim)
{
if(GetClientTeam(victim)!=GetClientTeam(attacker))
{
if(War3_GetRace(attacker)==thisRaceID)
{
new SkillLevel = War3_GetSkillLevel(attacker,thisRaceID,SKILL_DAMAGE);
if(SkillLevel>0)
{
if(War3_SkillNotInCooldown(attacker,thisRaceID,SKILL_DAMAGE,true))
{
War3_DamageModPercent(1.5);
War3_CooldownMGR(attacker,10.0,thisRaceID,SKILL_DAMAGE, _, _);
}
}
}
}
}
}


What's the best way that i can modify the damage of a single 'fire event' for the shotgun?

Cheers :)

Revan

  • Hero Member
  • *****
  • Posts: 513
    • View Profile
Re: Modifying damage to specific shotgun fires
« Reply #1 on: January 28, 2016, 01:49:39 AM »
Intresting question, one way this should be possible is by hooking the weapon_fire event(as the name suggests, that event is invoked whenever a weapon is fired.. duh) and remember that this shot is going to have a 1.5 damage multipler. Like this:
1. player fires gun, weapon_fire event is invoked
2. weapon_fire event handler sets some global to remember current state(when player fired and if damage is modified)
3. when w3 damage event fires(if it fires after weapon_fire, which it should) check if we need to double damage
4. repeat! The next time the player fires his gun the code in weapon_fire will detect that his last shot was not 10 seconds ago and deny the damage modifier(or allow if it actually was >= 10 seconds ago)

some semi-pseudoish code:
Code: [Select]
bool g_bDamageMultipler[MAXPLAYERSCUSTOM]; //remember if we need to apply damage multipler
int g_iLastTimeFired[MAXPLAYERSCUSTOM]; //holds war3 delay tracker "object"

public void OnPluginStart() {
   HookEvent("weapon_fire", OnWeaponFire);
   for(int i=0; i<MAXPLAYERSCUSTOM; ++i)
      g_iLastTimeFired[i] = War3_RegisterDelayTracker();
}

// do this in OnRaceChange/OnRaceSelected too
public void OnClientPutInServer(int client) {
  g_bDamageMultipler[client] = false;
  g_iLastTimeFired[client] = 0;
}
public void OnRaceSelected(int client, int old,int new) {
  if(old == thisRaceID)
     OnClientPutInServer(client);
 // or something like that
}

public void OnWeaponFire(Event ev, const char[] name, bool dontBroadcast) {
   int client = GetClientOfUserId(ev.GetInt("userid"));
   // ready for damage modifier?
   if(g_bDamageMultipler[client] && War3_TrackDelayExpired(g_iLastTimeFired[client]) {
      // cooldown expired, set modifier
      g_bDamageMultipler[client] = true;
      // reset delay tracker
      War3_TrackDelay(g_iLastTimeFired[client], 10.0);
   } else {
     // not ready
     g_bDamageMultipler[client] = false;
   }
}

OnW3TakeDamageThing(client,victim) {
  if(g_bDamageMultipler[client]) {
    //do stuff
  }
}

but take care if you hook weapon_fire I think it had some problems when using the knife(event firing pretty often) so just check if !War3_IsMeleeWeapon and you should be good to go  :)

I'm not actually sure if this is the best way, maybe someone else has a better idea.
« Last Edit: January 28, 2016, 01:54:03 AM by Revan »
#war3source on gamesurge

abgar

  • Full Member
  • ***
  • Posts: 114
    • View Profile
Re: Modifying damage to specific shotgun fires
« Reply #2 on: January 29, 2016, 12:18:52 AM »
Beautiful Revan - thanks :)

You were right - all i had to do was set the CD and a global bool on the weapon fire, due to the shotgun firing the player hurt 8 times.

Thanks as always mate :)