Author Topic: Default.nss - details?  (Read 797 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Default.nss - details?
« on: March 06, 2012, 01:15:04 pm »


               Can someone confirm this?

Basically, when you open a bic file of a character up in leto, you can see that the 'default' script is applied to all the events on the creature screen.

Default, as I was aware, is the script that is run every heartbeat.

However, I started thinking - could it also be used for other events, and what it actually needs, is a case statement inside it?

eg


void main()
{

   switch(iEventNumber)
      {
            case HEARTBEAT:
             //Heartbeat code here
              break;
            case ONDAMAGED:
             //On damaged code here?
              break;

      }


}



Can anyone confirm if this works?
I am at work, and cant get near nwn to try it.

Im ideally looking for a way of capturing the 'damaged' event on players.
The use of subraces, armor, and different weapon types, makes it impossible to handle it via item related onHit event.
I need to try and capture it on the players instead.
If creatures have these events, surely players do too?
               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Default.nss - details?
« Reply #1 on: March 06, 2012, 01:48:00 pm »


               Default is exectued for all character events. You will need some code to determine from which event was it executed (here's how it's done in PRC: http://pastebin.com/b9BwnPYf). This allows for some very cool things, but I can't say it's 100% reliable.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Default.nss - details?
« Reply #2 on: March 06, 2012, 02:04:27 pm »


               You should be careful about this. My thinking (when I learned about this) is that it is useful for clones of PCs (which are created with no AI), but you don't want it to do much on any other creature because it could eat up processing cycles.

My default has a single check for a local int called "CLONE", and if "CLONE" is FALSE nothing else executes in Default.
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Default.nss - details?
« Reply #3 on: March 06, 2012, 09:08:45 pm »


               there are certain issues with default script namely it does run for traps created by scripting function. Since you are NWNX user I suggest you to set uniques scrript for each event and then you will know what does fire and whats not. I use this approach with heartbeat only and it works fine, but I would be interested if you would make a research which other events works.
               
               

               
            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Default.nss - details?
« Reply #4 on: March 09, 2012, 01:50:29 pm »


               

Alex Warren wrote...

Default is exectued for all character events. You will need some code to determine from which event was it executed (here's how it's done in PRC: http://pastebin.com/b9BwnPYf). This allows for some very cool things, but I can't say it's 100% reliable.


Actually, Default.nss is not fired for all events.
What your script is doing, is still firing every 6-7 seconds, on the regular heartbeat interval, but capturing the 'GetLastDamager' etc and stuff, to determine whether a new damage occured since the last heartbeat.
It then collates all damages together, stores them on the player, and repeats next time.

All in all, it still fires once every 6-7 seconds, and not on an actual damage event.
All it is doing, is detecting whether a new damage has occured in the last 6-7 seconds, and if so, do actions xyz.

When I tested it out, I set the script to heal me for all negative damage I receive.


The effect was sporadic, and not equal to the amount of damage received.




eg-
Player 1  (Me)
Player 2 (You)

Player 2 - hits me for 30 negative damage
Player 2 hits me for 45 negative damage
Default nss fires - detects that the last damage done to me was 45 negative
Heals me for 45 negative

but the 30 negative damage slips through undetected, because the function 'GetLastDamagebyType only gets 'the last' damage.




               
               

               
            

Legacy_Alex Warren

  • Sr. Member
  • ****
  • Posts: 326
  • Karma: +0/-0
Default.nss - details?
« Reply #5 on: March 11, 2012, 05:19:23 pm »


               I stand corrected - you're right.

I tested that a bit - made a script that displayed current game time - it was executed every 6 - 8 seconds (for some extreme cases it was 2 - 12 secons). Equip/unequip/damage/rest didn't triggered the script. Than I used NWNX to replace character's heart beat script and default was not executed any more.

Sorry for confusion. I should read that script more carefully.
               
               

               
            

Legacy_virusman

  • Sr. Member
  • ****
  • Posts: 448
  • Karma: +0/-0
Default.nss - details?
« Reply #6 on: March 12, 2012, 03:45:42 pm »


               As far as I know, default.nss is called on heartbeat, death and conversation events.