PDA

View Full Version : force push



a_person
07-09-2004, 04:28 AM
Hi. This is my force push cog.


# 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=20.0 local
int rank local
flex mana local
flex dot local
flex maxDot local

int type local
int retval=0 local

vector dir local

sound pullSound=ForcePull01.WAV local

int IsAFlag=0 local

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

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.33);
}
Return;

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

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

// 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();
}

Return;

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

deactivated:

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

SetPulse(0);
jkEndTarget();

mana = GetInv(player, 14);

if(mana >= cost)
{
if(HasLOS(player, victim)) // check that we still have a LOS on it...
{
PlayMode(player, 24);
PlaySoundThing(pullSound, player, 1.0, -1, -1, 0x80);
if((GetInv(player, 64) != 1) && (GetInv(player, 65) != 1)) ChangeInv(player, 14, -cost);
SetBinWait(player, 24, 0.2);

throwThing = -1;
type = GetThingType(victim);
if(type == 2) // ACTOR
{
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);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
}
}
else
{
SetInvActivated(player, 24, 0);
Return;
}

}
else
if(type == 10) // OTHER PLAYER
{
if(!(GetThingFlags(victim) & 0x200))
retval = SkillTarget(victim, player, 24, rank);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
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);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
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);


ApplyForce(victim, VectorScale(GetThingLVec(player), 1000)); }
}
}

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:
SetPulse(0);
SetInvActivated(player, 24, 0);
victim = -1;
jkEndTarget();

Return;

end



Its just a really tiny modification of the force pull cog. It works fine but when I try to push an enemy of a cliff he just stops at the edge and wont go off. Can someone modify it to do that. Also it currently wont push people with no weapon, e.g. civilians and people using fists. Can someone modify it to do that aswell.

Thanks.

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~

Quib Mask
07-09-2004, 05:41 AM
Here's my force push cog, it passes checksum and should do everything you're asking for.


# Jedi Knight Cog Script
#
# FORCE_PULL.COG
#
# FORCEPOWER Script - Force Push
# Basic Power
# Bin 24
#
# [QM]
#
# (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

sound pullSound=ForcePull01.WAV local

int IsAFlag=0 local
int negone=-1 local

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

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.33);
}
Return;

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

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

// 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;
}
}
// Event Horizon
if(!IsAFlag)
{
dot = ThingViewDot(player, potential);
if(dot > maxDot)
{
victim = potential;
maxDot = dot;
}
}

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

Return;

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

deactivated:

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

SetPulse(0);
jkEndTarget();

mana = GetInv(player, 14);

if(mana >= cost)
{
if(HasLOS(player, victim)) // check that we still have a LOS on it...
{
PlayMode(player, 24);
PlaySoundThing(pullSound, player, 1.0, -1, -1, 0x80);
if((GetInv(player, 64) != 1) && (GetInv(player, 65) != 1)) ChangeInv(player, 14, -cost);
SetBinWait(player, 24, 0.5); // 0.2

throwThing = -1;
type = GetThingType(victim);
if(type == 2) // ACTOR
{
if(GetActorWeapon(victim, 1) != -1)
{
// Make victim drop powerup.
throwThing = SkillTarget(victim, player, 24, 0);
SetActorWeapon(victim, 1, negone);
AmputateJoint(victim, 3);
}
else
{
SetInvActivated(player, 24, 0);
}
type = 10;
}
else
if(type == 10) // OTHER PLAYER
{
// SkillTarget was here...
SetInvActivated(player, 24, 0);
}
else
if(type == 5) // ITEM
{
retval = SkillTarget(victim, player, 24, rank);
if(retval != 0)
{
if(!GetLifeLeft(victim)) SetPhysicsFlags(victim, 1);
throwThing = victim;
}
else
{
SetInvActivated(player, 24, 0);
}
}
// 120 * rank = 480
dir = VectorScale(VectorNorm(VectorSub(GetThingPos(victi m), GetThingPos(player))), (type - 4.5) * 22.5 * rank);
ApplyForce(victim, dir);

// 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(30.0, 3, throwThing, 0); // 4.0
// Duplicate send for lost packets
SetTimerEx(30.1, 4, throwThing, 0); // 4.1
}

// Turn off gravity for the thing
SetPhysicsFlags(throwThing, 0x1); // Clear
}
}
}

SetInvActivated(player, 24, 0);

Return;

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

if(0)
{
-1, -1, -1, -1, -1, -1, -1, -1;
1, 1;
if(0);
}
Return;

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

timer:

if(GetSenderId() == 1)
{
// We MUST set gravity whatever the original setting,
// else objects might just float around...
SetPhysicsFlags(GetParam(0), 0x1);
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), 0x1);
Return;
}
else
if(GetSenderId() == 3)
{
TakeItem(GetParam(0), GetParam(0));
Return;
}
else
if(GetSenderId() == 4)
{
TakeItem(GetParam(0), GetParam(0));
Return;
}

Return;

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

selected:
jkPrintUNIString(player, 24);
Return;

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

deselected:
call stop_power;
Return;

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

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

newplayer:
call stop_power;

Return;

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

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

Return;

end


Quib Mask

[This message has been edited by Quib Mask (edited July 09, 2004).]

zagibu
07-09-2004, 06:01 AM
I think you just have to detach him and lift him a little off ground...but then again you could just use quib masks cog...

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

Quib Mask
07-09-2004, 09:51 AM
The other benefit to my cog is if you push items, they won't disappear forever/respawn in the wrong spot like they do if you use force pull but don't grab the item. They often respawn sunk in the ground a little, but I couldn't do anything to fix that and am not really sure why it occurs (better half sunk in ground rather than never appears again...).

To do this I simply have the item TakeItem itself, so it disappears and waits the normal time for respawn.

The reason your cog didn't push civilians/unarmed baddies is because you put the push code within if(throwThing != -1) which checks if the baddie has a pullable weapon. Since a baddie with a fist doesn't have a weapon, they weren't being pushed.

Quib Mask

[This message has been edited by Quib Mask (edited July 09, 2004).]

a_person
07-09-2004, 08:04 PM
Ok new code. I got it so you can push them off cliffs now. Also so that once you push someone you can push them again. Only bugs now: Still cant push civilians or punching people, if you push someone with a gun twice he creates a new gun pickup even though he has no gun.


# 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=20.0 local
int rank local
flex mana local
flex dot local
flex maxDot local
int type local
int retval=0 local
vector dir local
sound pullSound=ForcePull01.WAV local
int IsAFlag=0 local
message startup
message activated
message deactivated
message pulse
message timer
message newplayer
message killed
message deselected
message selected
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.33);
}
Return;
# .................................................. ......................................
pulse:
// Check all things for our victim.
victim = -1;
maxDot = 0;
// 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();
}
Return;
# .................................................. ......................................
deactivated:
if(GetThingHealth(player) <= 0)
{
call stop_power;
Return;
}
SetPulse(0);
jkEndTarget();
mana = GetInv(player, 14);
if(mana >= cost)
{
if(HasLOS(player, victim)) // check that we still have a LOS on it...
{
PlayMode(player, 24);
PlaySoundThing(pullSound, player, 1.0, -1, -1, 0x80);
if((GetInv(player, 64) != 1) && (GetInv(player, 65) != 1)) ChangeInv(player, 14, -cost);
SetBinWait(player, 24, 0.2);
throwThing = -1;
type = GetThingType(victim);
if(type == 2) // ACTOR
{
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);
DetachThing(victim);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
}
}
else
{
SetInvActivated(player, 24, 0);
Return;
}
}
else
if(type == 10) // OTHER PLAYER
{
if(!(GetThingFlags(victim) & 0x200))
retval = SkillTarget(victim, player, 24, rank);
DetachThing(victim);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
SetInvActivated(player, 24, 0);
Return;
}
else
if((victim == -1) || (type == 2))
{
// Make victim drop powerup.
throwThing = SkillTarget(victim, player, 24, 0);
{
SetActorWeapon(victim, 1, 1);
DetachThing(victim);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
}

}
else
if(type == 5) // ITEM
{
retval = SkillTarget(victim, player, 24, rank);
if(retval != 0)
{
if(!GetLifeLeft(victim)) SetLifeleft(victim, 30.0);
ApplyForce(victim, VectorScale(GetThingLVec(player), 1000));
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);

ApplyForce(victim, VectorScale(GetThingLVec(player), 1000)); }
}
}
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:
SetPulse(0);
SetInvActivated(player, 24, 0);
victim = -1;
jkEndTarget();
Return;
end



If someone could take these bugs out it would be really apreciated.

Thanks.

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~

lucky_jackpot
07-10-2004, 02:09 AM
I know it's been a while since I last looked at this sort of force power thing, but I'm sure there's a "+repel" template that you can fire off at someone in JK. Come to think of it, yes there is as Boc uses it as one of his force powers, not to mention I've got it working in the past, for a custom dark jedi... http://forums.massassi.net/html/smile.gif. Why not have a look into this possibility? http://forums.massassi.net/html/smile.gif

I know I haven't corrected/modified any of your code (sorry, but "real life" has been getting in the way recently, hence my lack of appearance over the last couple of weeks), but I hope this helps http://forums.massassi.net/html/smile.gif - at the very least, you're receiving different ideas to experiment with http://forums.massassi.net/html/wink.gif http://forums.massassi.net/html/biggrin.gif

-Jackpot

[EDIT: ...not to mention the utter w00tage that is to be had by accumulating 600 posts now... http://forums.massassi.net/html/wink.gif http://forums.massassi.net/html/biggrin.gif]

------------------
"lucky_jackpot is the smily god..." - gothicX
"jackpot is an evil evil man... so evil, in fact, that he's awesome." - Seb

"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)

[This message has been edited by lucky_jackpot (edited July 10, 2004).]

zagibu
07-10-2004, 02:27 AM
I see an error after the CTF flag "hack" line. You have there:


if(GetThingType(potential == 5))

Shoudn't that be:


if(GetThingType(potential) == 5)

There might be more errors like this one, but I'm too lazy to read it all through.

------------------
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)

Quib Mask
07-10-2004, 03:30 AM
+force_repel isn't in every level's templates. All it does it make a force "explosion" that does no damage and pushes with 200 force (the same as the +force_dest2 explosion, just without the damage).

I'd say stick with what you have now... or use the cog I posted seeing as it has pushing scaled to the rank you have push at, pushes items with less force than player (items have much less mass than players so less force pushes them farther than a player), and is a pretty dang good force push cog. =P

Also, I explained why your cog can't push civilians and unarmed enemies; did you not read my post?

Quib Mask

a_person
07-10-2004, 04:35 AM
I read your post and after taking one or two of those line like that out it aloud me to push away puching enemys but not civilians or enemys who have already been pushed. I managed to get it to push away already pushed enemys but the problem is it creates an additional powerup when pushed. Also I would use your cog but im trying to learn how to do some of this stuff on my own.

If anyone could perhaps point out how I could get it to push civilians??

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~

a_person
07-10-2004, 04:50 AM
Ok I fixed the problem. Thanks for the help everyone!

------------------
~Nightfire Mod (http://www.nightfire.uni.cc)~