I'm working on a cam-guided missile (for the Nightfire TC), and I've got what I've done working so far, but I have a SERIOUS problem. When the rocket collides with a wall, JK crashes. I think it has something to do with setting the camera, but I can't figure it out. Here's the cog.
And here are the templates that are needed. Most are for the rocket explosions. (Don't worry about the cogs/models for the rocket; that part is not important at the moment)
[changed the templates to a quote to prevent scrollage...]
------------------
I am Darth Slaw.
The Dark Lord of the Sith,
And part of the Nightfire mod team
[This message has been edited by GBK (edited January 16, 2004).]
Code:
# Jedi Knight Cog Script # # WEAP_SENTINEL.COG # # WEAPON 7 script - Sentinel # - Rocket Launcher # - 4 rockets per reload # - Powerful # - Secondary Fire - Cam-Guided Missiles # # Source: M-16 Assault Rifle cog from the James Bond 007 mod (found on massassi.net) # made by Ben Allen # Modified by Darth Slaw # # (C) 2004 JK Mod: Nightfire TC #==============================================================# symbols model povModel=rldv.3do local model weaponMesh=strg.3do local keyframe mountAnim=strvmnt.key local keyframe dismountAnim=bryvdis.key local keyframe povfireAnim=bryvpst1.key local keyframe reloadAnim=kyhlstr.key local keyframe reloadgun=kyhlstr.key local keyframe holsterAnim=kyhlstr.key local sound mountSound=df_bry_ready.wav local sound reloadSound=df_bry_ready.wav local sound dismountSound=PutWeaponAway01.wav local sound fireSound=pistol-1.wav local sound outSound=pistout1.wav local sound beep=beep2.wav local template projectile=+rocket local template CameraTpl=+Zoom_Cam local thing player local flex fireWait=1.0 local flex holsterWait local flex autoAimFOV=25 local int trackID=-1 local int holsterTrack local int mode local int reload=0 local int ammomax=4 local int curammo=4 local int ammobin=15 local int weap=7 local int guideon=0 local int rocket local int OldFocus local int Dummy local int cam local vector look local message activated message deactivated message selected message deselected message autoselect message fire message timer message reloadclip message killed message pulse message user0 message stop_rocket end #==============================================================# code #------------------------------------------------------ fire: player = GetSourceRef(); mode = GetSenderRef(); //------------------------------------------------------------- // Check to see if we can fire // Is player still alive? if(GetThingHealth(player) <= 0) { Return; } if(reload > 0) // reloading? { Return; } if(GetInv(player, ammobin) < 1.0) // out of ammo? { curammo = 0; PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80); if((GetAutoSwitch() & 1)) SelectWeapon(player, AutoselectWeapon(player, 1)); Return; } //---------------------------------------------------------- if(curammo <= 0 && GetInv(player, ammobin) > 0.0) // clip is empty { reload = 1; PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80); SetTimerEx(0.4, 2, 0.0, 0.0); Return; } if(guideon == 1) { call stop_rocket; return; } if(mode == 0) // fire 1 { SetFireWait(player, fireWait); SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0); FireProjectile(player, projectile, fireSound, 8, '0.0168 0.1896 0.03', '0 0 0', 1.0, 0x30, autoAimFOV, autoAimFOV * 2); ChangeInv(player, ammobin, -1.0); jkPlayPOVKey(player, povfireAnim, 1, 0x38); curammo = curammo - 1; if(curammo <= 0 && GetInv(player, ammobin) > 0.0) // time to reload? - reload { reload = 1; PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80); SetTimerEx(0.4, 2, 0.0, 0.0); } Return; } //------------------------------------------------------- else // fire 2 { SetFireWait(player, fireWait); SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0); rocket = FireProjectile(player, projectile, fireSound, 8, '0.0168 0.1896 0.03', '0 0 0', 1.0, 0x30, autoAimFOV, autoAimFOV* 2); ChangeInv(player, ammobin, -1.0); jkPlayPOVKey(player, povfireAnim, 1, 0x38); curammo = curammo - 1; OldFocus = GetCurrentCamera(); guideon = 1; setpulse(0.01); Return; } //------------------------------------------------------- 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(); jkSetWaggle(player, '10.0 7.0 0.0', 350); DeactivateWeapon(player, mode); Return; #------------------------------------------------------ selected: player = GetSourceRef(); //print("MAC 10 selected"); jkPrintUNIString(player, weap); // 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, weap); SetMountWait(player, GetKeyLen(mountAnim)); Return; #------------------------------------------------------ deselected: player = GetSourceRef(); 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, weap) != 0.0) { // If the player has ammo if(GetInv(player, ammobin) != 0.0) { ReturnEx(500.0); } else { ReturnEx(-1.0); } } else { ReturnEx(-1.0); } Return; #------------------------------------------------------ timer: StopKey(player, holsterTrack, 0.0); if(reload == 1 && GetInv(player, ammobin) > 0) { reload = 0; SetFireWait(player, (GetKeyLen(reloadAnim) + 0.7)); PlaySoundThing(reloadSound, player, 1.0, -1, -1, 0x80); jkPlayPOVKey(player, reloadAnim, 1, 0x38); PlayKey(GetLocalPlayerThing(), reloadgun, 2, 32); if(GetInv(player, ammobin) < ammomax) curammo = GetInv(player, ammobin); else curammo = ammomax; } Return; #------------------------------------------------------ killed: player = GetLocalPlayerThing(); if(GetSenderRef() != player) Return; curammo = ammomax; Return; #------------------------------------------------------ reloadclip: SetFireWait(player, (GetKeyLen(reloadAnim) + 0.7)); PlaySoundThing(reloadSound, player, 1.0, -1, -1, 0x80); jkPlayPOVKey(player, reloadAnim, 1, 0x38); PlayKey(GetLocalPlayerThing(), reloadgun, 2, 32); if(GetInv(player, ammobin) < ammomax) curammo = GetInv(player, ammobin); else curammo = ammomax; reload = 0; Return; #------------------------------------------------------ stop_rocket: if(GetThingHealth(rocket) > 0) DestroyThing(rocket); guideon = 0; SetPulse(0); SetCameraFocus(0, player); if((OldFocus == 1) && (GetCurrentCamera() != 1)) CycleCamera(); Return; #------------------------------------------------------ pulse: if(getthinghealth(rocket) == 0) { call stop_rocket; return; } StopThing(player); Dummy = FireProjectile(player, CameraTpl, -1, -1, '0 0 0', '0 0 0', 0, 0, 0, 0); look = GetThingLVec(Dummy); SetThingLook(rocket, look); SetThingVel(rocket, VectorScale(VectorNorm(look), 4)); if(getthinghealth(rocket) != 0) { cam = FireProjectile(rocket, CameraTpl, -1, -1, '0 0.042 0', '0 0 0', 0, 0, 0, 0); SetCameraFocus(0, cam); } else { call stop_rocket; return; } Return; #------------------------------------------------------ user0: if(curammo >= ammomax) // fire 2 with full clip { Print("The clip is full."); PlaySoundLocal(beep, 1.0, 0, 0x0); if(GetInv(player, ammobin) < ammomax) curammo = GetInv(player, ammobin); else curammo = ammomax; reload = 0; SetFireWait(player, 0.3); } else if(curammo < ammomax && GetInv(player, ammobin) > 0.0) // reload the gun - reload { call reloadclip; } Return; #------------------------------------------------------ end
And here are the templates that are needed. Most are for the rocket explosions. (Don't worry about the cogs/models for the rocket; that part is not important at the moment)
Quote:
<font face="Verdana, Arial" size="2">_explosionn none orient=(0/0/0) type=explosion typeflags=0x1 damageclass=0x4
+lgflashh _explosionn thingflags=0x1 light=0.300000 timer=0.400000 typeflags=0x12 blasttime=0.200000 maxlight=1.000000
_weaponn none orient=(0/0/0) type=weapon collide=1 move=physics thingflags=0x20000000 mass=5 physflags=0x200 maxrotvel=90 damageclass=0x2 typeflags=0x1
+whitecloudd none orient=(0/0/0) type=particle timer=0.2 typeflags=0x3f material=00gsmoke.mat range=0.02 rate=128 maxthrust=30 elementsize=0.007 count=128
+dustcloudd +whitecloudd timer=0.12 material=dusty.mat range=0.015 rate=256 maxthrust=80 elementsize=0.01
+firecloudd +dustcloudd material=00explosion.mat range=0.050000 rate=64.000000 maxthrust=40.000000 count=64
+firecloudd3 +firecloudd maxthrust=20.000000 count=32
+firecloudd2 +firecloudd elementsize=0.012500
+debris_expp _explosionn timer=1.000000 sprite=debrisx.spr soundclass=exp_small.snd creatething=+firecloudd3 typeflags=0x7 blasttime=0.500000
_debriss none orient=(0/0/0) type=weapon collide=1 move=physics timer=1.1 airdrag=3.000000 physflags=0x201 vel=(0/4/0) angvel=(5/10/0) explode=+debris_expp damage=5 damageclass=0x1 typeflags=0xc
shrapnell_4 _debriss model3d=shrp_4.3do size=0.026000 movesize=0.026
shrapnell_3 _debriss model3d=shrp_3.3do size=0.028000 movesize=0.028
shrapnell_2 _debriss model3d=shrp_2.3do size=0.040000 movesize=0.04
shrapnell_1 _debriss model3d=shrp_1.3do size=0.045000 movesize=0.045
+rocket_exp _explosionn thingflags=0x1 light=0.2 timer=0.5 sprite=rldx.spr soundclass=exp_raildet.snd typeflags=0x17 damage=110 blasttime=0.7 force=300 maxlight=0.8 range=0.5 debris=shrapnell_1 debris=shrapnell_2 debris=shrapnell_3 debris=shrapnell_4
+rocket _weaponn thingflags=0x20000401 vel=(0/4/0) angvel=(0/0/90) size=0.003 movesize=0.003 typeflags=0x24020d timer=10 airdrag=0 height=0.003 physflags=0x200 explode=+rocket_exp fleshhit=+rocket_exp creatething=+lgflashh cog=class_rocket.cog model3d=rocket0.3do damage=50
+rocket2 +rocket thingflags=0x20000401 typeflags=0x24030c
+Zoom_Cam _weaponn size=0.001 movesize=0.001 maxvel=0 vel=(0/0/0) timer=0.01 thingflags=0 damageclass=0 typeflags=0xd
</font>
+lgflashh _explosionn thingflags=0x1 light=0.300000 timer=0.400000 typeflags=0x12 blasttime=0.200000 maxlight=1.000000
_weaponn none orient=(0/0/0) type=weapon collide=1 move=physics thingflags=0x20000000 mass=5 physflags=0x200 maxrotvel=90 damageclass=0x2 typeflags=0x1
+whitecloudd none orient=(0/0/0) type=particle timer=0.2 typeflags=0x3f material=00gsmoke.mat range=0.02 rate=128 maxthrust=30 elementsize=0.007 count=128
+dustcloudd +whitecloudd timer=0.12 material=dusty.mat range=0.015 rate=256 maxthrust=80 elementsize=0.01
+firecloudd +dustcloudd material=00explosion.mat range=0.050000 rate=64.000000 maxthrust=40.000000 count=64
+firecloudd3 +firecloudd maxthrust=20.000000 count=32
+firecloudd2 +firecloudd elementsize=0.012500
+debris_expp _explosionn timer=1.000000 sprite=debrisx.spr soundclass=exp_small.snd creatething=+firecloudd3 typeflags=0x7 blasttime=0.500000
_debriss none orient=(0/0/0) type=weapon collide=1 move=physics timer=1.1 airdrag=3.000000 physflags=0x201 vel=(0/4/0) angvel=(5/10/0) explode=+debris_expp damage=5 damageclass=0x1 typeflags=0xc
shrapnell_4 _debriss model3d=shrp_4.3do size=0.026000 movesize=0.026
shrapnell_3 _debriss model3d=shrp_3.3do size=0.028000 movesize=0.028
shrapnell_2 _debriss model3d=shrp_2.3do size=0.040000 movesize=0.04
shrapnell_1 _debriss model3d=shrp_1.3do size=0.045000 movesize=0.045
+rocket_exp _explosionn thingflags=0x1 light=0.2 timer=0.5 sprite=rldx.spr soundclass=exp_raildet.snd typeflags=0x17 damage=110 blasttime=0.7 force=300 maxlight=0.8 range=0.5 debris=shrapnell_1 debris=shrapnell_2 debris=shrapnell_3 debris=shrapnell_4
+rocket _weaponn thingflags=0x20000401 vel=(0/4/0) angvel=(0/0/90) size=0.003 movesize=0.003 typeflags=0x24020d timer=10 airdrag=0 height=0.003 physflags=0x200 explode=+rocket_exp fleshhit=+rocket_exp creatething=+lgflashh cog=class_rocket.cog model3d=rocket0.3do damage=50
+rocket2 +rocket thingflags=0x20000401 typeflags=0x24030c
+Zoom_Cam _weaponn size=0.001 movesize=0.001 maxvel=0 vel=(0/0/0) timer=0.01 thingflags=0 damageclass=0 typeflags=0xd
</font>
[changed the templates to a quote to prevent scrollage...]
------------------
I am Darth Slaw.
The Dark Lord of the Sith,
And part of the Nightfire mod team
[This message has been edited by GBK (edited January 16, 2004).]
May the mass times acceleration be with you.