CATAPULT SCRIPT WITH MISS EFFECT AND OPERATOR
This is my version of making a catapult fire at a target waypoint. i based
it on a script i found in another post but i cant remember his name =(
It has a random generator creating a miss effect so that it does not fire at
the same spot all the time.. as a real catapult.
It also has a catapult operator who fires the catapult, if he is killed the
catapult does not fire anymore.
It has a random fire delay and fire chance so that you can create arrays of
say 4 catapults shooting seemingly random.
What you need:
1 catapult (make it usable)
1 target waypoint , the catapult can shoot at any range
1 NPC catapult operator
Tag the catapult with whatever you want. but you need to have the same tag
on the operator. tag the target with "catapult tag" + _t.
eg: catapult tag = CATAPULT1
catapult operator= CATAPULT1
catapult targetwaypoint = CATAPULT1_t
Make this script on the catapult operator NPC OnHeartBeat:
Code: void main()
{
int FIRECHANCE = 50; // Percentaget chance of catapult to fire each 6 seconds
if (d100() < FIRECHANCE)
{
float dly = IntToFloat( d6() ); // creates a random delay so many catapults
// does not fire at the same time
dly = dly/2;
DelayCommand(dly, ActionInteractObject(GetObjectByTag(GetTag(OBJECT_SELF))));
}
}
the operator has a default 50% chance of firing the catapult each 6 seconds.
can easily be changed if you want it to fire more often or seldom
This goes in the catapults OnUsed:
Code: void main()
{
// if (GetLocalInt(OBJECT_SELF, "CatapultReady") == 0)
// {
// edit these 4 numbers if needed
float TARGET_RADIUS = 6.0; // Constant used to determine the radius of the fireball's blast. Should be higher for Defenders than Attackers.
int AOEDAMAGE = d20(2); // Area of effect Damage dice for the firedamage on impact
float WAIT = 2.7; // delay between firing the catapult and creating the explosion.
float MISSRADIUS = 10.0; // max offset in meters from target area creating miss effect
// below does not need to be changed
object oTarget = GetObjectByTag((GetTag(OBJECT_SELF) + "_t")); // Selects a target named after the catapult tag followed by _t
// below looks messy but it just sets up random generator to create a range from neg to pos
float MISSNEG = MISSRADIUS +1.0; // dont touch =P
int MISSRAN = (FloatToInt(MISSRADIUS) * 2)+1; // no touche! =P
// vector calculation begin
vector vselfpos = GetPosition(oTarget); // get vector of current location
vselfpos.x = vselfpos.x + (MISSNEG - IntToFloat(Random( MISSRAN )));
vselfpos.y = vselfpos.y + (MISSNEG - IntToFloat(Random( MISSRAN )));
location lTarget = Location( GetArea(OBJECT_SELF), vselfpos, 20.0);
// vector calculation end .. lTarget is the new impact point with miss effect applied
object oHarmed = GetFirstObjectInShape(SHAPE_SPHERE, TARGET_RADIUS, lTarget, FALSE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE); // Begins the process of damaging all creatures and placeables within a sphere of the target.
//Function set that creates the fake fireball.
ActionCastFakeSpellAtLocation(SPELL_FIREBALL, lTarget, PROJECTILE_PATH_TYPE_BALLISTIC);
ActionWait(WAIT);
ActionDoCommand(ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_FIREBALL), lTarget));
SetLocalInt(OBJECT_SELF, "CatapultReady", 2);
while (oHarmed != OBJECT_INVALID)
{
ActionDoCommand(ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(AOEDAMAGE, DAMAGE_TYPE_FIRE), oHarmed));
ActionDoCommand(ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_FLAME_M), oHarmed));
oHarmed = GetNextObjectInShape(SHAPE_SPHERE, TARGET_RADIUS, lTarget, FALSE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE);
}
// }
// else
// SendMessageToPC(GetPCSpeaker(), "The catapult is not yet ready to use again.");
}
the first number you might want to tweak is:
float WAIT = 2.7;
in the catapult script.. it determines the delay between fire and impact.
you might want to set it as high as 10.0 seconds if the catapult fires at
extreme ranges. to time the actual impact of the fake fireball and the blast
it creates.
Hope you have fun with it =P
|