(no subject)

Dec 01, 2004 23:38

Well I did it.


# Jedi Knight Cog Script
#
# WEAP_BRYAR.COG
#
# WEAPON 2 Script - Bryar Pistol
#
# The trusty weapon of Kyle Katarn. This is actually an older modified rifle
# that has been cut down to more of a pistol size. It is very accurate but
# somewhat of a low power weapon. This weapon has only one type of fire.
#
# - Affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved
#
#
#THINGS TO DO:
#proximity jiggle
#burn damage
#==============================================================#
symbols

model povModel=bryv.3do local
model weaponMesh=bryg.3do local
model grenmodel=det0.3do local

keyframe mountAnim=bryvmnt.key local
keyframe dismountAnim=bryvdis.key local
keyframe holsterAnim=kyhlstr.key local

sound outSound=pistout1.wav local
sound mountSound=df_bry_ready.wav local
sound dismountSound=PutWeaponAway01.wav local
sound fireSound=pistol-1.wav local

template projectile=ghost local

thing player local
thing victim local

flex fireWait=0.5 local
flex holsterWait local
flex powerBoost local

int weaponIndex local
int trackID=-1 local
int dummy=0 local
int mode local
int retval local
int count local
int mass local
int type local
int holsterTrack local
int IsOn local
int distance local
int sender local
int switch local
int sentvel local
int forcescale local

vector LForce local
vector tossforce local
vector gravforce local
vector facepos local
vector dir local
vector upforce local
vector totalforce local

message activated
message deactivated
message selected
message deselected
message autoselect
message fire
message timer
message pulse

end
#==============================================================#
code
#------------------------------------------------------
fire:
player = GetSourceRef();
// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
// Check Ammo - If we are out, autoselect best weapon.
if(GetInv(player, 11) < 1.0)
{
PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
Print("Out Of Energy");
Return;
}

if(mode == 0)
{
if(IsOn == 1 && victim != -1)
{
SetPulse(0.0);
Print("launching projectile");
dummy = FireProjectile(player, projectile, fireSound, 8, VectorScale('0.0135 0.1624 0.0', 5), '0 0 0', 1.0, 0x20, 1, 1);
LForce = VectorScale(GetThingLVec(dummy), GetThingMass(victim) * 10);
ApplyForce(victim, LForce);
SetPhysicsFlags(victim, 0x1); //return gravity
SetPhysicsFlags(victim, 0x50);
//jkEndTarget(victim);
SetPulse(0.0);
SetTimerEx(0.01, victim, 911, 0);
victim = -1;
IsOn = 0;
}
else if(IsOn == 0)
{
//SetPulse(0.0);
Print("primary fire");
victim = FirstThingInView(player, 20, 19, 0x4FE);
if((victim != -1) && (HasLOS(player, victim)))
{
jkSetTarget(victim);
DetachThing(victim);
ClearPhysicsFlags(victim, 0x1);
distance = VectorLen(VectorNorm(VectorSub(GetThingPos(victim), GetThingPos(player))));
tossforce = VectorScale(VectorSub(GetThingPos(victim), GetThingPos(player)), 300 - distance * distance);
mass = GetThingMass(victim);
upforce = VectorScale(VectorSet(0, 0, 1), mass / 2);
totalforce = VectorAdd(tossforce, upforce);
ApplyForce(victim, totalforce);
SetPhysicsFlags(victim, 0x1); //return gravity
SetPhysicsFlags(victim, 0x50);
SetTimerEx(0.01, victim, 911, 0);
//dummy = FireProjectile(player, projectile, fireSound, 8, '0.0135 0.1624 0.0', '0 0 0', 1.0, 0x20, 1, 1); //kinetic blast
Return;
}
}
}
else
{
if(IsOn == 0) //gun hasn't been activated yet
{
victim = FirstThingInView(player, 20, 100, 0x4FE);
if((victim != -1) && (HasLOS(player, victim)))
{
type = GetThingType(victim);
printint(type);
if(type == 2) //actor
{
IsOn = 1; //activate gun
jkSetTarget(victim);
Print("Fired");
SetPulse(.01);
Return;
}
if(type == 10) //player, simply pull their weapon if within range with bit of randomness applied
{
if(!(GetThingFlags(victim) & 0x200))
{
retval = SkillTarget(victim, player, 420, VectorLen(VectorSub(GetThingPos(player), GetThingPos(victim))));
victim = retval;
IsOn = 1; //activate gun
jkSetTarget(victim);
Print("Fired");
SetPulse(.01);
Return;
}
}
if(type == 5 || type == 4) //item or debris
{
IsOn = 1; //activate gun
jkSetTarget(victim);
Print("Fired");
SetPulse(.01);
}
else Return; //if it's not any of the above, kill script
}
}
else
{
Print("Deactivated");
IsOn = 0;
//jkEndTarget(victim);
SetPhysicsFlags(victim, 0x1); //return gravity
SetPhysicsFlags(victim, 0x50);
SetPulse(0.0);
SetTimerEx(0.01, victim, 911, 0);
victim = -1;
}
}
ChangeFireRate(player, fireWait);

Return;
#------------------------------------------------------
activated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '0.0 0.0 0.0', 0);
powerBoost = GetInv(player, 63);
ActivateWeapon(player, fireWait / powerBoost, mode);

Return;
#------------------------------------------------------
deactivated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '10.0 7.0 0.0', 350);
DeactivateWeapon(player, mode);

Return;
#------------------------------------------------------
selected:
player = GetSourceRef();
IsOn = 0;
// Setup the meshes and models.
jkSetPOVModel(player, povModel);
jkSetWeaponMesh(player, weaponMesh);
SetArmedMode(player, 1);
// Play mounting sound.
PlayMode(player, 41);
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
// Play the animation (NOLOOP + UNIQUE + ENDPAUSE).
// The animation is held at the last frame after it is played.
trackID = jkPlayPOVKey(player, mountAnim, 0, 0x14);
jkSetWaggle(player, '10.0 7.0 0.0', 350);
// Clear saber flags, and allow activation of the weapon
jkClearFlags(player, 0x5);
SetCurWeapon(player, 2);
SetMountWait(player, GetKeyLen(mountAnim));

Return;
#------------------------------------------------------
deselected:
player = GetSourceRef();
weaponIndex = GetSenderRef();
PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
jkPlayPOVKey(player, dismountAnim, 0, 0x18);
holsterWait = GetKeyLen(holsterAnim);
SetMountWait(player, holsterWait);
holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
SetTimerEx(holsterWait, 2, 0.0, 0.0);
if(trackID != -1)
{
jkStopPOVKey(player, trackID, 0);
trackID = -1;
}
jkSetWaggle(player, '0.0 0.0 0.0', 0);

Return;
#------------------------------------------------------
autoselect:
player = GetSourceRef();
// If the player has the weapon
if(GetInv(player, 2) != 0.0)
{
// If the player has ammo
if(GetInv(player, 11) != 0.0)
{
ReturnEx(500.0);
}
else
{
ReturnEx(-1.0);
}
}
else
{
ReturnEx(-1.0);
}

Return;
#------------------------------------------------------
timer:
sender = GetSenderID();
switch = GetParam(0);
count = GetParam(1);
printint(switch);
if(switch != 911 && switch != 912)
{
StopKey(player, holsterTrack, 0.0);
Return;
}
if((switch == 911) && (GetThingAttachFlags(sender) != 1)) //hasn't attached to ground
{
Print("gravity returned");
sentvel = VectorLen(GetThingVel(sender));
//PrintInt(sentvel);
forcescale = 5 + sentvel / 10;
gravforce = VectorScale(VectorSet(0, 0, -1), forcescale);
ApplyForce(sender, gravforce);
SetTimerEx(0.01, sender, switch, 0);
Return;
}
if((switch == 911) && (GetThingAttachFlags(sender) == 1)) //has attached to ground
{
Print("returning to ground");
SetTimerEx(0.01, sender, 912, 0);
Return;
}
if(switch == 912)
{
count = count + 1;
printint(count);
if(GetThingAttachFlags(sender) == 1 || count >= 30)
{
Print("returned to ground");
jkEndTarget();
KillTimerEx(sender);
Return;
}
else
{
SetTimerEx(0.01, sender, 912, count);
Return;
}
}

Return;
#------------------------------------------------------
pulse:
if(victim != -1)
{
dummy = FireProjectile(player, projectile, fireSound, 8, VectorScale('0.0135 0.1624 0.0', 5), '0 0 0', 1.0, 0x20, 1, 1);
//if(dummy != -1)
//print("dummy fired");
//else
//print("dummy not fired");
StopThing(dummy);
facepos = GetThingPos(dummy);
//printvector(facepos);
DestroyThing(dummy);
DetachThing(victim);
ClearPhysicsFlags(victim, 0x1);
distance = VectorLen(VectorNorm(VectorSub(facepos, GetThingPos(victim))));
//PrintFlex(distance);
//PrintFlex(GetThingMass(victim));
dir = VectorScale(VectorSub(facepos, GetThingPos(victim)), GetThingMass(victim) * 2 - distance * 5);
ApplyForce(victim, dir);
if(GetThingType(victim) == 2 && GetThingHealth(victim) < 0)
SetPulse(0.0), print("target killed");
return;
}
else
{
SetPulse(0.0);
Print("target destroyed");
jkEndTarget();
}
setpulse(0.0);
jkEndTarget(); //failsafe
killtimerex(victim);
killtimerex(sender);
Return;
#------------------------------------------------------
end

my brain aches
Previous post Next post
Up