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 forgets to warm up CONSTENTLY!
Weapon forgets to warm up CONSTENTLY!
2003-12-26, 2:10 PM #1
Hi!
I'm changing a STRifle to do a berzerk shot, but something isn't quite working...
Code:
# Jedi Knight Cog Script
#
# WEAP_STRIFLE.COG
#
# WEAPON 3 script - Stormtrooper Rifle
#
# The standard rifle used by the stormtroopers.  Not as accurate as the Bryar Pistol.
# This weapon has only one type of fire.
#
# - Affected by MagSealed sectors/surfaces.
#
# [YB & CYW]
#
# (C) 1997 LucasArts Entertainment Co. All Rights Reserved


symbols

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

keyframe    mountAnim=StrVmnt.key               local
keyframe    dismountAnim=StrVdis.key            local
keyframe    povfireAnim=StrVpst1.key            local
keyframe    holsterAnim=kyhlstr.key             local

sound       mountSound=df_rif_ready.wav         local
sound       dismountSound=PutWeaponAway01.wav   local
sound       fireSound=trprsht2.wav              local
sound       outSound=trprout.wav                local

template    projectil=+raildet                 local
template	projectile0=+bryarbolt		local
template	projectile1=+stlaser		local
template	projectile2=+grenade2		local
template	projectile3=+crossbowbolt3	local
template	projectile4=+repeaterball	local
template	projectile5=+raildet2		local
template	projectile6=+seqchrg2		local
template	projectile7=+concbullet		local
template	projectile8=+force_lightning	local
template	projectile9=+force_dest_p1	local

thing       player                              local

vector      randVec                             local

flex        fireWait=0.2                        local
flex        holsterWait                         local
flex        powerBoost                          local
flex        autoAimFOV=25                       local
flex        autoAimMaxDist=5                    local

thing		eegad=-1			local
thing		g				local

int         dummy                               local
int         trackID=-1                          local
int         fireChannel=-1                      local
int         holsterTrack                        local
int         mode                                local

int		busy=0				local

sound		warmup=forcefieldhum01.wav	local
int		chachacha=1			local

message     activated
message     deactivated
message     selected
message     deselected
message     autoselect
message     fire
message     timer
message		pulse

end

# ========================================================================================

code

fire:
   player = GetSourceRef();
   mode = GetSenderRef();
if(mode==0) {
   // Check that the player is still alive.
   if(GetThingHealth(player) <= 0)
   {
      Return;
   }

   // Check Ammo - If we are out, autoselect best weapon.
   // It should always use two energy cells, but -- as in DF --
   // allow the last fire if there is only one left...
   if(GetInv(player, 11) < 100.0)
   {
      PlaySoundThing(outSound, player, 1.0, -1, -1, 0x80);
      if((GetAutoSwitch() & 1))
         SelectWeapon(player, AutoSelectWeapon(player, 1));
      Return;
   }

   // Get random aiming error
   randVec = VectorSet((Rand()-0.5)*5, (Rand()-0.5)*5, 0.0);
	if(busy==1) { print("Warming up! Please wait..."); return; }
   SetPOVShake('0.0 -.003 0.0', '1.5 0.0 0.0', .05, 80.0);
   eegad = FireProjectile(player, projectil, fireSound, 8, '0.0168 0.1896 0.00', randVec, 1, 0x31, autoAimFOV, autoAimFOV*2);
	busy=1;
	captureThing(eegad);
	chachacha=PlaySoundThing(warmup,player,1,-1,1,0x81);
	ChangeSoundPitch(chachacha,0.01,0.01);
	sleep(0.01);
	SetTimer(10);
	ChangeSoundPitch(chachacha,2,10);
	SetPulse(0.1);
   // SetThingVel(dummy, vectorScale(GetThingVel(dummy), 0.01));

   ChangeInv( player, 11, -100.0 );
   jkPlayPOVKey( player, povfireAnim, 1, 0x38 );

   powerBoost = GetInv(player, 63);
   ChangeFireRate(player, fireWait/powerBoost);
} else { 
print("Instant warm up! Hopefully...");
	chachacha=PlaySoundThing(warmup,player,1,-1,1,0x81);
	ChangeSoundPitch(chachacha,0.01,0.01);
	sleep(0.01);
	SetTimer(1);
	ChangeSoundPitch(chachacha,2,1);
}
   Return;

# ........................................................................................

activated:
   player = GetSourceRef();
   mode = GetSenderRef();

   jkSetWaggle(player, '0.0 0.0 0.0', 0);
   powerBoost = GetInv(player, 63);
   ActivateWeapon(player, fireWait/powerBoost, mode);
   Return;

# ........................................................................................

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

# ........................................................................................

selected:
   player = GetSourceRef();
	busy=0;
   PlayMode(player, 41);
   PlaySoundThing(mountSound, player, 1.0, -1, -1, 0x80);
   jkSetPOVModel(player, povModel);
   SetArmedMode(player, 1);
   jkSetWeaponMesh(player, weaponMesh);
   jkSetWaggle(player, '10.0 7.0 0.0', 350);
   trackID = jkPlayPOVKey(player, mountAnim, 0, 20);
   SetMountWait(player, GetKeyLen(mountAnim));
   jkClearFlags(player, 0x5);
   SetCurWeapon(player, 3);

   Return;

# ........................................................................................

deselected:
   player = GetSourceRef();
StopSound(chachacha,1);
	SetTimer(0);
   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, 3) != 0.0)
   {
      // If the player has ammo
      if(GetInv(player, 11) != 0.0)
      {
         ReturnEx(600.0);
      }
      else
      {
         ReturnEx(-1.0);
      }
   }
   else
   {
      ReturnEx(-1.0);
   }

   Return;

# ........................................................................................

timer:
	if(busy==1)
	{
		busy=0;
		StopSound(chachacha,1);
		print("DING! Fries are done!");
	}
	else
	{
   StopKey(player, holsterTrack, 0.0);
	}
   Return;
pulse:
	if(busy==0) return;
	g=CreateThing(projectile0[rand()*9],eegad);
	CaptureThing(g);
	SetThingVel(g,VectorSet((rand()*2.00)-1.00,(rand()*2.00)-1.00,(rand()*2.00)-1.00));
	SetThingLVec(g,VectorSet((rand()*2.00)-1.00,(rand()*2.00)-1.00,(rand()*2.00)-1.00));
return;
end

When I shoot, it is supposed to have a ten second warm up (basically 10 seconds for the bolt to complete its task in spreading death to the level before the next one comes). Now it doesn't always begin the timer or even play the sound, therefore I added this secondary fire to try it again with a less waiting time. But often that doesn't work. I have tried this berzerk shot once before. Works fine when I test it in the testing level, but when I put the pieces together in a folder and in the respective files (JKL templates and stuff) they wouldn't come out, so I try once again without having too much new in the JKL. I tried a ParseArg to add a trail cog, but it didn't work out, so I tried to place it all in one cog. Help!

/Edward
Edward's Cognative Hazards
2003-12-27, 5:23 AM #2
I had LOTS of similar cog malfunction problems using "sleep()". Try omitting that command. Use another timer command if necessary.

------------------
It's Peanut Butter Jelly Time!
/Banana starts dancing
May the mass times acceleration be with you.
2003-12-27, 10:27 AM #3
Well, I took away the sleeps and it seems to be working OK... Reason why I put up a sleep was because I had put 2 Change Pitch verbs together (one to bring it low and another to fade up) and it didn't work... Oh, and another thing... When I shoot at a close range or something, it blows, then the stuff emmits from the dead guy, then, only sometimes, does it crash the game. The crash that freezes the game.

/Edward
Edward's Cognative Hazards
2003-12-27, 8:25 PM #4
Tell me - what exactly do you want the cog to do? Describe in detail.

------------------
Duel Zero key count: Zero! Down to guns and forces. Expect a release soon.
2003-12-28, 2:28 AM #5
OK, here's the deal... You shoot, projectile teave a trail of EVERYTHING, and it will all end after 10 seconds... Works fine, sometimes cuts short because it hits a wall, and sometimes it continues to emmit the trail from a thing it touched or that was close by... And sometimes when this happens, it freezes the game... Too many things being created at once perhaps? If I hadn't baked the trailing into the pulse here, and put it in a seperate pulse on a seperate COG, the result would be something like this first image

Hope that is enough. If not, do post over there for me to post a beta or Demo.

/Edward


[This message has been edited by Edward (edited December 28, 2003).]
Edward's Cognative Hazards
2003-12-28, 5:29 AM #6
well, i wouldent do it liek that any way.. i would add a modifyed 00_smoketrail.cog into the template in static.JKL and leave the STrfile.cog as it is.

------------------
I am pjb.
Another post......
another moment of my life wasted.....
at least i made a level.
PJB's JK page's

-the PJB jedi rule book-
rule one, "never trust a bartender with bad grammar"-kyle katarn in JO

Rule Two, "Gravity is a crule misstress" -kyle katarn in MotS, and the alternatior MK I in AJTD
I am Darth PJB!
well, go on, run away!

i have a plastic lightsaber and a jedi cape.. am i a nerd?

If gravity is a crule mistress, and bar tenders with bad grammar are untrustworthy, what is air?
2003-12-29, 5:26 AM #7
You need to pay attention to what you write. And has this been checked with Parsec? I know it hasn't because I see some obvious errors it would have reported - like the fact that there is no SetThingLVec.

The sleep in the fire message is small enough that it probably doesn't do any harm, but even so, sleeps are a bad idea. This isn't because sleeps are taboo or anything - this has to do with how threads work.

The reason trailthings are still created when the projectile is removed is because you're still creating them after it's gone. You need to listen for its removed event.

Some of the variables are badly named, but only the randvec one will give you problems. If you use a variable with the same name as a verb, that verb won't work. You won't notice anything until you try to use the verb, but it's bad syntax and should be fixed.

Fix those things, and it should start working.

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2003-12-29, 2:20 PM #8
All hail - the Oracle has spoken ^^^ [http://forums.massassi.net/html/smile.gif]
And that, as they say, is that [http://forums.massassi.net/html/wink.gif] [http://forums.massassi.net/html/tongue.gif]

I don't know whether it's just me, but I've noticed a reasonable amount of editing of class cogs recently (nowt wrong with that [http://forums.massassi.net/html/wink.gif]) - the area I believe to be the one that is proving seemingly difficult to fathom is where some editors and coggers alike seem rather trigger-happy to go inserting that old "Sleep()" verb in and (as SaberMaster points out) it's not a wise idea when considering how thread executions in programs are performed.

Naturally, I'm not going to totally slate "Sleep()" - it certainly has its place (especially for single-player cutscenes !!! [http://forums.massassi.net/html/biggrin.gif]), but for anything requiring some "thinking" rather than a "quick n' dirty fix", then Timers are by far your best shot [http://forums.massassi.net/html/smile.gif]

Hope this has helped [http://forums.massassi.net/html/biggrin.gif]

-Jackpot

------------------
"lucky_jackpot is the smily god..." - gothicX

"Life is mostly froth and bubble,
But two things stand in stone,
Kindness in another's trouble,
Courage in your own"
("Ye Wearie Wayfarer" - by Adam Lindsay Gordon)

[This message has been edited by lucky_jackpot (edited December 29, 2003).]
"lucky_jackpot is the smily god..." -gothicX
"Life is mostly froth and bubble, but two things stand in stone,
Kindness in another's trouble, courage in your own"
- "Ye Wearie Wayfarer"
|| AI Builder: compatible with both JK & MotS || My website ||

↑ Up to the top!