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 → Weapon clips? Money?
Weapon clips? Money?
2004-10-14, 2:31 PM #1
...There might have already been something posted on this, but I cannot seem to find any tutorials on it. I know that Cogs can make use of separate, global level variables, but I was also wondering how it could be applied to weapons, to give them a clip that had to be reloaded after x# of shots. Also, is it possible to add anything to the HUD, so that the player would actually have a running display of how much was left in the clip? Of course, this could also be used for other things, such as an actualy display of cash on hand (relying on messages from transactions was an annoying part of LoaM).
Wake up, George Lucas... The Matrix has you...
2004-10-14, 4:09 PM #2
Excellent question, does anyone have any answers?
"Nulla tenaci invia est via"
2004-10-14, 4:49 PM #3
Yeah, I have (variations of) both of those things.
* reloading cog
* clip amount

because this uses the forcemana bin for ammo display, you will need to remove the cog attached to that bin (16) in items.dat for the ammo display to work correctly (otherwise JK will reset it).

I just rewrote this thing now, partly because I wanted to for fun but it turns out I can't find the original version I had.
kudos to Ben Allen for the reload code I based this off of. Also to Ruthven, whose stargate p90 cog showed me how I can properly use sleeps in a weapon cog. :)

Code:
# Jedi Knight Cog Script
#
# WEAP_BRYAR.COG
#
# WEAPON 2 Script - Bryar Pistol
# - Pistol
# - 20 Shots per reload
# - Moderate Damage
# - Primary Fire: Energy bolt
# - Secondary Fire: Reload
#
# 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, and
# requires a reload of the clip every 20 shots.
#
# - Affected by MagSealed sectors/surfaces.
#
# [darthslaw]
#
# Thanks to Ben Allen for the original reloading code.
#
# This Cog is Not supported by LucasArts Entertainment Co
# =======================================================================
symbols

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

keyframe  mountAnim=bryvmnt.key               local
keyframe  dismountAnim=bryvdis.key            local
keyframe  povfireAnim=bryvpst1.key            local
keyframe  holsterAnim=kyhlstr.key             local
keyframe  povReloadAnim=bryvmnt.key           local
keyframe  extReloadAnim=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
sound     reloadsound=df_bry_ready.wav        local
sound     beep=beep2.wav                      local

template  projectile=+bryarbolt               local

thing     player                              local

flex      fireWait=0.5                        local
flex      holsterWait                         local
flex      powerBoost                          local
flex      autoAimFOV=30                       local
flex      reloadwait                          local
flex      priority=500.0                      local

int       trackID=-1                          local
int       mode                                local
int       holsterTrack                        local
int       clip=20                             local
int       clipmax=20                          local
int       cliptofill                          local
int       reloading=0                         local
int       ammobin=11                          local
int       weap=2                              local

message   startup
message   activated
message   deactivated
message   selected
message   deselected
message   autoselect
message   fire
message   timer
message   killed

end
# =======================================================================
code
# .......................................................................
startup:
	holsterWait = GetKeyLen(holsterAnim);
	reloadwait = GetKeyLen(povReloadAnim);

Return;
# .......................................................................
fire:
	player = GetSourceRef();
	# Set HUD to show bullets in force mana display
	SetInv(player, 14, 400 * clip / clipmax);
	// Check that the player is still alive.
	if(GetThingHealth(player) <= 0)
	{
		Return;
	}
	if(reloading) Return;
	if(mode == 0)
	{
		// Check Ammo - If we are out, autoselect best weapon.
		if(GetInv(player, ammobin) < 1.0)
		{
			PlaySoundThing(outSound, player, 1.0, -1.0, -1.0, 0x80);
			if(GetAutoSwitch() & 1) SelectWeapon(player, AutoselectWeapon(player, 1));
			Return;
		}
		if(clip <= 0)
		{
			call reload_nodelay;
			Return;
		}
		SetPOVShake('0.0 -.003 0.0', '1.0 0.0 0.0', .05, 80.0);
		FireProjectile(player, projectile, fireSound, 8, '0.0135 0.1624 0.0', '0 0 0', 1.0, 0x20, autoAimFOV, autoAimFOV * 2);
		jkPlayPOVKey(player, povfireAnim, 1, 0x38);
		clip = clip - 1;
		if(clip <= 0)
		{
			call reload;
			Return;
		}
		powerBoost = GetInv(player, 63);
		SetFireWait(player, fireWait / powerBoost);
	}

Return;
# .......................................................................
reload_nodelay:
	//clip is full
	if(clip >= clipmax)
	{
		clip = clipmax;
		PlaySoundLocal(beep, 1.0, 0.0, 0x0);
		Print("Clip is fully charged.");
		Return;
	}
	//no shots left in inv
	if(GetInv(player, ammobin) <= 0) Return;
	//already reloading
	if(reloading) Return;
	reloading = 1;
	call reloadfx;

Return;
# .......................................................................
reload:
	//clip is full
	if(clip >= clipmax) Return;
	//no more shots left in inv
	if(GetInv(player, ammobin) <= 0) Return;
	//already reloading
	if(reloading) Return;
	reloading = 1;
	Sleep(0.4);
	reloadfx:
	jkSetWaggle(player, '0.0 0.0 0.0', 0);
	PlaySoundThing(reloadsound, player, 1.0, -1.0, -1.0, 0x80);
	PlayKey(player, extReloadAnim, 1, 0x0);
	jkPlayPOVKey(player, extReloadAnim, 0, 0x12);
	SetFireWait(player, reloadwait + 0.3);
	Sleep(reloadwait);
	cliptofill = clipmax - clip;
	if(GetInv(player, ammobin) >= cliptofill)	//inv can give a full clip
		clip = clipmax;
	else						//inv can't fill clip
		clip = clip + GetInv(player, ammobin);
	ChangeInv(player, ammobin, -cliptofill);
	# Set HUD to show bullets in force mana display
	SetInv(player, 14, 400 * clip / clipmax);
	reloading = 0;
	jkSetWaggle(player, '10.0 7.0 0.0', 350);

Return;
# .......................................................................
activated:
	player = GetSourceRef();
	mode = GetSenderRef();
	jkSetWaggle(player, '0.0 0.0 0.0', 0);
	if(mode == 0)
	{
		powerBoost = GetInv(player, 63);
		ActivateWeapon(player, fireWait / powerBoost, mode);
	}
	else
	{
		call reload_nodelay;
	}

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

Return;
# .......................................................................
selected:
	player = GetSourceRef();
	// 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);
	# Set HUD to show bullets in force mana display
	SetInv(player, 14, 400 * clip / clipmax);
	// 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);
	if(clip <= 0) SetTimerEx(GetKeyLen(mountAnim), 1, 0, 0);
	// 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, 0x10);
	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(priority);
		}
		else
		{
			ReturnEx(-1.0);
		}
	}
	else
	{
		ReturnEx(-1.0);
	}

Return;
# .......................................................................
timer:
	if(GetSenderID() == 1) call reload_nodelay;
	if(GetSenderID() == 2) StopKey(player, holsterTrack, 0.0);

Return;
# .......................................................................
killed:
	clip = clipmax;
	reloading = 0;

Return;
# .......................................................................
end
May the mass times acceleration be with you.
2004-10-14, 5:32 PM #4
Quote:
Originally posted by nottheking
(relying on messages from transactions was an annoying part of LoaM).


:(
the idiot is the person who follows the idiot and your not following me your insulting me your following the path of a idiot so that makes you the idiot - LC Tusken
2004-10-14, 6:13 PM #5
You could have made an item that interfaced with the bank and told you how much money you had on hand. :/
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2004-10-14, 6:33 PM #6
I FINALLY played LoaM tuesday night (just didn't get around to it before, kinda like how I didn't play Rangi until yesterday).
That was fun (though sometimes kinda confusing -- I get lost easily and sometimes don't see obvious paths). I look forward to the sequel :)

----------------------

btw, if you somehow overlooked it, I added the cog into my other post.
May the mass times acceleration be with you.
2004-10-15, 12:29 AM #7
To display custom hud items you have to work with flat 3dos.
"Häb Pfrässe, süsch chlepfts!" - The coolest language in the world (besides Cherokee)
2004-10-15, 7:08 AM #8
Quote:
Originally posted by Darth Slaw
Yeah, I have (variations of) both of those things.

Cool! Now let's just see if I can implement it right...
Quote:
Originally posted by Wolfy
:(

Don't worry too much. That was the only problem I saw with LoaM, and I ususally see a lot more problems than that with levels I play. I do look forward to LoaM2. Perhaps you might implement some sort of credits display there...
Quote:
Originally posted by zagibu
To display custom hud items you have to work with flat 3dos.

Really? I thought that the HUD was simply a set of multi-staged BMs laid out over the rendering display.
Wake up, George Lucas... The Matrix has you...
2004-10-15, 8:38 AM #9
Quote:
Originally posted by nottheking
Cool! Now let's just see if I can implement it right...

Don't worry too much. That was the only problem I saw with LoaM, and I ususally see a lot more problems than that with levels I play. I do look forward to LoaM2. Perhaps you might implement some sort of credits display there...

Really? I thought that the HUD was simply a set of multi-staged BMs laid out over the rendering display.


No, he said to display custom hud items you'd need to use flat 3do's.. he didn't say that the hud was flat 3do's.
"Nulla tenaci invia est via"
2004-10-16, 7:27 AM #10
How do you get those flat 3dos to follow the camera around, again?
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2004-10-16, 11:01 AM #11
You can use FireProjectile() to create the hud in front of the player

Or, if you're using a thing-based weapon model, like seifer or Ace1, you can use jkSetPOVModel() (I think that's the verb) to set the weapon model to the hud 3do. This is what Ace1 is doing with some of his mods.

btw, if you want the hud to show up in 3rd person, you *must* use the FireProjectile method.
May the mass times acceleration be with you.
2004-10-16, 1:14 PM #12
If you're going to use a 3do for part of the HUD, you'll need to make it itty bitty and get it as close to the camera as possible so that it won't get covered up by something else.

For example, the 3do HUD Shred made for TDiR has a radius of .23892, really small. It is fired 0.0408 in front of the camera and 0.021 above the camera.
-Hell Raiser

↑ Up to the top!