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 → reloading
reloading
2004-01-04, 2:18 PM #1
Ok I made my crossbow a M4A1 I have have a key to make it reload and i also have a button for reloading. Fire 2 is not the reload button its done in the user0 message.
How do I get the cog to count the bullets so that every 30 shots it plays the reloading key and gives you another 30 shots and so that if you press the reload button before the use of the 30 shots it puts the number of shots you have back to 30.

------------------
hello.
go to www.nigelsjkprojects.uni.cc
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-04, 3:38 PM #2
You can use this cog I've modified and am planning to use in my new weapons mod. As it says, I have borrowed it from Ben Allen's James Bond mod. You're definitely going to want to modify this if you want to hotkey a reload key that's not fire2.

Code:
# Jedi Knight Cog Script
#
# WEAP_MAC10.COG
#
# WEAPON 6 script - Ingram MAC 10
#        - Submachine Gun
#        - 32 shots per reload
#        - Not powerful or accurate, but fast
#
# - Affected by MagSealed sectors/surfaces.
#
# Source: M-16 Assault Rifle cog from the James Bond 007 mod (found on massassi.net)
# made by Ben Allen
# Modified (EXTREMELY!) by Darth Slaw to have automatic reloading when clip runs out
# (If you compare his original code to my modified one, you would hardly tell it was
# originally his!)
# Feel free to use my resources for your own use.  Just be sure to give credit for them.
# (C) 2003 JK Modification: Slaw's JK Weapons Pack, by Darth Slaw
#==============================================================#
symbols

model     povModel=mac10v.3do                 local
model     weaponMesh=strg.3do                 local

keyframe  mountAnim=bryvmnt.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=+bullet6                 local

thing     player                              local

flex      fireWait=0.04                       local
flex      reloadWait=0.7                      local
flex      holsterWait                         local
flex      autoAimFOV=25                       local

vector    rVec                                local

int       trackID=-1                          local
int       holsterTrack                        local
int       mode                                local
int       reload=0                            local
int       ammomax=32                          local
int       curammo=32                          local
int       ammobin=12                          local
int       weap=6                              local

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

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(mode == 0)	// fire 1
	{
		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;
		}
		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);
			rVec = VectorSet((Rand() - 0.5) * 10, (Rand() - 0.5) * 10, 0.0);
			FireProjectile(player, projectile, fireSound, 8, '0.0168 0.1896 0.03', rVec, 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
	{
		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;
#------------------------------------------------------
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) + reloadWait));
		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) + reloadWait));
	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;
#------------------------------------------------------
end


It keeps track of the ammo and stuff via integer values and not inventory bins. I've worked on perfecting the cog's basic structure for several years now, and it's getting closer to that point (I hope). Hopefully this will help you with reloading code. [http://forums.massassi.net/html/biggrin.gif]

------------------
It's Peanut Butter Jelly Time!
/Banana starts dancing

[This message has been edited by Darth Slaw (edited January 04, 2004).]
May the mass times acceleration be with you.
2004-01-04, 4:39 PM #3
Um...

Couldn't this be done by checking how many bullets you have left, and setting certain bullet numbers as 'reload bullets?'

Like, if you're down to #30...

Code:
fire:
ammo=getinv(player, bin);
if(ammo == 30 || ammo == 60) // or if ammo == 180...
{
call reload;
}
else
{
call shoot;
}


------------------
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-04, 5:31 PM #4
All you need is to have the reload stuff in a seperate fuction and call that both in the user0 and in the fire message you have a check like what Checksum said. Just you can just have the fire stuff instead of the call shoot; verb. [http://forums.massassi.net/html/tongue.gif]

------------------
The Sniper Missions. Current project, The Sniper Missions

The Magician Saber System.

The 2 riddle!
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2004-01-04, 5:42 PM #5
Quote:
<font face="Verdana, Arial" size="2">Originally posted by Checksum:
Couldn't this be done by checking how many bullets you have left, and setting certain bullet numbers as 'reload bullets?'</font>


Reloading in the middle of a magazine mean anything to you? [http://forums.massassi.net/html/tongue.gif] Besides, if you are sharing ammunition with other weapons (which you frequently must in JK to avoid many great pains to do otherwise), you'll have one powerup give you 10 rounds, another kind give you 30, etc. Bins have always seemed like the best choice to me.

------------------
Bassoon, n. A brazen instrument into which a fool blows out his brains.
Bassoon, n. A brazen instrument into which a fool blows out his brains.
2004-01-04, 5:57 PM #6
Thanks for your help every one ill try some of the ideas now. Also if anyone can just simply put the extra symbols neccasarry any extra's that go into the fire message and what I would put in user0 to call a reload while in the middle of a clip.

------------------
hello.
go to www.nigelsjkprojects.uni.cc
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-05, 10:13 AM #7
Try this. It should work.
Code:
# Jedi Knight Cog Script
#
# This cog constructed for a_person to reload via user0 message
# Fire 1 and 2 fire bullets. Hotkey reloads.
# Written by Darth Slaw
# Base for cog was Ben Allen's M16 rifle cog from James Bond JK mod (version 1)
#
#==============================================================#
symbols

model     povModel=strv.3do                   local
model     weaponMesh=strg.3do                 local

keyframe  mountAnim=bryvmnt.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

thing     player                              local

flex      fireWait=0.04                       local
flex      reloadWait=0.7                      local
flex      holsterWait                         local
flex      autoAimFOV=25                       local

vector    rVec                                local

int       trackID=-1                          local
int       holsterTrack                        local
int       mode                                local
int       reload=0                            local
int       ammomax=32                          local
int       curammo=32                          local
int       ammobin=12                          local
int       weap=6                              local

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

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 - autoreload
	{
		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);
		rVec = VectorSet((Rand() - 0.5) * 10, (Rand() - 0.5) * 10, 0.0);
		FireProjectile(player, projectile, fireSound, 8, '0.0168 0.1896 0.03', rVec, 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)	// clip is empty - autoreload
		{
			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();
	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();
	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) + reloadWait));
		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:
	curammo = ammomax;

Return;
#------------------------------------------------------
reloadclip:
	SetFireWait(player, (GetKeyLen(reloadAnim) + reloadWait));
	PlaySoundThing(reloadSound, player, 1.0, -1, -1, 0x80);
	jkPlayPOVKey(player, reloadAnim, 1, 0x38);
	PlayKey(GetLocalPlayerThing(), reloadgun, 2, 32);
	//Determine how much ammo is in clip
	if(GetInv(player, ammobin) < ammomax) curammo = GetInv(player, ammobin);
	else curammo = ammomax;
	reload = 0;	// not reloading

Return;
#------------------------------------------------------
user0:
	if(curammo >= ammomax)	// 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)	// Partial clip and extra bullets
	call reloadclip;

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


------------------
It's Peanut Butter Jelly Time!
/Banana starts dancing

[This message has been edited by Darth Slaw (edited January 05, 2004).]
May the mass times acceleration be with you.
2004-01-05, 12:46 PM #8
woohu!! Thanks alot Darth Slaw your cog worked rreally well.

------------------
hello.
go to www.nigelsjkprojects.uni.cc
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-05, 1:39 PM #9
I'm glad it worked for you. If you have any questions or anything on the cog, I'll try to help you out. [http://forums.massassi.net/html/biggrin.gif]

------------------
It's Peanut Butter Jelly Time!
/Banana starts dancing
May the mass times acceleration be with you.

↑ Up to the top!