Author Topic: Constant RadiusImpulse for a set time  (Read 1442 times)

I'm making a Blackhole Generating device as the next WMD. I've tried making a shield in the past and came up with a similar problem: I can't get the impulse to "remain" or linger, it acts 1 time on everyone and everything in the specified Radius and then that's it.

What I need is a code that will generate an impulse field/zone, like the FireDamage script for the fire arrows in the ammo add-on. The FireDamage script from the firearrows would apply damage every X second(s), and last a certain amount of time. The fire damage would actually take into account the DamageRadius as well, so you could create huge feilds of firedamage. I need something like this, but for ImpulseForce instead of Damage. As for suction/pull, that's been resolved (RadiusImpulseforce was set to a NEGATIVE value)

Here are the last bits of the Blackhole generator script (called VoidCaller). I had added the FireArrow firedamage feature to it (which works perfectly), and another code someone gave me to help me with the sheild (under Firedamage, and this one doesn't quite work).

Code: [Select]
//This part works.

$FireSpeed = 100; //Higher = Slower
$FireAmount =5; //Higher = More Damage
$FireDamageTime = 10000;
function VoidCallerProjectile::radiusDamage(%this, %obj, %col, %distanceFactor, %pos, %damageAmt)
{
if(%col.getClassName() $= "Player" && %col.getState() !$= "Dead" && isObject(%col.client.minigame)){
%col.psn=schedule($FireSpeed,0,"timedmg",%col,$FireAmount,$DamageType::FArrowDirect,$FireSpeed,$FireDamageTime);}
%col.psnamount = 0;
}

function timedmg(%col,%amount,%type,%timer,%maxtime)
{
 if(%col.getClassName() $= "Player" && %col.getState() !$= "Dead" && isObject(%col.client.minigame)){
 %col.damage(%col, "Head", %amount, %type);
 %col.burn(1000);
 %col.psnamount = %col.psnamount + $FireSpeed;
 if(%col.psnamount < %maxtime){
%col.psn=schedule($FireSpeed,0,"timedmg",%col,%amount,%type,%timer,%maxtime);}}
}

function VoidCallerdProjectile::onCollision(%this, %obj, %slot){
     if(!%obj.client.isSuperAdmin && !%obj.client.isAdmin)
         return;
         %i = new Trigger() {
            position = %pos;
            rotation = "1 0 0 0";
            scale = "3 24 3";
            dataBlock = LastingImpulse;
            polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         };
   schedule(20000,0,TriggerDelete,%i);
}


//This part does not work.

datablock TriggerData(LastingImpulse){
   tickPeriodMS = 100;
};

function LastingImpulse::OnEnter(%this, %trigger, %obj){
   %obj.setVelocity(vectorAdd(%obj.getVelocity(),"0 0 500"));
}

function TriggerDelete(%obj){
   %obj.delete();
}

Could you guys help me out? I gave you the last bits which could or could not be salvaged, I'm just not sure.
Also I'm programming illiterate, and can't decipher/create code very well, so I might not understand what to do with a chunk of code you throw at me.
« Last Edit: October 31, 2007, 11:02:45 PM by Muffinmix »

You're not defining %pos in the onCollision function.

You're not defining %pos in the onCollision function.

Oh, how do I do that?

Code: [Select]
function VoidCallerdProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal){
     if(!%obj.client.isSuperAdmin && !%obj.client.isAdmin)
         return;
         %i = new Trigger() {
            position = %pos;
            rotation = "1 0 0 0";
            scale = "3 24 3";
            dataBlock = LastingImpulse;
            polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         };
   schedule(20000,0,TriggerDelete,%i);
}

Try this.

The Trigger's position is usually one corner of the trigger, not the center. Try this:

Code: [Select]
function VoidCallerdProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal){
     if(!%obj.client.isSuperAdmin && !%obj.client.isAdmin)
         return;
         %i = new Trigger() {
            position = vectorSub(%pos,vectorScale("3 24 3",0.5));
            rotation = "1 0 0 0";
            scale = "3 24 3";
            dataBlock = LastingImpulse;
            polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         };
   schedule(20000,0,TriggerDelete,%i);
}

Ok, the last bits now look like this

Code: [Select]
function VoidCallerdProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal){
     if(!%obj.client.isSuperAdmin && !%obj.client.isAdmin)
         return;
         %i = new Trigger() {
            position = vectorSub(%pos,vectorScale("3 24 3",0.5));
            rotation = "1 0 0 0";
            scale = "3 24 3";
            dataBlock = LastingImpulse;
            polyhedron = "0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000000 0.0000000 -1.0000000 0.0000000 0.0000000 0.0000000 1.0000000";
         };
   schedule(20000,0,TriggerDelete,%i);
}

datablock TriggerData(LastingImpulse){
   tickPeriodMS = 100;
};

function LastingImpulse::OnEnter(%this, %trigger, %obj){
   %obj.setVelocity(vectorAdd(%obj.getVelocity(),"0 0 500"));
}

function TriggerDelete(%obj){
   %obj.delete();
}

I am still not too sure how this all works, which value changes the impulseforce and the lifetime of the field? I tried changing tickPeriodMS to but that didn't quite work.

I think the field does work now however, because when the projectile detonated I began to orbit around it slightly, I think. It didn't last for very long.

   %obj.setVelocity(vectorAdd(%obj.getVelocity(),"0 0 500"));

The "500" is the impulse force. In this case it blasts you very high upwards.

What is the impulse forces etc on the projectile? That could be causing the "Orbit" thing.

Currently Impulse Radius and Impulse Force of the explosion are the following:

Code: [Select]
   impulseRadius = 200;
   impulseForce = -1000000;

The negative makes it pull people/vehicles towards it.

For projectile data it's the following:

Code: [Select]
   impactImpulse      = 1500;
   verticalImpulse   = 3000;

I left these as they were, chances of actually getting a direct hit are almost null.


   %obj.setVelocity(vectorAdd(%obj.getVelocity(),"0 0 500"));

The "500" is the impulse force. In this case it blasts you very high upwards.

What do the two other 0 values do? are they x and y axis values while 500 is the z axis one?


Ah ok
To get suction then, would I need to set all 3 values to equal negative values?

Code: [Select]
%scale = "1";
%obj.setVelocity(vectorAdd(%obj.getVelocity(),vectorScale(vectorSub(%trigger.position,%obj.position),%scale));

Try that. There may be a syntax error with brackets, it's late for me...

Change %scale to make it faster or slower.


In the trigger onEnter function.