PDA

View Full Version : Help with Force Push/Pull



Lord Kaje
11-17-2003, 05:02 PM
Everything works well -- EXCEPT --

If I activate this COG when there is nothing "Pushable/Pullable" in view, it will automatically activate on a "Pushable/Pullable" object or NPC - i.e., you can activate it in a completely clear area, go through a door into another area that has an NPC or, say, a shield powerup & said NPC or powerup will be automatically effected.


# Jedi Knight Cog Script
#
# FORCE_PULL.COG
#
# FORCEPOWER Script - Force Pull
# Basic Power
# Bin 24
#
# [YB]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

template powerup local

int player local
int victim local
int potential local
int throwThing local

flex cost=30.0 local
int rank local
flex mana local
flex dot local
flex maxDot local

int type local
int retval=0 local

vector dir local

int IsAFlag=0 local

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

keyframe push=kyrepel0.key local
keyframe pull=kyfpull0.key local

sound pushsound=ForcePush01.WAV local
sound pullsound=ForcePull01.WAV local

end

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

code

startup:
player = GetLocalPlayerThing();

Return;

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

activated:
// Cannot use power if blinded
if(GetActorFlags(player) & 0x800) Return;

if(IsInvActivated(player, 24)) Return;

mana = GetInv(player, 14);
rank = GetInv(player, 24);

if(mana >= cost)
{
victim = -1;
SetInvActivated(player, 24, 1);
SetPulse(0.033);
}
Return;

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

pulse:

// Check all things for our victim.
victim = -1;
maxDot = 0;

player = GetLocalPlayerThing();
thrust = GetThingThrust( player );
actorFlags = GetActorFlags(player);

// Search for all players, actors and items.
potential = FirstThingInView(player, 20 + 15 * rank, 5.5, 0x424);
while(potential != -1)
{
if(HasLOS(player, potential) &&
(potential != player) &&
(VectorDist(GetThingPos(player), GetThingPos(potential)) <= (0.5 + rank / 2)) &&
!(GetThingFlags(potential) & 0x200) &&
!(GetActorFlags(potential) & 0x100) &&
!((jkGetFlags(potential) & 0x20) &&
!IsInvActivated(player, 23))
)
{
// Hack to avoid targetting a CTF flag...
IsAFlag = 0;
if(GetThingType(potential == 5))
{
if(GetItemFlags(potential) & 8)
{
IsAFlag = 1;
}
}

if(!IsAFlag)
{
dot = ThingViewDot(player, potential);
if(dot > maxDot)
{
victim = potential;
maxDot = dot;
}
}

}
potential = NextThingInView();
}

// If we have a victim...
if(victim != -1)
{
jkSetTargetColors(18, 19, 20);
jkSetTarget(victim);
}
else
{
jkEndTarget();
}

//Forward = Push
if((victim == -1) || (GetThingHealth(player) <= 0))
{
call stop_power;
Return;
}
if (VectorY(thrust) > 0)
{
Print("Force Push");
call push;
SetPulse(0);
PlayKey(player, push, 1, 0x38);
PlaySoundThing(pushsound, player, 1.0, -1, -1, 0x80);
}

//Backpedal = Pull
if((victim == -1) || (GetThingHealth(player) <= 0))
{
call stop_power;
Return;
}
if (VectorY(thrust) < -1)
{
Print("Force Pu11");
call pull;
SetPulse(0);
PlayKey(player, pull, 1, 0x38);
PlaySoundThing(pullsound, player, 1.0, -1, -1, 0x80);
}

Return;

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

deactivated:

SetInvActivated(player, 24, 0);
victim = -1;
call stop_power;
jkEndTarget();
SetPhysicsFlags(player, 0x4a4f);

Return;

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

push:

if((victim == -1) || (GetThingHealth(player) <= 0))
{
call stop_power;
Return;
}
jkEndTarget();

mana = GetInv(player, 14);

if(mana >= cost)
{
if(HasLOS(player, victim)) // check that we still have a LOS on it...
{
if(!IsInvActivated(player, 23)) AddDynamicTint(player, 0.0, 2.0, 0.0);
PlayKey(player, pull, 1, 0x38);
PlaySoundThing(PushSound, player, 1.0, -1, -1, 0x80);
SendTrigger(-1, 250, player, victim, 0, 0);
dir = VectorScale(VectorNorm(VectorSub(GetThingPos(playe r), GetThingPos(victim))), -400);
ApplyForce(victim, dir);
if(GetInv(player, 64) != 1) ChangeInv(player, 14, -cost);
SetBinWait(player, 24, 1);
}
}
;
SetInvActivated(player, 24, 0);
SetBinWait(player, 24, 1);

Return;

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

pull:

if((victim == -1) || (GetThingHealth(player) <= 0))
{
call stop_power;
Return;
}
jkEndTarget();

mana = GetInv(player, 14);

if(mana >= cost)
{
if(HasLOS(player, victim)) // check that we still have a LOS on it...
{
if(!IsInvActivated(player, 23)) AddDynamicTint(player, 0.0, 0.0, 20.0);
PlayKey(player, Pull, 1, 0x38);
PlaySoundThing(PullSound, player, 1.0, -1, -1, 0x80);
if((GetInv(player, 64) != 1) && (GetInv(player, 65) != 1)) ChangeInv(player, 14, -cost);
SetBinWait(player, 24, 1.0);
SendTrigger(-1, 240, player, victim, 0, 0);

throwThing = -1;
type = GetThingType(victim);
if(type == 2) // ACTOR
{
dir2 = VectorScale(VectorNorm(VectorSub(GetThingPos(playe r), GetThingPos(victim))), 200);
ApplyForce (victim, dir2);

if(GetActorWeapon(victim, 1) != -1)
{
// Make victim drop powerup.
throwThing = SkillTarget(victim, player, 24, 0);

if(throwThing != -1)
{
SetActorWeapon(victim, 1, -1);
AmputateJoint(victim, 3);
}
}
else
{
SetInvActivated(player, 24, 0);
Return;
}

}
else
if(type == 10) // OTHER PLAYER
{
dir2 = VectorScale(VectorNorm(VectorSub(GetThingPos(playe r), GetThingPos(victim))), 200);
ApplyForce(victim, dir2);

if(!(GetThingFlags(victim) & 0x200))
retval = SkillTarget(victim, player, 24, rank);
SetInvActivated(player, 24, 0);
Return;
}
else
if(type == 5) // ITEM
{
retval = SkillTarget(victim, player, 24, rank);

if(retval != 0)
{
if(!GetLifeLeft(victim)) SetLifeleft(victim, 30.0);
throwThing = victim;
}
else
{
SetInvActivated(player, 24, 0);
Return;
}
}

// Throw item at player.
if(throwThing != -1)
{
SetTimerEx(1.5, 1, throwThing, 0);

// Duplicate sends for lost packets
SetTimerEx(3.5, 2, throwThing, 0);
SetTimerEx(3.6, 2, throwThing, 0);

if(IsMulti())
{
// Kill the thing
SetTimerEx(4.0, 3, throwThing, 0);
// Duplicate send for lost packets
SetTimerEx(4.1, 4, throwThing, 0);
}

// Turn off gravity for the thing
ClearPhysicsFlags(throwThing, 0x1);

dir = VectorScale(VectorNorm(VectorSub(GetThingPos(playe r), GetThingPos(throwThing))), 50);
ApplyForce(throwThing, dir);
}
}
}

SetInvActivated(player, 24, 0);

Return;

#................................................. ...............................................#
timer:

if(GetSenderId() == 1)
{
// We MUST set gravity whatever the original setting,
// else objects might just float around...
SetPhysicsFlags(GetParam(0), 1);
Return;
}
else
if(GetSenderId() == 2)
{
// Set back to no gravity after the object had a chance to
// settle down for next time they respawn...
ClearPhysicsFlags(GetParam(0), 1);
Return;
}
else
if(GetSenderId() == 3)
{
// SITH_TF_DISABLED
SetThingFlags(GetParam(0), 0x80000);
SetLifeLeft(GetParam(0), 26);
Return;
}
else
if(GetSenderId() == 4)
{
SetThingFlags(GetParam(0), 0x80000);
SetLifeLeft(GetParam(0), 25.9);
Return;
}

Return;

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

selected:
jkPrintUNIString(player, 24);
Return;

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

deselected:
call stop_power;
Return;

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

killed:
if(GetSenderRef() != player) Return;

newplayer:
call stop_power;

Return;

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

stop_power:
SetInvActivated(player, 24, 0);
victim = -1;
jkEndTarget();

Return;

end


What might I be overlooking...?

Thanx!

_K_



[This message has been edited by SaberMaster (edited November 19, 2003).]

Checksum
11-18-2003, 11:40 PM
try the code tags,
like this.

It'd be fine otherwise, but force pull is the biggest cog in the game.

------------------
Duel Zero (http://forums.massassi.net/html/Forum5/HTML/010438.html) key count: Zero! Down to guns and forces. Expect a release soon.

SaberMaster
11-19-2003, 07:15 PM
No need for two of these checks in pulse.



if((victim == -1) || (GetThingHealth(player) <= 0))

What is this?



}
;
SetInvActivated(player, 24, 0);


There's some other redundant code, unused variables, variables not defined, etc. Reread your code, fix the errors and then run your cog through Parsec (the link is in my sig). The HasLOS() check should make sure the target isn't behind a wall.

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/files.html), Parsec (http://www.geocities.com/sabersdomain/files.html), Scribe (http://www.geocities.com/sabersdomain/files.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/files.html).

Lord Kaje
11-20-2003, 04:13 AM
Thanx...!

Yeah, this piece has really become jumbled... really needs a qwik clean-up.

_K_

SaberMaster
11-20-2003, 04:58 PM
Sure. http://forums.massassi.net/html/wink.gif

------------------
Author of the JK DataMaster (http://www.geocities.com/sabersdomain/files.html), Parsec (http://www.geocities.com/sabersdomain/files.html), Scribe (http://www.geocities.com/sabersdomain/files.html), and the EditPlus Cog Files (http://www.geocities.com/sabersdomain/files.html).

Hell Raiser
11-22-2003, 10:24 PM
Make sure the thing is visable before you target it, and make sure the range (in JKU's) in FTiV() isn't set insanely high.

------------------
-Blessed Be-
I know it's the last day on earth,
We'll be together while the planet dies.
DBZ: The Destruction is Real (http://www.hellraiser64.com/tdir)