Author Topic: Lagy death script  (Read 1273 times)

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« on: August 21, 2011, 01:37:25 am »


               This is what 99 percent of my creatures use as a death script and it is laggy.




This is the first script that fires

Then the execute script fires the 2nd script listed on this page

I think the script fireing order is messed up.In the creatures scripts the first script listed here fires first.

Maybe the bottom script should fire first.

Also i dont see anything that kills this creature........ since it is a death script maybe thats where the lag is coming from.

Does a number need to be set for the random waypoints in the script cause its at 0











void main()
{
    object oDamager = GetLastDamager();
    if ((GetIsPC(oDamager)) && (GetIsPossessedFamiliar(oDamager) == FALSE))
    {
        CreateItemOnObject("",oDamager,1);
        if (GetTimeHour() == 0)
        {
            CreateItemOnObject("",oDamager,1);
        }
    }
  int    nWaypoint = 0;
  object oWaypoint = GetFirstObjectInArea();
  while( GetIsObjectValid( oWaypoint))
  { if( GetObjectType( oWaypoint) == OBJECT_TYPE_WAYPOINT)
    { if( GetTag( oWaypoint) == GetTag( OBJECT_SELF))
      { ++nWaypoint;
      }
    }
    oWaypoint = GetNextObjectInArea();
  }
  if( nWaypoint <= 0) return;
  nWaypoint = Random( nWaypoint) + 1;
  oWaypoint = GetFirstObjectInArea();
  while( GetIsObjectValid( oWaypoint))
  { if( GetObjectType( oWaypoint) == OBJECT_TYPE_WAYPOINT)
    { if( GetTag( oWaypoint) == GetTag( OBJECT_SELF))
      { if( (--nWaypoint) <= 0)
        { CreateObject( OBJECT_TYPE_CREATURE, GetResRef ( OBJECT_SELF), GetLocation( oWaypoint));
          return;
        }
      }
    }
    oWaypoint = GetNextObjectInArea();
    ExecuteScript("ondeatheffect",OBJECT_SELF);
  }
}














//ondeatheffect this is the 2nd script
#include "i420_s_inc_pstat"
void main()
{
  SetPCKillStats(GetLastKiller(), OBJECT_SELF);
  object oPC = GetLastKiller();
  effect eHeal = EffectHeal(1);
  effect eHaste = (EffectHaste());
  effect eStr = (EffectAbilityIncrease(ABILITY_STRENGTH, 1));
  effect eVis = (EffectVisualEffect(VFX_DUR_GLOW_RED));
      ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oPC);
      ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oPC);
      if (d100() > 50)ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHaste, oPC, 30.0);

}
               
               

               


                     Modifié par Builder_Anthony, 21 août 2011 - 12:45 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Lagy death script
« Reply #1 on: August 21, 2011, 02:51:32 am »


               The ExecuteScript portion should be executed on the killer, instead of the creature killed.  While cutting out the one unneeded check won't improve performance in any noticeable way, it would be more reliable.

 One thing you could do to increase performance, is after it does the waypoint count of that waypoint tag type the first time, you could write the count to the area as an int to be retrieved on the next OnDeath event for that tagged creature.  Then only the first death of each tagged creature per area needs the full object check.
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #2 on: August 21, 2011, 05:27:26 pm »


               I look at the execute script and it does seem to do it from the killer.

Eliminating any unused checks is my goal.

As for the last comment about the waypoints .......well im just lost there.

I cant really script so im kinda asking for help.
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Lagy death script
« Reply #3 on: August 21, 2011, 07:00:32 pm »


               No he means you are executing the script on object_self, should be on oDamager.  Also on the executed script you have the various effects defined but don't apply them all, like the strength one.  Maybe also get rid of the glow effect on the PC. Maybe looping through all the waypoints though is really causing some lag. also it seems you should move down the execute line to one more bracket, for it seems to me as is it is part of the while loop.  Anyhow good thing you posted this.
since I bet someone will be able to fix it up for you.  Btw you have a couple while loops in there for the wp's, not really sure that is needed.  You are using those waypoints to respawn monsters.
               
               

               
            

Legacy__Guile

  • Hero Member
  • *****
  • Posts: 1308
  • Karma: +0/-0
Lagy death script
« Reply #4 on: August 21, 2011, 10:13:00 pm »


               It would be a lot easier to just count the Number of Waypoints from the OnEnter event for the Area, setting the variable on the Area and retrieving it through scripting rather than doing it from the creatures OnDeath even, sersiously.

Loops are a major source of lag on many servers, especially when those loops are looking for something in an area, and even more so if there are a lot of object to cycle through as well.

Those are my recommendation...
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Lagy death script
« Reply #5 on: August 21, 2011, 10:42:49 pm »


               Tried to tweak it a bit combined the two scripts into one.


#include "i420_s_inc_pstat"
void BuffDamager(object oDamager)
{
  SetPCKillStats(oDamager, OBJECT_SELF);
  effect eHeal = EffectHeal(1);
  effect eHaste = (EffectHaste());
  effect eStr = (EffectAbilityIncrease(ABILITY_STRENGTH, 1));
  effect eVis = (EffectVisualEffect(VFX_DUR_GLOW_RED));'

      ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oDamager);
      ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oDamager);

      if (d100() > 50)ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eHaste, oDamager, 30.0);

}




void main()
{
    object oDamager = GetLastDamager();
    int    nWaypoint;
    object oWaypoint;

    if ((GetIsPC(oDamager)) && (GetIsPossessedFamiliar(oDamager) == FALSE))
    {
        CreateItemOnObject("",oDamager,1);      //need to add somethings resref here?
        if (GetTimeHour() == 0)
        {  //need to add somethings resref here?
            CreateItemOnObject("",oDamager,1);
        }
    }

  nWaypoint = 0;
  oWaypoint = GetFirstObjectInArea();

  while( GetIsObjectValid( oWaypoint))
  {
    if( GetObjectType( oWaypoint) == OBJECT_TYPE_WAYPOINT)
    {
        if( GetTag( oWaypoint) == GetTag( OBJECT_SELF))
        {
            ++nWaypoint;
        }
    }
    oWaypoint = GetNextObjectInArea();
  }

  /*if( nWaypoint <= 0)
  {
    nWaypoint = Random( nWaypoint) + 1;
  }

  while( GetIsObjectValid( oWaypoint))
  { if( GetObjectType( oWaypoint) == OBJECT_TYPE_WAYPOINT)
    { if( GetTag( oWaypoint) == GetTag( OBJECT_SELF))
      { if( (--nWaypoint) <= 0)
        { CreateObject( OBJECT_TYPE_CREATURE, GetResRef ( OBJECT_SELF), GetLocation( oWaypoint));
          return;
        }
      }
    }
    oWaypoint = GetNextObjectInArea();*/
    BuffDamager( oDamager );
  //}
}

               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #6 on: August 21, 2011, 10:47:23 pm »


               Well i could dicth the strength one but the red glow is a must because it lets the pc know hes just received haste.

I thought they get applied once he kills the monster.It seems to work that way but i did edit some things out of that script.

Gyulie i guess i could do it that way by counting the waypoints when a player enters the area and then retreivving it i guess i could add a execute script to all my areas.BUt again i cant really script good so i dont want to make a mess out of things.I guess if this gets sorted out i could try it that way.The less lag i get would be great.I never really liked that cycle threw waypoint thing anyways.
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #7 on: August 21, 2011, 10:48:46 pm »


               Ok well i tested it out and things seem to be working.I have to test a little more on checking if they are spawning.But the red glow and haste are there.
               
               

               


                     Modifié par Builder_Anthony, 21 août 2011 - 10:14 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Lagy death script
« Reply #8 on: August 22, 2011, 01:15:56 am »


               The point I was trying to make about strength is that you don't actually increase the strength of the killer, the oPC. You need to add a line like:
if (d100() > 50)ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eStr, oDamager, 30.0);
And I would make eHeal d4()  I played in your mod and healing is pretty tough, getting back 1 pt for killing a creature that just beat you to a pulp, well to make up for that I would cut the str duration and haste to like 10 seconds haste is way powerful.  More of a taste thing though. Of course you could always compare the difference in levels, HitDice between the PC and thing they killed and award them something for that.  In other words a high level PC would get no bonus for killing stuff more tha 2 levels below them.  Or you could adjust the duration of the effects accordingly.
Oh and one last thing regarding the red glow.  It's fine if that's what you want to indicate a blood-lust sort of thing, but regardless the PC will know since they are hasted or buffed and that will show up above by the PC 's in the buff/deteriment bar.
               
               

               


                     Modifié par ffbj, 22 août 2011 - 12:27 .
                     
                  


            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #9 on: August 22, 2011, 02:38:32 am »


               Ya i do see the bar but thats a great idea for checking the pcs level and offering aditional things.IM testing the script baragg posted so it might be a few days before i can tell anyhting.Plus i need to determine that missing tag in there i forgot what its doing.I think i might just erase it out of there as long as the creatures spawn to random waypoints.

Nice talking to everyone im still on here i never really post though.
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Lagy death script
« Reply #10 on: August 22, 2011, 12:43:34 pm »


               From this point on:

/*if( nWaypoint <= 0)

I commented most of the stuff there out. Cause if nWaypoint <= 0, it returns at that point and nothing else would happen.
               
               

               


                     Modifié par Baragg, 22 août 2011 - 11:43 .
                     
                  


            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #11 on: August 22, 2011, 05:25:13 pm »


               Ya see thats zero i think its wrong and needs to be set to something but im not sure what its does.Heres the thing i already have like 8 waypoints in my areas taged ZSA_WAYPOINT i figured this script was picking one of those waypoints.But from reading something wayback i think im soupposed to edit something in the script to the maximum number of waypoints in the area.So i guess it was searching thew them.Im not sure what the zero is for but thats what i thought it was for and im just so darn lost lol.I just want the monsters to spawn at one of those ZSA_WAYPOINT randomly.


I guess my point is the part where the pc receive stats is working fine from what i can tell.
Im just trying to determine if monsters are spawning at a random waypoint tagged ZSA_WAYPOINT
               
               

               


                     Modifié par Builder_Anthony, 22 août 2011 - 04:27 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Lagy death script
« Reply #12 on: August 23, 2011, 01:35:13 am »


               It looked to me as if the script looked for a waypoint with the same tag as the creature in order to spawn at, based on:
 if( GetTag( oWaypoint) == GetTag( OBJECT_SELF))

 Unless your monsters are also tagged ZSA_WAYPOINT they'll likely not respawn at a waypoint with that tag.  You'd need this instead:
if( GetTag( oWaypoint) == "ZSA_WAYPOINT")
               
               

               
            

Legacy_Builder_Anthony

  • Hero Member
  • *****
  • Posts: 786
  • Karma: +0/-0
Lagy death script
« Reply #13 on: August 23, 2011, 02:19:13 am »


               My monsters are tagged zsa_zombie that i want to use the respawn.

I figure the monsters i dont want to use the respawn are just tagged something else.

I did not make any changes to braggs script.I would like that in there if anyone can hook it up.
               
               

               


                     Modifié par Builder_Anthony, 23 août 2011 - 01:20 .
                     
                  


            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Lagy death script
« Reply #14 on: August 23, 2011, 02:46:10 am »


               You'd just need to insert something like this before the respawn checks:

if (GetTag (OBJECT_SELF) != "zsa_zombie") return;

If you want the buff effect to take place regardless of respawn, that could be moved above this check.