Anyone seen Eraser? Like that cool scope on that EMP gun? Well I've been trying to recreate something like that. Zooming throu walls. But I got this great idea, instead of the old fasion way of FireProjectile with offset vector. Do some math and calculate the pos of the scope and move it there. Good in theory, no? SetThingPos shouldn't change the sector and delete the thing, no? Well, here's what I have so far. See if you can help me.
------------------
The Sniper Missions. Current project, The Sniper Missions
The Magician Saber System.
The 2 riddle!
[This message has been edited by SaberMaster (edited July 27, 2003).]
Code:
# Jedi Knight Cog Script # # WEAP_CONCRIFLE.COG # # WEAPON 9 Script - Sniper Rifle # # Sniper Rifle # # - Not affected by MagSealed sectors/surfaces. # # [DP] # symbols model povModel=conv.3do local model weaponMesh=cong.3do local keyframe mountAnim=ConVmnt.key local keyframe dismountAnim=ConVdis.key local keyframe povfireAnim=ConVpst1.key local keyframe holsterAnim=kyhlstr.key local sound mountSound=df_rif_ready.wav local sound dismountSound=PutWeaponAway01.wav local sound fireSound=srfire.wav local sound outSound=concuss1.wav local sound zoomSound=scope.wav local flex fireWait=1.5 local flex powerBoost local flex autoAimFOV=30 local flex autoAimMaxDist=5 local flex holsterWait local int dummy local template projectile=+sniperbullet local template camera=+zoom local thing player local int trackID=-1 local int mode local int holsterTrack local int selectMode=1 local flex mag=0.25 local flex zoom=0 local flex temp local int reloading=0 local int moving=0 local int count=0 local int scope=-1 local int oldCam local int on=0 local int zoomChannel=-1 local int justOn local vector tempVec local vector zoomVec local message activated message deactivated message selected message deselected message autoselect message user1 message timer message pulse end # ======================================================================================== code User1: If(reloading) Return; // Check that the player is still alive. If(GetThingHealth(player) <= 0) Return; // Check Ammo - If we are out, autoselect best weapon. If(GetInv(player, 12) < 1) { PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80); if(GetAutoSwitch() & 1) SelectWeapon(player, AutoSelectWeapon(player, 1)); Return; } SetPOVShake('0 -.03 0', '4 0 0', .05, 80); //FireProjectile(player, projectile, fireSound, 8, '0.02 0.15 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimMaxDist); FireProjectile(player, projectile, fireSound, 8, '0 0 0.037', '0 0 0', 1, 0x0, 0, 0); ChangeInv(player, 12, -1); reloading = 1; jkPlayPOVKey(player, povfireAnim, 1, 0x38); powerBoost = GetInv(player, 63); SetTimerEx(fireWait/powerBoost, 1, 0, 0); Return; # ........................................................................................ Activated: player = GetSourceRef(); mode = GetSenderRef(); If(!on) { oldCam = GetCurrentCamera(); If(mode == 1) mag = 5; justOn = 1; } Else justOn = 0; jkSetWaggle(player, '0 0 0', 0); zoomChannel = PlaySoundLocal(zoomSound, 1, 0, 0x1); count = 0; moving = 1; on = 1; zoom = .5 - mode; SetPulse(0.01); Return; # ........................................................................................ Deactivated: player = GetSourceRef(); mode = GetSenderRef(); jkSetWaggle(player, '10 7 0', 350); moving = 0; If(zoomChannel != -1) { StopSound(zoomChannel, 0); zoomChannel = -1; } If(count <= 3) // If the zoom keys are tapped { If(mode == 1) { If(justOn) mag = 5; Else If(mag < 5) call scope_off; Else mag = 2.5; } Else { If(mag < 2.5) mag = 2.5; Else If(mag < 5) mag = 5; Else call scope_off; } } Return; # ........................................................................................ Selected: player = GetSourceRef(); // Play external mounting animation PlayMode(player, 41); // Setup the meshes and models. jkSetPOVModel(player, povModel); SetArmedMode(player, 1); jkSetWeaponMesh(player, weaponMesh); jkSetWaggle(player, '10.0 7.0 0.0', 350); // Play mounting sound. 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, 20); SetMountWait(player, GetKeyLen(mountAnim)); // Clear saber flags, and allow activation of the weapon jkClearFlags(player, 0x5); SetCurWeapon(player, 9); // Check Ammo - If we are out, autoselect best weapon. If(GetInv(player, 12) < 2) { PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80); if(GetAutoSwitch() & 1) SelectWeapon(player, AutoSelectWeapon(player, 1)); } mag = 0.25; If(reloading) SetTimerEx(fireWait/powerBoost, 1, 0, 0); Return; # ........................................................................................ Deselected: player = GetSourceRef(); If(on) call scope_off; If(reloading) KillTimerEx(1); PlaySoundThing(dismountSound, player, 1.0, -1, -1, 0x80); jkPlayPOVKey(player, dismountAnim, 0, 18); 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; # ........................................................................................ //newplayer: // player = GetSourceRef(); // // // Make sure that if the player is respawning, the old mount isn't playing anymore. // if (trackID != -1) // jkStopPOVKey(player, trackID, 0); // // Return; # ........................................................................................ Autoselect: selectMode = GetSenderRef(); player = GetSourceRef(); // If the player has the weapon if(GetInv(player, 9) != 0.0) { // If the player has ammo if(GetInv(player, 12) > 7.0) { // query for ammo if(selectMode == -1) { ReturnEx(1000.0); Return; } if((selectMode == 0) && !(GetAutoPickup() & 2)) { ReturnEx(1000.0); Return; } if((selectMode == 1) && !(GetAutoSwitch() & 2)) { ReturnEx(1000.0); Return; } if((selectMode == 2) && !(GetAutoPickup() & 2)) { ReturnEx(1000.0); Return; } ReturnEx(-2.0); Return; } else { ReturnEx(-1.0); } } else { ReturnEx(-1.0); } Return; # ........................................................................................ Timer: If(GetSenderID() == 1) { reloading = 0; Return; } StopKey(player, holsterTrack, 0.0); Return; # ........................................................................................ Scope_off: If(zoomChannel != -1) { StopSound(zoomChannel, 0); zoomChannel = -1; } SetPulse(0); mag = 0.25; on = 0; SetCameraFocus(0, player); If(oldCam) CycleCamera(); Return; #......................................................................................... Pulse: If(GetThingHealth(player) <= 0) { call scope_off; Return; } If(GetCurrentCamera()) CycleCamera(); If(moving) { mag = mag + zoom * count * 0.005; If(mag > 5) mag = 5; If(mag < .25) mag = .25; count = count + 1; } If(mag == 5 && zoom > 0) { StopSound(zoomChannel, 0); zoomChannel = -1; } If(mag <= 0.25 && zoom < 0) { call scope_off; Return; } scope = FireProjectile(player, camera, -1, -1, '0 0 0.037', '0 0 0', 1, 0, 0, 0); tempVec = VectorAdd(GetThingPos(scope), VectorScale(VectorNorm(GetThingLVec(scope)), mag)); SetThingPos(scope, tempVec); SetCameraFocus(0, scope); Return; end
Code:
My math is right, but for some reason the scope, whenever it enters another sector, goes to HOM. Ideas or more explanation?The template +zoom _weapon size=0.001 movesize=0.001 vel=(0/0/0) timer=0.015 thingflags=0x0 damageclass=0x0 typeflags=0x0 collide=0
------------------
The Sniper Missions. Current project, The Sniper Missions
The Magician Saber System.
The 2 riddle!
[This message has been edited by SaberMaster (edited July 27, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack
SATNRT, JK Pistol Mod, Aliens TC, Firearms
Completed
Judgement Day (HLP), My level pack