Aller au contenu

Photo

Giving an item to a player after they select a specialization using event overrides


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Sakaslan

Sakaslan
  • Members
  • 18 messages
I need to give an item to a player once the player chooses a custom specialization I'm making.  I assume the best way to do this is to intercept an appropriate event, add the item, then pass the event on.  So far I've tried using EVENT_TYPE_CHARGEN_END (Since one of the event parameters distinguishes between the modes CHARGEN_MODE_CREATE and CHARGEN_MODE_LEVELUP, I assumed that this event was fired when the player closed the level-up GUI also) and EVENT_TYPE_ABILITY_ACQUIRED (assuming this was fired every time a character gained an ability).

With EVENT_TYPE_CHARGEN_END, I used:

case EVENT_TYPE_CHARGEN_END:
{
  int nMode = GetEventInteger(ev, 0);  // Mode will be either CHARGEN_MODE_CREATE or CHARGEN_MODE_LEVELUP
  object oChar = GetEventObject(ev, 0); // The character undergoing levelup
 
  UT_AddItemToInventory(R"item_name.uti", 1);

}

The full script is more complicated since I need a check to see if the character has the ability in question and to see if the item already exists (i.e., has been given in a previous instance of the event interception), but I'll fill that in later when I know I have the basic event interception working correctly.  It seems to me that this simple script should add "item_name.uti" to inventory every time EVENT_TYPE_CHARGEN_END fires.  This didn't work, so I then assumed that my original assumption about when EVENT_TYPE_CHARGEN_END fires was faulty.  A lot of assumptions, I know (and, yeah, I know what they say about assume).

So I moved on to EVENT_TYPE_ABILITY_ACQUIRED (which I now think would be a more elegant solution, if I could get it to work), using:

case EVENT_TYPE_ABILITY_ACQUIRED:
{
   int nAcquired = GetEventInteger(ev, 0); // 1: ability acquired -1: ability lost
   int nAbilityID = GetEventInteger(ev, 1);
   object oChar = GetEventObject(ev, 0);

  UT_AddItemToInventory(R"item_name.uti", 1);

}

Again, the final script will be more complex and include a check to see if the specific ability (the specialization's ABILITY_SPELL_HIDDEN_XXXXXX) was the one acquired, etc.  But I wanted something simple to test with, and thought that this script would add "item_name.uti" to inventory every time an ability was acquired.  But it doesn't.

In both cases, I added the appropriate line to my engineevents_mymod.xls/gda and pointed the Script String to my event handler script.  Also in both, the variable ev is defined before the switch command, I just didn't paste the entire thing to keep the post clutter-free.  The scripts compile fine, though.

I know there's EVENT_TYPE_PLAYERLEVELUP that fires every time the player requests to enter the level up screen, but don't know know of any event that fires when the player closes that screen, as I'd hoped CHARGEN_END did.

So two questions:

1. Is there a simpler way to solve the issue of giving the player an item when they select a specific specialization?
2. Assuming "no" is the answer to 1, am I clearly doing something wrong in these examples or do these events not fire when I'm thinking they should?  Is there some event that would be better suited to my purposes?

Modifié par Sakaslan, 17 septembre 2010 - 10:05 .


#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
There have been some problems reported previously with attempting to use engineevents.xls to override events. I am not sure if that applies to the specific ones you are attempting to override.



My suggestion would be to create a module script for your addin and in that, handle EVENT_TYPE_CHARGEN_END. If you use EVENT_TYPE_ABILITY_ACQUIRED, then you will have to make sure to destroy the item if the player deselects the ability (if nAcquired is -1 in the snippet you pasted)

Another suggestion would be to use PrintToLog statements to verify that your script is firing and doing the things you want. That helps a lot when debugging scripts.

#3
Sakaslan

Sakaslan
  • Members
  • 18 messages
Thanks, TL. I had hoped to be able to use an override so that I could use the event manager mod, since this addin modifies the single player game. Trying to keep possible conflicts down, etc. Just to be clear, if I handle EVENT_TYPE_CHARGEN_END and ultimately pass it through to its default handler with HandleEvent(ev) in a module script, my addin will still conflict with any other adding that overrides EVENT_TYPE_CHARGEN_END, correct?



I never used PrintToLog but I did just try to add some FloatyMessages in and got no response for those, so I don't think either of my attempts ever resulted in the script firing. But just in case, I'll go the PrintToLog route and see if the results differ.



When you're talking about EVENT_TYPE_ABILITY_ACQUIRED and making sure I destroy the item if the player deselcts the ability: I assumed that the actual event wasn't fired until the player was given the ability. What I mean is, if the player is inside the chargen UI and clicks on Ability X to select it, do you know if EVENT_TYPE_ABILITY_ACQUIRED fires then or only if the Ability remains selected once the player hits "Play" to exit the Chargen UI, finalize the choices made in the UI, and return to the game? I ask because I assumed that the return of -1 for nAcquired would be returned if the ability was removed from the player with something like RemoveAbility.

#4
TimelordDC

TimelordDC
  • Members
  • 923 messages
If the messages didn't appear with DisplayFloatyMessage, PrintToLog wouldn't return anything too.



Yep, it would override any other single player addin that overrides EVENT_TYPE_CHARGEN_END but that is based on module priority which you can coordinate with other module-makers (primarily companion mod-makers and a couple others)



EVENT_TYPE_ABILITY_ACQUIRED is fired immediately once the Ability is selected. nAcquired is -1 when the ability is deselected and it is used to restore the Ability points.


#5
Sakaslan

Sakaslan
  • Members
  • 18 messages
I've been just plugging in random events to see which triggers my PrintToLog/DisplayFloatyMessage statements.



I already had an override for EVENT_TYPE_EQUIP (which, naturally, worked the first time and so I was surprised when my attempt with EVENT_TYPE_CHARGEN_END was an abysmal failure). So far out of:



E_T_CHARGEN_END

E_T_ABILITY_ACQUIRED

E_T_COMBAT_INITIATED

E_T_MELEE_ATTACK_START

E_T_CHAR_RECORD_OPENED

E_T_UNEQUIP



only UNEQUIP seems to be firing the override script. I guess I will keep trying others to see if there's something I can successfully override and then use in conjunction with event manager in order to prevent conflicts. It will just kill the immersion somewhat if I have to tell the player "once you learn this, make sure you unequip a random item or [insert other event-related action] to get the full effect!"



If nothing realistic works out, I'll resort to overriding CHARGEN_END in the module event handler script.