Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsCog Forum → sniper rifle
sniper rifle
2004-01-11, 12:33 PM #1
Ok yea its a sniper rifle but with a catch. Because all the other gun slots are filled with other stuff i need for this sniper to replace sequencer charges. So can someone help me with this one. All I need is for the second fire to be a zoom scope first fire to shoot and in a user0 message to reload. user0 is because it reloads via a hotkey. I hope all this makes sense. The ammo max is 10 rounds.

------------------
Nightfire Mod
Spoting an error in post will result in a $100 reward.
Offer expires on 6/6/06. Valid one per customer, per day.

Rangi
2004-01-11, 1:40 PM #2
Here it is. It's been tested and seems to work correctly. It also has crosshair stuff in it. If you don't want a crosshair feature, just delete everything between the lines "#crosshair" and "#/crosshair" in the templates I provided you and the "pulse" and "symbols" sections of the cog.

Code:
# Jedi Knight Cog Script
# Written by Darth Slaw
# Reloading feature - Ben Allen
# Zoom feature - Heidiki
# Some parts of the zoom/crosshair modifications were inspired by Zagibu
#==============================================================#
symbols

model     povModel=bryv.3do                   local
model     weaponMesh=bowg.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=+bryarbolt               local
#crosshair
template  crosshair=+crosshair9               local
int       xhair                               local
#/crosshair
template  CameraTpl=+Zoom_Cam                 local

thing     player                              local

flex      fireWait=1.0                        local
flex      reloadWait=1.5                      local
flex      holsterWait                         local
flex      autoAimFOV=25                       local
flex      ZoomMag=0.15                        local

int       dummy                               local
int       trackID=-1                          local
int       holsterTrack                        local
int       mode                                local
int       reload=0                            local
int       ammomax=10                          local
int       curammo=10                          local
int       ammobin=8                           local
int       weap=8                              local
int       OldFocus                            local
int       Stay                                local
int       Zoom=1                              local
int       ZoomCount                           local

vector    ZoomFactor                          local

message   activated
message   deactivated
message   selected
message   deselected
message   autoselect
message   fire
message   timer
message   reloadclip
message   user0
message   pulse
message   stop_power
message   killed

end
#==============================================================#
code
#------------------------------------------------------
fire:
	player = GetSourceRef();
	mode = GetSenderRef();
	//-------------------------------------------------------------
	// Check to see if we can fire
	// Is player still alive?
	if(GetThingHealth(player) <= 0)
	{
		call stop_power;
		Return;
	}
	if(reload > 0)	// reloading?
	{
		call stop_power;
		Return;
	}
	if(GetInv(player, ammobin) < 1.0)	// out of ammo?
	{
		call stop_power;
		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
	{
		call stop_power;
		reload = 1;
		PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
		SetTimerEx(0.4, 2, 0.0, 0.0);
		Return;
	}
	else if(curammo > 0)	// fires the gun
	{
		SetFireWait(player, fireWait);
		SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
		FireProjectile(player, projectile, fireSound, 8, '0 0 0.037', '0 0 0', 1.0, 0x30, autoAimFOV, autoAimFOV * 2);
		ChangeInv(player, ammobin, -1.0);
		jkPlayPOVKey(player, povfireAnim, 1, 0x38);
		ChangeFireRate(player, fireWait);
		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;
	}

Return;
#------------------------------------------------------
activated:
	player = GetSourceRef();
	mode = GetSenderRef();
	if(mode == 0)
	{
		jkSetWaggle(player, '0.0 0.0 0.0', 0);
		ActivateWeapon(player, fireWait, mode);
	}
	else
	{
		if(Zoom)
		{
			OldFocus = GetCurrentCamera();
			ParseArg(player, "maxrotvel=20 maxrotthrust=20");
			SetPulse(0.01);
		}
		else call stop_power;
		Stay = 0;
		ZoomCount = 0;
	}
	

Return;
#------------------------------------------------------
deactivated:
	player = GetSourceRef();
	mode = GetSenderRef();
	if(mode == 0)
	{
		jkSetWaggle(player, '10.0 7.0 0.0', 350);
		DeactivateWeapon(player, mode);
	}
	else
	{
		Zoom = 1 - Zoom;
		Stay = 1;
	}

Return;
#------------------------------------------------------
selected:
	player = GetSourceRef();
	//print("Sniper Rifle selected");
	jkPrintUNIString(player, weap);
	call stop_power;
	// 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);
	call stop_power;
	Zoom = 1;

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) + reloadWait));
		PlaySoundThing(reloadSound, player, 1.0, -1, -1, 0x80);
		jkPlayPOVKey(player, reloadAnim, 1, 0x38);
		PlayKey(player, reloadgun, 2, 32);
		curammo = ammomax;
		SetPulse(0);
		ParseArg(player, "maxrotvel=200 maxrotthrust=180");
		SetCameraFocus(0, player);
		ZoomMag = 0.15;
		if((OldFocus == 1) && (GetCurrentCamera() != 1)) CycleCamera();
	}

Return;
#------------------------------------------------------
killed:

	call stop_power;
	curammo = ammomax;

Return;
#------------------------------------------------------
reloadclip:

	call stop_power;
	SetFireWait(player, (GetKeyLen(reloadAnim) + reloadWait));
	PlaySoundThing(reloadSound, player, 1.0, -1, -1, 0x80);
	jkPlayPOVKey(player, reloadAnim, 1, 0x38);
	PlayKey(player, reloadgun, 2, 32);
	curammo = ammomax;
	reload = 0;

Return;
#------------------------------------------------------
stop_power:
	SetPulse(0);
	ParseArg(player, "maxrotvel=200 maxrotthrust=180");
	SetCameraFocus(0, player);
	ZoomMag = 0.15;
	if((OldFocus == 1) && (GetCurrentCamera() != 1)) CycleCamera();

Return;
#------------------------------------------------------
pulse:
	if(!Stay)
	{
		if(Zoom)
		{
			ZoomMag = ZoomMag + ZoomCount * 0.005;
			if(ZoomMag > 12) ZoomMag = 12;	// maximum zoom
		}
		else
		{
			SetPulse(0);
			ParseArg(player, "maxrotvel=200 maxrotthrust=180");
			SetCameraFocus(0, player);
			ZoomMag = 0.15;
			if((OldFocus == 1) && (GetCurrentCamera() != 1)) CycleCamera();
			Return;
		}
		ZoomFactor = VectorSet(0, ZoomMag, 0.037);
		ZoomCount = ZoomCount + 1;
	}
	if((ZoomMag == 0.15) && !Zoom)
	{
		call stop_power;
		Return;
	}
	dummy = FireProjectile(player, CameraTpl, -1, -1, ZoomFactor, '0 0 0', 0, 0, 0, 0);
	SetThingPos(dummy, VectorAdd(GetThingPos(dummy), VectorScale(VectorNorm(GetThingLVec(dummy)), -0.1)));	
	#crosshair
	xhair = FireProjectile(player, crosshair, -1, -1, ZoomFactor, '0 0 0', 0, 0, 0, 0);
	SetThingPos(xhair, VectorAdd(GetThingPos(dummy), VectorScale(VectorNorm(GetThingLVec(dummy)), 0.1)));
	#/crosshair
	SetCameraFocus(0, dummy);
	if(GetCurrentCamera() == 1) CycleCamera();         		// no external view

Return;
#------------------------------------------------------
user0:

	if(curammo >= ammomax)						// full clip
	{
		Print("The clip is full.");
		PlaySoundLocal(beep, 1.0, 0, 0x0);
		curammo = ammomax;
		reload = 0;
	}
	else if(curammo < ammomax && GetInv(player, ammobin) > 0.0)	// reload the gun
	{
		call stop_power;
		call reloadclip;
	}

Return;
#------------------------------------------------------
end


You will also need these templates in your static.jkl file
Code:
_weaponn	none		orient=(0/0/0) type=weapon collide=1 move=physics thingflags=0x20000000 mass=5 physflags=0x200 maxrotvel=90 damageclass=0x2 typeflags=0x1
+Zoom_Cam	_weaponn	size=0.001 movesize=0.001 maxvel=0 vel=(0/0/0) timer=0.01 thingflags=0 damageclass=0 typeflags=0xd
#crosshair
_crosshair      none            orient=(0/0/0) type=weapon collide=1 move=physics mass=0 physflags=0x200 maxrotvel=90 typeflags=0x1 size=0.001 movesize=0.001 maxvel=0 vel=(0/0/0) timer=0.01 thingflags=0 damageclass=0
+crosshair9     _crosshair      sprite=crosshair9.spr
#/crosshair


If you need any further help on this topic, don't hesitate to ask. [http://forums.massassi.net/html/biggrin.gif]

[This message has been edited by Darth Slaw (edited January 11, 2004).]
May the mass times acceleration be with you.
2004-01-11, 4:05 PM #3
What's with that whole template thing?

Just set physics flags 0x1000 to limit turning, force first person, and change the zoom using a local parsearg that changes the camera distance.

------------------
Duel Zero : Released the beta. Probably the end of it. Not to worry though, I'm working on Randsaber, which is a lot better.
2004-01-11, 9:06 PM #4
Wow Checksum, I didn't know it could be that easy. I've always used the template thing too.

------------------
-There are easier things in life than finding a good woman, like nailing Jello to a tree, for instance

-Tazz
-There are easier things in life than finding a good woman, like nailing Jello to a tree, for instance

Tazz
2004-01-11, 9:23 PM #5
Yeah, I guess these things just come from experience.

------------------
Duel Zero : Released the beta. Probably the end of it. Not to worry though, I'm working on Randsaber, which is a lot better.
2004-01-12, 10:05 AM #6
I use this one now because I don't have to set like 50 zoom levels for the weapons that don't zoom to a single magnification. You can zoom to the nearest 0.005 with this method (when you release the button, it'll stop zooming where you are).
It's just a matter of preference. I always use this method; I like it better.

Besides, I'd assume that he's making some sort of new projectile for a sniper rifle like a bullet, so it would make no difference if there were templates or not for the zoom. I can't imagine shooting bryar bolts out of an 800m range sniper rifle!
There's a good chance that this is involved in that Nightfire TC that's under development, too.

[This message has been edited by Darth Slaw (edited January 12, 2004).]
May the mass times acceleration be with you.

↑ Up to the top!