Aller au contenu

Photo

Run Script on event


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

#1
freche

freche
  • Members
  • 292 messages
I'm quite new to the toolset and modding.
What i would like to do is to run a small script on each character (prefered npcs + party) everytime they enter and leave combat.
I have looked around in various files, the toolset and the wiki but I guess I'm too new to all this :)
The closest I found was http://social.biowar.../Event_override , but as I understand it, it will override the Event and all other things that are affected by the event is then not run ?

or is it just so easy that I follow the Event_override on the wiki and just have to add the:
HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE);

without the if handler at the end of the script to run both my script and any core script that might run at the event?

#2
Phaenan

Phaenan
  • Members
  • 315 messages
The M2DA override part on that wiki page would definitely work, as long as you include the part sending the event to the relevant core handler. Although, depending on what you want to change in the way the event is handled you may want to send the event to the core before doing your own modifications. :o
As in something like that :
case EVENT_TYPE_COMBAT_END: {
       HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE);
       // Your stuff
       break;
}

Modifié par Phaenan, 18 février 2010 - 01:40 .


#3
freche

freche
  • Members
  • 292 messages
Thanks, however it seems like I'm running into trouble when trying to use EVENT_COMBAT_INITIATED

For testing this is the script I run atm, I have added the script to both inventory
added and combat initiated in engineevents.gda. When I try it out in
game I get a message Inventory everytime I loot something, but I never
get Combat START when I enter combat.

#include "utility_h"
#include "wrappers_h"
#include "events_h"
void main()
{
    event ev   = GetCurrentEvent();
    int nEvent = GetEventType(ev);
    object oOwner = GetEventCreator(ev);
    object oPC = GetHero();

    switch (nEvent)
    {
        case EVENT_TYPE_COMBAT_INITIATED:
        {
            HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE);
            DisplayFloatyMessage(oPC,"Combat START", FLOATY_MESSAGE, 14654488, 5.0);
            break;
        }

        case EVENT_TYPE_INVENTORY_ADDED:
        {  
            HandleEvent(ev, RESOURCE_SCRIPT_CREATURE_CORE);
            object oItem = GetEventObject(ev, 0);
            if (IsPartyMember(oOwner))
            {
                DisplayFloatyMessage(oPC, "Inventory", FLOATY_MESSAGE, 14654488, 10.0);
            }
            break;
        }

    }
}

#4
Nattfodd

Nattfodd
  • Members
  • 321 messages
Where do you placed this code? In a script associated with the creature that you are attacking?

#5
freche

freche
  • Members
  • 292 messages
I edited the events.2da to:
ID    Label                                                               Visualizer           Script
int    string                                                               comment           string
  6   EVENT_TYPE_INVENTORY_ADDED                                           override_script
30   EVENT_TYPE_COMBAT_INITIATED                                            override_script

and converted it to gda and placed the engineevents.gda into the override folder
Then I made the script above with the name override_script and placed it in the \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\override\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\toolsetexport folder

As I understood from the wiki the script doesn't need to be associated to a creature since it will run everytime the event is called.
And as I said this works for the EVENt_TYPE_INVENTORY_ADDED, I get a floating text above my main character that say Inventory (as it should be) but when I enter combat I don't get any text message.

So is it to assume that EVENT_TYPE_COMBAT_INITIATED is not triggered when someone is entering combat ?

Modifié par freche, 18 février 2010 - 11:09 .


#6
Nattfodd

Nattfodd
  • Members
  • 321 messages

freche wrote...
So is it to assume that EVENT_TYPE_COMBAT_INITIATED is not triggered when someone is entering combat ?


Probably. The wiki says "Fires whenever the attack command is added into the command queue", that i don't know what does it means specifically.
Have you tried with the event "EVENT_TYPE_ATTACKED"?

#7
Magic

Magic
  • Members
  • 187 messages
I've never seen EVENT_TYPE_COMBAT_INITIATED being fired, and it's not handled in any core creature script, combat related script, or ai script, so ... I think the most important for you will be EVENT_TYPE_PERCEPTION_APPEAR. There the creature goes into combat AND sets the perception of its allies as well. Maybe that's already all you need for entering combat.

Edit: Forgot, rules_core.nss.

Modifié par Magic, 18 février 2010 - 05:58 .


#8
freche

freche
  • Members
  • 292 messages
I have tried a bit with EVENT_TYPE_GAMEMODE_CHANGE however when I try to run a override with a script then send it to the core script combat never start (hostile mobs don't attack when aproached).



Will take a look on the perception event.

#9
Magic

Magic
  • Members
  • 187 messages
I didn't understand what you wanted to do with the EVENT_TYPE_GAMEMODE_CHANGE but manipulating the game mode directly is somewhat tricky. It definately is not tied to NPCs entering combat but only related to the party. Perhaps I didn't get what you want to achieve in the first place, though. Do you want to run a script on several creatures as soon as combat starts for anyone? Or, as I assumed, do you want a creature-by-creature check for entering combat?

#10
freche

freche
  • Members
  • 292 messages
Yes you assumed correct, it's just that I'm so new to the toolset so it's a lot of trial and error, searching on the wiki and going through files to get a better understanding about how things work for me atm. Havn't been able to try out EVENT_TYPE_PERCEPTION_APPEAR yet but will do.

#11
Nattfodd

Nattfodd
  • Members
  • 321 messages
Keep in mind that EVENT_TYPE_PERCEPTION_APPEAR, fires for all creatures, not only for hostile creatures. So if you want to know if a combat is started you must add a test if Perceiver is hostile to Perceived.

I think the EVENT_TYPE_ATTACKED should accomplish your task, but i haven't used it yet.