Aller au contenu

Photo

throwing this out there as well


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

#1
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
this code makes a projectile go from waypoint1 to waypoint2. now the problem is that i want the player to get hurt when he walks inbetween the waypoints and gets hit by the fireball. with the code below no damage is dealt to the player.

void main() {
object oWaypoint1 = GetObjectByTag("waypoint1");
object oWaypoint2 = GetObjectByTag("waypoint2");
vector vProjectile1 = GetPosition(oWaypoint1);
vector vProjectile2 = GetPosition(oWaypoint2);
object oHero = GetHero();
 

FireProjectile(2, vProjectile1, vProjectile2, 0, FALSE, oHero);
}

Modifié par gordonbrown82, 03 février 2010 - 12:54 .


#2
Craig Graff

Craig Graff
  • Members
  • 608 messages

gordonbrown82 wrote...

this code makes a projectile go from waypoint1 to waypoint2. now the problem is that i want the player to get hurt when he walks inbetween the waypoints and gets hit by the fireball. with the code below no damage is dealt to the player.

void main() {
object oWaypoint1 = GetObjectByTag("waypoint1");
object oWaypoint2 = GetObjectByTag("waypoint2");
vector vProjectile1 = GetPosition(oWaypoint1);
vector vProjectile2 = GetPosition(oWaypoint2);
object oHero = GetHero();
 

FireProjectile(2, vProjectile1, vProjectile2, 0, FALSE, oHero);
}


You need to set an impact event and handle it with a script from an object, probably a placeable, but a creature would work as well. You also need to make sure that the projectile type you use has DynamicCollisions enabled in PRJ_base.xls,
[dascript]
void main()
{
    object oBolt;                    
    object oWaypoint1 = GetObjectByTag("waypoint1");
    object oWaypoint2 = GetObjectByTag("waypoint2");
    vector vProjectile1 = GetPosition(oWaypoint1);
    vector vProjectile2 = GetPosition(oWaypoint2);
    object oHero = GetHero();
    object oHandler = UT_GetNearestObjectByTag(oHero, "tag_of_handling_object");              
   
    event evImpact = Event(EVENT_TYPE_CUSTOM_EVENT_01);

    vProjectile1.z += 0.75; // Take this up to aproximately chest height
    vProjectile2.z += 0.75; // Take this up to aproximately chest height

    evImpact = SetEventFloat(evImpact, 0, 50.0);   // Optionally, send damage info (or target or caster or whatever)

    oBolt = FireProjectile(201, vProjectile1, vProjectile2, 0, FALSE, oHandler);

    SetProjectileImpactEvent(oBolt, evImpact);
}
[/dascript]

Then, in the script for the handling object, something like this:
[dascript]
void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    string sDebug;
    object oPC = GetHero();    

    switch(nEventType)
    {
        // Impact event for projectile
        case EVENT_TYPE_CUSTOM_EVENT_01:
        {                                                 
            float fDamage = GetEventFloat(ev, 0);
            object oCreator  = GetEventCreator(ev);     // the projectile object
            location lImpact = GetLocation(oCreator);

            // HACK: The area component of lImpact is always invalid.
            lImpact = SetLocationArea(lImpact, GetArea(oCreator));

            object[] arTarget;
            int i;
            for (i = 1; IsObjectValid(GetEventObject(ev, i)); i++)
            {
                arTarget[i-1] = GetEventObject(ev, i);
            }
            int nTargets = GetArraySize(arTarget);   
                                 
            // redundant in this case, but a useful setup if you want to handle different impacts differently
            for (i = 0; i < nTargets; i++)
            {
                if (IsFollower(arTarget[i]))
                {
                    DamageCreature(arTarget[i], OBJECT_SELF, fDamage, DAMAGE_TYPE_NATURE);
                }
            }
           
            break;
        }     
    }
}
[/dascript]

Modifié par Craig Graff, 03 février 2010 - 03:56 .


#3
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
thanks a bunch craig i'll try to implement this.

#4
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
when compiling the first script i get declarations does not match paramets for

oBolt = FireProjectile(201, vProjectile1, vProjectile2, 0, oHandler);




#5
Craig Graff

Craig Graff
  • Members
  • 608 messages
I left out a FALSE

oBolt = FireProjectile(201, vProjectile1, vProjectile2, 0, FALSE, oHandler);

#6
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
ok it all compiles properly but there's no damage made to the character when he gets hit by the bolt (i'm not sure if that was put in your script at all but i'm not sure how to know if it's working unless that's added. perhaps something is wrong with how i've put the scripts to use. the setup is as follows: Posted Image



the guy closest to the camera activates the projectile firing script when clicked on and the other guy with tag "grunt" has the eventhandling script. i put grunt here: object oHandler = UT_GetNearestObjectByTag(oHero, "grunt"); although i don't really get that part



sorry about all the questions no answer is ok i'm just curious how this works.

#7
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
ah this bit of code gives a declarations does not match parameters error:



// HACK: The area component of lImpact is always invalid.

lImpact = SetLocationArea(GetArea(oCreator));

#8
Craig Graff

Craig Graff
  • Members
  • 608 messages
Another bit I edited on the fly without the benefit of compiling.



lImpact = SetLocationArea(lImpact , GetArea(oCreator));





You could probably figure these errors out by looking at the function header info (just double click on the function name).

#9
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
he he yeah you're right i saw that one parameter was missing but i couldn't figure out what it was since i don't understand 40% of the code. i'm still not getting it to work though.

#10
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
oh wait you made a comment about that already..

Modifié par gordonbrown82, 03 février 2010 - 12:20 .


#11
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
crap

Modifié par gordonbrown82, 03 février 2010 - 12:55 .


#12
Craig Graff

Craig Graff
  • Members
  • 608 messages
You might also want to switch the 1.5 to 0.75, since that is what actual tested code in the game seems to use (and 1.5 meters is more like head height). (Edited above code.)

#13
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
0.75 didn't do anything either. the only impact events that recorded is when the bolt hits waypoint2, a floaty message appears then if i put it in the event handling code. i think i'm going to try to set off an area of effect spell that does damage or something using the impact i get from hitting waypoint2.

Modifié par gordonbrown82, 04 février 2010 - 04:00 .