PDA

View Full Version : A new problem arises!!!



Edward
06-10-2004, 10:08 AM
# 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


symbols

model povModel=PulseV.3DO local
model weaponMesh=PulseInHand.3DO local

keyframe mountAnim=PulseUp.key local
keyframe dismountAnim=PulseDown.key local
keyframe povfireAnim=PulseShoot.key local
keyframe holsterAnim=kyhlstr.key local
keyframe povGren=PulseGrenade.key local

keyframe povboredAnim0=PulseV_bored1.key local
keyframe povboredAnim1=PulseV_bored2.key local

sound outSound=pulse_rifle_empty.wav local
sound mountSound=invrotate.wav local
sound dismountSound=PutWeaponAway01.wav local
sound fireSound=pulse.wav local
sound grenadeR=Ed_PulseGrenade_reload.wav local
sound grenadeF=Ed_PulseGrenade_Launch.wav local
sound boredsnd0=swingfist01.wav local
sound boredsnd2=swingfist04.wav local
sound boredsnd3=trprout.wav local

template projectile=+bryarbolt local
template projgren=+grenade3 local

thing player local

flex fireWait=0.05 local
flex holsterWait local
flex autoAimFOV=30 local

int weaponIndex local
int trackID=-1 local
int dummy=0 local
int mode local
int holsterTrack local
int onegrenade=0 local
int busy=0 local

int bob=-1 local

int boredtrack=-1 local
flex oldammo local
int br local

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


end

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

code

fire:
player = GetSourceRef();

// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
KillTimerEx(14);
SetTimerEx(10,14,0,0);
if(boredtrack!=-1) { jkStopPOVKey(player, boredtrack, 0.1); boredtrack=-1; }
// Check Ammo - If we are out, autoselect best weapon.
if(mode!=1) {
if(GetInv(player, 11) < 1.0)
{
PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
Return;
}

SetPOVShake('0.0 -.003 0.0', '1.0 0.0 0.0', .05, 80.0);
dummy = FireProjectile(player, projectile, fireSound, 8, '0.0135 0.1624 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimFOV*2);
ChangeInv(player, 130, -1.0);
jkPlayPOVKey(player, povfireAnim, 1, 0x38);
ChangeFireRate(player, fireWait);
} else {
if(busy==1) return;
if(onegrenade==1) return;
busy=1;
onegrenade=1;
jkPlayPOVKey(player,povGren,1,0x38);
PlaySoundThing(grenadeR,player,1,-1,5,0xC0);
SetTimerEx(GetKeyLen(povGren)/3,15,0,0);
}

Return;

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

activated:
player = GetSourceRef();
mode = GetSenderRef();
jkSetWaggle(player, '0.0 0.0 0.0', 0);
ActivateWeapon( player, fireWait, mode );
Return;

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

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

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

selected:
player = GetSourceRef();
SetTimerEx(10,14,0,0);
oldammo=GetInv(player,11);
SetInv(player,11,GetInv(player,130));
// Setup the meshes and models.
jkSetPOVModel(player, povModel);
jkSetWeaponMesh(player, weaponMesh);
SetArmedMode(player, 1);
SetPulse(0.01);
// Play mounting sound.
PlayMode(player, 41);

// 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));
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
Return;

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

deselected:
player = GetSourceRef();
weaponIndex = GetSenderRef();
PlaySoundThing(mountSound, player, 1.0, -1.0, -1.0, 0x80);
KillTimerEx(14);
SetInv(player,11,oldammo);
PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
jkPlayPOVKey(player, dismountAnim, 0, 0x04);
if (trackID != -1)
{
jkStopPOVKey(player, trackID, 1);
trackID = -1;
}
SetPulse(0);
holsterWait = GetKeyLen(holsterAnim);
SetMountWait(player, holsterWait);
holsterTrack = PlayKey(player, holsterAnim, 1, 0x4);
SetTimerEx(holsterWait, 2, 0.0, 0.0);
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, 130) != 0.0)
{
ReturnEx(500.0);
}
else
{
ReturnEx(-1.0);
}
}
else
{
ReturnEx(-1.0);
}

Return;

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

timer:
if(GetSenderID()==15)
{
if(onegrenade==1)
{
If(GetInv(player,4)>0)
{
SetPOVShake('0.0 -.003 0.0', '1.0 0.0 0.0', .05, 80.0);
dummy = FireProjectile(player, projgren, grenadeF, 8, '0.0135 0.1624 0.0', '0 0 0', 5, 0x21, autoAimFOV, autoAimFOV*2);
ChangeInv(player, 4, -1.0);
printint(GetInv(player,4));
print("grenades left");
}
else
{
PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
print("EMPTY!");
}
onegrenade=0;
}
}
else if(GetSenderID()==2)
{
StopKey(player, holsterTrack, 0.0);
}
else if(GetSenderID()==14)
{
br=rand()*2;
print("bored!");
printint(br);
boredtrack=jkPlayPOVKey(player,povboredAnim0[br],1,0x38);
if(br==1)
{
call bored1;
}
else if(br==0)
{
call bored0;
}
KillTimerEx(14);
SetTimerEx(10-(rand()*8),14,0,0);
}
return;
pulse:
jkSetWaggle(player, '0.0 0.0 0.0', 0);
SetInv(player,11,GetInv(player,130));
return;
bored0:
print("I'm bored. Flip it!");
PlaySoundThing(boredsnd0,player,1,0,1,0x80);
sleep(GetKeyLen(povboredAnim0)/4);
PlaySoundThing(boredsnd0,player,1,0,1,0x80);
return;
bored1:
print("I'm bored. Swing it!");
PlaySoundThing(boredsnd2,player,1,0,1,0x80);
PlaySoundThing(boredsnd3,player,1,0,1,0x80);
sleep(GetKeyLen(povboredAnim1)/4);
PlaySoundThing(boredsnd2,player,1,0,1,0x80);
PlaySoundThing(boredsnd3,player,1,0,1,0x80);
return;
end

It is at the bottom. Or near there. Timer: SenderID 14, br value.
br=rand()*2; This should give me the numbers 0, 1, and possibly 2, no? The printint() says, 0... 0... 1... 0... 1... etc... OK! If(br==1), then... 'Noa, sorry. Doesa nota computa...' A' Bega Pardon?

You can see that if(br==1), then call the bored1 message. And yet, when the printint says that br=1, it does not call the message. Why not? And if you say that bored0/1 is not a valid message, then don't post and bug SM for a renewed Parsec. Sure, the messages are unknown 'cause they are custom. It worked a while ago when I didn't have if(br==0) and a copy of bored0 called bored2 (exact same contens). So, if Equel is not Equel to Equel, what is Equel Equel to if not Equel to Equel?
pardon my frustration

/Edward

LKOH_SniperWolf
06-10-2004, 11:49 AM
Well, I can explain the rand part, but not the calls.

rand generates through a particular formula (in case of JK, I believe it automatically seeds with "time"). The number generated is a "random" number from 0 to 1. In truth it's a decimal. Now, in converting from floats to ints, the number is simply trunctuated. So if it were something like 1.6789, it would become just 1. So the only way to get 2 would be if the random number were "1", which will basically never happen. So if you want 2 to be a number that you'll see, multiply by 3.

Solution:
Follow the following formula when using rand() for ints.

Basically it goes like this.

x = (rand() * a) + b;

a - total number of numbers generated. The
range if you will. If it's three, there
will be three possible numbers.
b - where you want the numbers to start
if it's 1, that'll be the first number.

So for a normal die, it'd be:
x = (rand() * 6) + 1;

After this you can modify it of course. If you wanted only odds, y = 2x - 1

More than needed to be said of course, but that's both the long and short of it.

------------------
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come

Edward
06-11-2004, 04:02 PM
OK, the rand is... A little complicated, but still... Why won't it call? If (br==1) then Why won't you call? If Equel to is not Equal to Equal to, then what is Equal to Equal to if not Equal to?

zagibu
06-11-2004, 04:15 PM
Try:


if(br < 1)
call bored0;
else if(br < 2)
call bored1;
...

If it still doesn't work, insert a print statement into each if block...
And if it prints, but doesn't call your function, then try to rename them to user0...

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

Edward
06-12-2004, 02:19 AM
OK, the weapon above worked fine when I tried if(br<1) and 2. But, I try the same thing on another weapon, and that doesn't work. I put in prints for the ifs and they print, but the messages don't come. I renamed them to user0 and user1, but still nothing...


# Jedi Knight Cog Script
#
# WEAP_STRIFLE.COG
#
# WEAPON 3 script - Stormtrooper Rifle
#
# The standard rifle used by the stormtroopers. Not as accurate as the Bryar Pistol.
# This weapon has only one type of fire.
#
# - Affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

model povModel=SmartV.3do local
model weaponMesh=SmartInHand.3do local

keyframe mountAnim=SmartUp.key local
keyframe dismountAnim=SmartDown.key local
keyframe povfireAnim=SmartFire.key local
keyframe holsterAnim=kyhlstr.key local

keyframe povboredAnim0=SmartV_bored1.key local
keyframe povboredAnim1=SmartV_bored2.key local
keyframe povboredAnim2=SmartV_bored1.key local

sound mountSound=invrotate.wav local
sound dismountSound=PutWeaponAway01.wav local
sound fireSound=Ed_smart_fire_1.wav local
sound outSound=trprout.wav local

template projectile=+stlaser local

thing player local

vector randVec local

flex fireWait=0.05 local
flex holsterWait local
flex powerBoost local
flex autoAimFOV=360 local
flex autoAimMaxDist=5 local

sound boredsnd0=swingfist02.wav local
sound boredsnd1=lgclick1.wav local

thing victim=-1 local
thing potential=-1 local
flex dot local
flex maxDot local
int type local
int retval=0 local
vector dir local
int IsAFlag=0 local
vector lv local
vector lvr local


int dummy local
int trackID=-1 local
int fireChannel=-1 local
int holsterTrack local
int mode local

int ch=1 local

int boredtrack=-1 local
flex oldammo local

int br local

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

end

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

code

fire:
player = GetSourceRef();
mode = GetSenderRef();

// Check that the player is still alive.
if(GetThingHealth(player) <= 0)
{
Return;
}
if(boredtrack!=-1) { jkStopPOVKey(player, boredtrack, 0.1); boredtrack=-1; }
KillTimerEx(14);
SetTimerEx(10,14,0,0);
// Check Ammo - If we are out, autoselect best weapon.
// It should always use two energy cells, but -- as in DF --
// allow the last fire if there is only one left...
if(GetInv(player, 131) < 1.0)
{
PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
Return;
}

// Get random aiming error
randVec = VectorSet((Rand()-0.5)*5, (Rand()-0.5)*5, 0.0);

SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
ch=PlaySoundThing(fireSound,player,1,-1,10,0xC0);
ChangeSoundPitch(ch,1.00+(rand()/10),.01);
if(mode==0) {
dummy = FireProjectile(player, projectile, -1, 8, '0.0168 0.1896 0.00', '0 0 0', 1.0, 0x10, 0, 0);
CaptureThing(dummy);
victim = -1;
maxDot = 0;
potential = FirstThingInView(player, 100, 5.5, 0x424);
while(potential != -1)
{
if(HasLOS(player, potential) && (potential != player) && (VectorDist(GetThingPos(player), GetThingPos(potential)) <= 100) && !(GetThingFlags(potential) & 0x200) && !((jkGetFlags(potential) & 0x20) && !IsInvActivated(player, 23)) && !(GetThingType(potential)==5))
{
dot = ThingViewDot(player, potential);
if(dot > maxDot)
{
victim = potential;
maxDot = dot;
}
}
potential = NextThingInView();
}
if(victim!=-1)
{
lv=VectorSub(GetThingPos(player),GetThingPos(victi m));
lvr=VectorSet(-VectorX(lv),-VectorY(lv),-VectorZ(lv));
SetThingLook(dummy,lvr);
SetThingVel(dummy,VectorSet(VectorX(lvr)*10,Vector Y(lvr)*10,VectorZ(lvr)*10));
jkSetTargetColors(43, 65, 36);
jkSetTarget(victim);
}
else
{
jkEndTarget();
}
} else {
dummy = FireProjectile(player, projectile, -1, 8, '0.0168 0.1896 0.00', '0 0 0', 1.0, 0x10, 0, 0);
}
// SetThingVel(dummy, vectorScale(GetThingVel(dummy), 0.01));

ChangeInv( player, 131, -1.0 );
jkPlayPOVKey( player, povfireAnim, 1, 0x38 );

powerBoost = GetInv(player, 63);
ChangeFireRate(player, fireWait/powerBoost);

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();
jkSetWaggle(player, '10.0 7.0 0.0', 350);
jkEndTarget();
DeactivateWeapon(player, mode);
Return;

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

selected:
player = GetSourceRef();
SetTimerEx(10,14,0,0);
oldammo=GetInv(player,11);
SetInv(player,11,GetInv(player,131));
PlayMode(player, 41);
SetPulse(0.01);
jkSetPOVModel(player, povModel);
SetArmedMode(player, 1);
jkSetWeaponMesh(player, weaponMesh);
jkSetWaggle(player, '10.0 7.0 0.0', 350);
trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
SetMountWait(player, GetKeyLen(mountAnim));
jkClearFlags(player, 0x5);
SetCurWeapon(player, 3);
PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
Return;

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

deselected:
SetInv(player,11,oldammo);
player = GetSourceRef();
PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80);
jkPlayPOVKey(player, dismountAnim, 0, 0x4);
killtimerex(14);
SetPulse(0);
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, 3) != 0.0)
{
// If the player has ammo
if(GetInv(player, 131) != 0.0)
{
ReturnEx(600.0);
}
else
{
ReturnEx(-1.0);
}
}
else
{
ReturnEx(-1.0);
}

Return;

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

timer:
if(GetSenderID()==2)
{
StopKey(player, holsterTrack, 0.0);
Return;
}
else if(GetSenderID()==14)
{
br=rand()*2;
printint(br);
boredtrack=jkPlayPOVKey(player, povboredAnim0[br], 1, 0x0a);
if(br<1)
{
print("callin0");
call bored0;
}
else if(br<2)
{
print("callin1");
call bored1;
}
KillTimerEx(14);
SetTimerEx(10,14,0,0);
}
return;
pulse:
jkSetWaggle(player, '0.0 0.0 0.0', 0);
SetInv(player,11,GetInv(player,131));
return;
bored0;
print("Swing!");
PlaySoundThing(boredsnd0,player,1,0,1,0x80);
return;
bored1;
print("Watsis!");
sleep(GetKeyLen(povboredAnim1)/8);
PlaySoundThing(boredsnd1,player,1,0,1,0x80);
sleep(GetKeyLen(povboredAnim1)/4);
PlaySoundThing(boredsnd1,player,1,0,1,0x80);
return;
end

If call is not equel to call, then waht is call equel to if not equel to call.

/Edward

zagibu
06-12-2004, 03:30 AM
You got semicolons after the message name where there should be doublepoints.

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

Edward
06-12-2004, 02:44 PM
GAAAAH!!! Thanks...

Hay! Just a small question to everyone. Does anyone know how to split the screen on JK? You know, like 2 people talking to each other over the phone and you see them both.

/Edward

LKOH_SniperWolf
06-13-2004, 01:12 PM
There isn't really a way. JK wasn't really meant for things like that. As far as I'm aware you can only have a single viewpoint for the camera. I guess you could create half-body models or something, and draw a room with one background to halfway, and a different one the rest of the way. So this trick might be able to emulate having two, but it's probably the best you could do.

------------------
_ _ _____________ _ _
Wolf Moon
Cast Your Spell On Me
Beware
The Woods At Night
The Wolf Has Come