PDA

View Full Version : Why won't this work?



1stXXZ
06-09-2002, 05:21 PM
I created this cog to slow down enemies. The only thing it doesn't do is slow them down. It stays on for the right time, and then turns off. Why won't it work? Here it is:

# Jedi Knight Cog Script
#
# FORCE_SLOW.COG
#
#Slows down an enemy for a short period of time.
#Replaces Blinding
#
#
#
#[XXZ]

symbols

thing player local
thing victim local

int rank local
int active=0 local

sound slowsound=forceslow1.wav local
sound slowsound2=forceslow2.wav local

message startup
message activated
message pulse
message timer
message killed
message selected

end

# ================================================== ======================================

code

startup:
player=GetLocalPlayerThing();
call stop_power;

Return;

# .................................................. ......................................

activated:
if(active) Return;

rank=GetInv(player, 27);
victim=-1;
active=1;
SetInvActivated(player, 27, 1);
SetPulse(0.33);
SetTimer(rank * 5);
victim=FirstThingInView(player, 30 + 15 * rank, 8, 0x404);
SetActorExtraSpeed(victim, -.5 + rank / 2);

Return;

#-----------------------------------------------------------------------------------------

pulse:
if(GetThingHealth(victim)<=0)
{
call stop_power;
}

Return;

#-----------------------------------------------------------------------------------------

timer:
call stop_power;

Return;

#-----------------------------------------------------------------------------------------

selected:
jkPrintUNIString(player, 27);

Return;

#-----------------------------------------------------------------------------------------

killed:
call stop_power;

Return;

#-----------------------------------------------------------------------------------------

stop_power:
SetPulse(0);
SetActorExtraSpeed(victim, 0);
SetInvActivated(player, 27, 0);
active=0;

Return;

end

Descent_pilot
06-10-2002, 07:11 AM
Rank is a positive number, so at least you get a 0, for rank 1. Change SetActor... to SetActorExtraSpeed(victim, -.5 - rank / 2); It'll slow the target down. Which brings me to my next point, I don't think your targeting will work. Model it after grip or pull. http://forums.massassi.net/html/wink.gif Come back if you still can't get it to work.

------------------
The Sniper Missions. Current project, The Sniper Missions

The_New_Guy
06-11-2002, 07:15 PM
I'm not positive of this, but I believe that: SetActorExtraSpeed(); only works locally (only on local player).

I think you will need to use Triggers/Skill Target and force the victim to run

SetActorExtraSpeed(player, -.5 + rank / 2);

maybe set it up similar to how the force_powers operate in kyle.cog

Descent_pilot
06-13-2002, 09:01 PM
The_New_Guy, LucasArts isn't the sharpest tool in the shed but they try to avoid confusion. If SetActorExtraSpeed(thing, flex); was for the local player only, it would be SetPlayerActorSpeed(flex); check the JKSpecs (http://www.massassi.net/jkspecs/), they are great cogging reference.

------------------
The Sniper Missions. Current project, The Sniper Missions

[This message has been edited by Descent_pilot (edited June 13, 2002).]

The_New_Guy
06-14-2002, 07:53 AM
Actaully I would say LucasArts failed pretty miserably in this respect.

Example:
All the inventory verbs only work locally even though you must specify player in the command parameters.

The JKSpecs, DataMaster, and Hidiki's sites are good references but no substitute for JK editing experience.

Descent_pilot
06-15-2002, 07:04 AM
Like I said 'they try to avoid confusion.' Good point on the experience. I do agree there.

------------------
The Sniper Missions. Current project, The Sniper Missions

[This message has been edited by Descent_pilot (edited June 17, 2002).]

gbk
06-15-2002, 08:12 AM
Yup, all the tuts and resources in the world cant compare to the experiance of actully cogging... http://forums.massassi.net/html/wink.gif

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources (http://www.tbns.net/GBK/ol/index.htm).

SaberMaster
06-15-2002, 11:43 AM
Here's my version of the force slow cog:



# force_slow.cog
#
# A force power to slow down victims.
# Meant to replace blinding.
#
# [SM]
#================================================= =====================#
symbols

thing player local
thing victim local
thing potential local
thing dummy local
thing target local

int rank local
int active local
int bin=27 local
int mana local

flex cost=20 local
flex maxDot local
flex dot local
flex timeleft local
flex mass local

vector vel local
vector momentum local
vector force local

sound slowsound=forceslow1.wav local
sound slowsound2=forceslow2.wav local

template cone_tpl=+force_blind local

message startup
message activated
message deactivated
message pulse
message timer
message killed
message selected

end
#================================================= =====================#
code
#----------------------------------------------------------------
startup:
player=GetLocalPlayerThing();
active=0;

Return;
#----------------------------------------------------------------
activated:
if(active) Return; // Return if the power is already in use.
active=1;
mana = GetInv(player, 14);
rank = GetInv(player, bin);
if(mana < cost) Return; // Return if we don't have the mana.
victim=-1;
SetInvActivated(player, bin, 1); // Show the icon.
SetPulse(0.2);

Return;
#----------------------------------------------------------------
pulse:
victim = -1;
maxDot = 0;

// Find the first player or actor in view of the player.
potential = FirstThingInView(player, 30 + 15 * rank, 8, 0x404);

// Loop until there are no more "next" things in view.
while(potential != -1)
{
// Test the thing to see if it's: in sight, not the player, within range, not dead, not a droid, and not using persuasion if we have force vision off.
if(HasLOS(player, potential) && potential != player && VectorDist(GetThingPos(player), GetThingPos(potential)) <= 1 + rank && !(GetThingFlags(potential) & 0x200) && !(GetActorFlags(potential) & 0x100) && !(jkGetFlags(potential) & 0x20 && !IsInvActivated(player, 23)))
{
// dot will be the dot product of the angle between the direction the player is looking and a direction from the player to the potential target.
dot = ThingViewDot(player, potential);

// If dot is greater than 0 or the dot of the last potential, then the new potential is closer to the center of the player's LOS.
if(dot > maxDot)
{
// Store this target's number and remember the dot.
victim = potential;
maxDot = dot;
}
}

// Get the next thing in view for the next loop.
potential = NextThingInView();
}

// If victim is not equal to -1, then we've found an acceptable target.
if(victim != -1)
{
// Set the reticle's colors and put it on the target.
jkSetTargetColors(1, 2, 3);
jkSetTarget(victim);
}

// If we did not find a good target during this pulse, then we may have lost sight of a good target from the previous pulse.
else jkEndTarget(); // So remove the reticle.

Return;
#----------------------------------------------------------------
deactivated:
SetPulse(0); // Stop the pulse message.

// If we don't have a target or the player is dead, stop the power and quit.
if(victim == -1 || GetThingHealth(player) < 1)
{
SetInvActivated(player, bin, 0);
active=0;
Return;
}

jkEndTarget(); // Remove the reticle.
mana = GetInv(player, 14);
if(mana < cost) Return; // Stop here if we don't have the mana.

// Unless we have a force surge, subtract the cost from the mana.
if(GetInv(player, 65) != 1) ChangeInv(player, 14, -cost);
SetBinWait(player, bin, 0.2); // Stop this force power from being used for 0.2 seconds.

PlayMode(player, 24); // Play a throw animation.
PlaySoundThing(slowSound, player, 1.0, -1, -1, 0x80); // Play the blinding sound.

// Create a particle stream and direct it at the target.
dummy = CreateThingAtPosNR(cone_tpl, GetThingSector(player), VectorAdd(GetThingPos(player), '0.0 0.0 0.04'), '0.0 0.0 0.0');
SetThingLook(dummy, VectorSub(GetThingPos(victim), GetThingPos(player)));

if(GetThingType(victim) == 10) // Human opponent.
{
SkillTarget(victim, player, bin, rank); // Call the skill message in the other player's kyle.cog.
}
else // AI opponent.
{
SetTimerEx(0.1, victim, GetThingSignature(victim), rank * 15);
}

active = 0;
SetInvActivated(player, bin, 0); // Remove the force power's icon.

Return;
#----------------------------------------------------------------
timer:
target = GetSenderID();

// Check the signature (unique ID) to make sure this is the same target.
if(GetThingSignature(target) != GetParam(0)) Return;

timeleft = GetParam(1) - 0.1; // Calculate time left and return if time is up.
if(timeleft < 0) Return;

vel = GetThingVel(target);
if(VectorLen(vel) > 0.1) // If the enemy's speed is less than 0.1, then we shouldn't try to slow him down.
{
mass = GetThingMass(target);
momentum = VectorScale(vel, mass);
force = VectorScale(momentum, -0.9);
ApplyForce(target, force); // Apply enough force to reduce his velocity by 90%
}

SetTimerEx(0.1, target, GetThingSignature(target), timeleft);

Return;
#----------------------------------------------------------------
selected:
jkPrintUNIString(player, bin); // Make sure the 27'th UNI string reads "Force Slow."

Return;
#----------------------------------------------------------------
killed:
SetPulse(0);
SetInvActivated(player, bin, 0);
active=0;

Return;
#----------------------------------------------------------------
end


I don't think you can use SetActorExtraSpeed() with AI. At least, it's always been my
experience that AI are not affected by the verb. And I decided not use AISetMoveSpeed()
because AI can reset their move speed.

So instead, I applied enough force to the victim to reduce his momentum by 90% each
0.1 seconds. This system is more realistic if not an elegant solution.

Notice that if the victim is a player, he is skilled just the same as the original force
blinding cog did. The code in kyle.cog for blinding attacks needs to be modified. But
for that, you can use SetActorExtraSpeed().

Good luck. http://forums.massassi.net/html/wink.gif

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/fileframe.html), Parsec (http://www.geocities.com/sabersdomain/fileframe.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/fileframe.html).
Visit Saber's Domain (http://www.geocities.com/sabersdomain).

[This message has been edited by SaberMaster (edited June 15, 2002).]