Aller au contenu

Photo

[SOLVED] Script Help - Walking into fire does damage


7 réponses à ce sujet

#1
DaSkee

DaSkee
  • Members
  • 19 messages
I have some fire in the level in the mod that I'm working on and I would like to make it so that walking into the fire causes damage and a fire effect.

I'm guessing I should set up a trigger around the fire and then put a script on that trigger. However, I can't figure out for the life of me how to do this script. I've been trying to add the "EffectDamage" effect to a triggered event, but its not working. Can anyone help with this?

Modifié par DaSkee, 17 mars 2010 - 02:02 .


#2
TimelordDC

TimelordDC
  • Members
  • 923 messages
This should do the required fire damage.

#include "log_h"
#include "utility_h"
#include "wrappers_h" 
#include "events_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    int nEventHandled = FALSE; 

    switch(nEventType)
    {
        case EVENT_TYPE_ENTER:
        {
            object oCreature = GetEventCreator(ev);
            DamageCreature(oCreature, <object doing the damage>, <damage value in float>, DAMAGE_TYPE_FIRE);

            break;
        }
    
    }                                         
    if (!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_TRIGGER_CORE);
    }
}


#3
DaSkee

DaSkee
  • Members
  • 19 messages
Thank you!

#4
DaSkee

DaSkee
  • Members
  • 19 messages
Hrm. It's not working as expected.

I did some changes. It compiles fine, however, when I walk into the fire it does so much instant damage that I die immediately. I added a "commandwait" but that doesn't seem to be working. Is that command borked?

#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);  
    float fDmg = 5.f;
    float fDelay = 5.f;
    command cWait = CommandWait(fDelay);
    int nEventHandled = FALSE;

    switch(nEventType)
    {
        case EVENT_TYPE_ENTER:
        {
            object oCreature = GetEventCreator(ev);
            object oTrigger = OBJECT_SELF; 
            int nCheck = IsInTrigger(oCreature, oTrigger);

                while
                    (nCheck == TRUE)
                        {cWait;
                        DamageCreature(oCreature,
                        oTrigger,
                        fDmg,
                        DAMAGE_TYPE_FIRE);} 
            break;
        }

    }
    if (!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_TRIGGER_CORE);
    }
}

Thanks again for that first bit of help, it really helped get the ball rolling.

Modifié par DaSkee, 06 mars 2010 - 10:04 .


#5
TimelordDC

TimelordDC
  • Members
  • 923 messages
I don't know what 5.f will do but you could try changing it to 5.0f.



Also, if you haven't gone through chargen and have the default template loaded (note - not the same as doing Quick Play), you will have only 1 hp. Check if that is the case too.



Another note - you don't need the IsInTrigger check since the event is triggered only when the player enters the Trigger.

#6
DaSkee

DaSkee
  • Members
  • 19 messages
I added the IsInTrigger because I want it to continually happen whenever the player is in the trigger so if they stand in the trigger they'll continually receive fire damage. I couldn't figure out how to set up a loop that will continually check that with just the event_type_trigger.



The 5.f for the float compiles fine, and works in the fDmg float so I'm not convinced this is the problem. Changing it to 5.0f didn't have any discernible affect. I also have a chargen script, so the character that I'm using has health, armor, and weapons.



Basically whats happening is that the while loops way too quickly, so the player takes a bunch of little bits of damage (I know this 'cause of all the 4's that appear over their head), but so quickly that they die instantly. I added the wait command hoping that that will cause the while to only loop once every 5 seconds, but even though it compiles it has absolutely no effect on what happens in the game.



My current guess that that that command just doesn't work, but I could be typing it in wrong or putting it in the wrong place. I've tried it at the beginning and at the end of the loop as well, but neither way works.



I'm totally at a loss at what to do here.

#7
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
command wait doesn't do what you think it does. Commands are actions you assign to creatures using AddCommand. By looping, you're applying the damage to the creature over and over again. Scripts always executre instantly and fully, there is no way to delay the actions within them, other than using a delayed event which I'll go into later. Also, even if command wait did effect the script, checking nCheck like that within the loop would be pointless becuase you're not updating it's value each cycle.

If you want to do damage over time, there's two ways. One is to apply a damage over time effect to the creature. This is quite easy to do, but will keep doing damage even if the creature leaves the trigger. You could use the exit event of the trigger to remove all damage over time effects on the creature that were created by the trigger. The damage over time event would eventualy expire though, even if the creature didn't leave the trigger, but you could give it a very long life.

The other way would be to use a delayed event which calls itself, creating a heartbeat. In the spawn event, do something like this (I'm going from memory, the paramater order or naming might be off):

DelayEvent(1.0, OBJECT_SELF, Event(EVENT_TYPE_CUSTOM_EVENT_1));

Then create an case for that event type, and in it call that same line of code. Grab all the creatures within a certain radius, check if they are in the trigger, and apply the damage. If you only care about party members, then loop through those instead. The only drawback to this method would be if you have a lot of these triggers in an area, it might start to cause slowdown.

If you've got access to the main campaign (single player) resources, there's a trigger in the night version of redcliffe that you could look at as an example. I think it's named arl101tr_fire_trap or something similar.

Modifié par DavidSims, 07 mars 2010 - 06:43 .


#8
DaSkee

DaSkee
  • Members
  • 19 messages
Sorry it took so long to respond, I was out of town all last week. Your suggestion was EXTREMELY helpful, thank you! Here is what I ended up going with-
#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    int nEventHandled = FALSE;

    switch(nEventType)
    {
        case EVENT_TYPE_ENTER:
        {
            object oCreature = GetEventCreator(ev);
            object oTrigger = OBJECT_SELF;
            ApplyEffectDamageOverTime(oCreature, oTrigger, ABILITY_SPELL_FLAME_BLAST, 150.f, 30.f, DAMAGE_TYPE_FIRE);

            break;
        }

        case EVENT_TYPE_EXIT:
        {
            object oCreature = GetEventCreator(ev);
            RemoveFireBasedEffects(oCreature);
        }


    }
    if (!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_TRIGGER_CORE);
    }
}