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 .