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 → Do have to link it to a level??
Do have to link it to a level??
2001-07-26, 12:35 AM #1
One quick question- I've been trying to make Jawa Tag versitile so that it can be used on any level. I tried linking it in items.dat, but that didn't seem to work. Any ideas on how to make it work on any level? I believe this is why I can't get the code to work, (not even debugging text) but I'll post the re-written code below. BTW -thanks Hideki. Haven't tested it yet, but we'll soon find out. Also, can I use GetNumPlayers() somehow to make sure it doesn't pick over the number of players in the game?

the items.dat snippet:
Code:
# Item definition file for Jedi Knight
# ========================================================================================
# name                  id              min     max     flags   args
# ========================================================================================

#####################################################
# Jawa Tag Debug Items (To allow play on any level) #
#####################################################

jt_main_cog		85		1	1	0x20   	cog=jt_main.cog
jt_iconclient_cog	86		1	1	0x20	cog=jt_iconclient.cog
jt_icon			87		0	1	0x00


-----------------------
the main Jawa Tag cog re-written:
Code:
# Jedi Knight Cog Script
#
# JT_MAIN.COG
#
# * This script is losely based on CTF_MAIN.COG and KFY_MAIN.COG.
#   No code was directly taken from KFY_MAIN.COG, it was merely 
#   used as a reference.  Extensive code was taken from CTF_MAIN.COG.
#
#
# Copyright 2001 - Tazz - tazztazz@hotmail.com

# Jawa bin is 87
symbols

int          player=-1                          local                         
int          jawa=-1                            local                         
int          players0                           local                         
int          players1                           local                         
int          players2                           local                         
int          players4                           local                         
int          players5                           local                         
int          players6                           local                         
int          players7                           local                         
int          players8                           local                         
int          players9                           local                         
int          players10                          local                         
int          players11                          local                         
int          timerID=-1                         local                         
int          x                                  local                         
int          ID                                 local                         
int          chosen                             local                         
thing        potential                          local                         
thing        randPlayer                         local                         
thing        leaveplayer                        local                         
model        jawa_mdl=jawa.3do                  local                         

# Scoring Section                       
int          became_the_jawa=7                  local                         
flex         pulse_score=1.0                    local                         
int          suicide=-2                         local                         
int          kill_jawa=3                        local                         
int          jawa_score_ok=0                    lcoal                         
int          hi_score=-1                        local                         
int          hi_player=-1                       local                         

# Sounds Section                       
sound        jawacall=ForceThrow01.WAV          local                         
sound        scoresnd=ForceThrow01.WAV          local                         
sound        alarmsnd=00AlarmLoop01.WAV         local                         
sound        successsnd=Accomplish1.WAV         local                         

message      startup                                                          
message      timer                                                            
message      join                                                             
message      leave                                                            
message      pulse                                                            
message      killed                                                           

# Timer IDs
#
# 5000 = Lock Jawa selection for 30 seconds, then select random jawa
# 5001 = Display welcome text/info
# 5002 = Person who killed jawa now becomes the jawa

end                                                                           

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

code

startup:

  player = GetLocalPlayerThing();
  CaptureThing(player);
  SetMasterCOG(GetSelfCOG());

  if(verbose > 2) Print("Jawa Tag: Startup Begun");

  // Nobody can become the jawa for 30 seconds
  If(IsServer()) SetTimerEx(30, 5000, 0, 0);

  SetPulse(2);

  Return;

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

join:
   player = GetSenderRef();

   // Send the Welcome information, but delay it by 2 seconds
   SetTimerEx(2, 5001, player, 0);
   Return;

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

leave:
   leaveplayer = GetSenderRef();

   if(GetInv(leaveplayer, 87) > 0.0)
   {
      // Remove the icon
      // Send a TRIGGER_ICON with its parameters
      SendTrigger(leaveplayer, 1001, 87, 0, 0, 0);
      SetInv(leaveplayer, 87, 0.0);

      //Choose a new jawa in 3 seconds
      SetTimerEx(5000, 3, 0, 0);
   }

   Return;

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

pulse:

  // Add score and display score occasionally

  //Make sure we have a current jawa FIRST
  If(jawa_score_ok < 1) Return;

  SetPlayerScore(jawa, GetPlayerScore(jawa) + pulse_score);
  if(GetPlayerScore(jawa) > hi_score)
     {
        hi_score = GetPlayerScore(jawa);
        hi_player = jawa;

        call check_score_limit;
     }

  //Score display
  count = count + 1;
  if(count > 4)
     {
        count = 0;
        jkStringClear();
        jkStringConcatPlayerName(jawa);
        jkStringConcatSpace();
        jkStringConcatASCIIString(", (the current Jawa) has a score of: ");
        jkStringConcatInt(GetPlayerScore(jawa));
	jkStringOutput(-3, -1);
     }
  Return;
# ........................................................................................

timer:

  timerID = GetSenderID();

  If(timerID == 5000) //Choose who is going to be the JAWA!!
     {
	//Thanks to Hideki for the following code:
	For(x=0; x<GetSectorCount(); x=x+1)
     	   {   
		potential = FirstThingInSector(x);   
		While(potential != -1)   
		   {      
			If(GetThingType(potential) == 0x400)      
			   {         
				players[ID] = potential;         
				ID = ID + 1;      
			   }      
			potential = NextThingInSector(potential);   
		   }	
	     }
  	chosen = rand()*ID;
  	if(chosen == ID) chosen = ID - 1;
  	randPlayer = players[chosen];
  	//End Hideki's code ;-)
	
	//Transform the player
      	jawa = randPlayer;

      	//Change model and puppet mode
      	SetThingModel(jawa, jawa_mdl);
      	SetArmedMode(jawa, 6);

 	//Add inventory (easier to keep track)
	SetInv(jawa, 87, 1);

        // Set the player's model to fully lit
        SetThingLightMode(player, 0);

        // Set an icon
        // Send a TRIGGER_ICON with its parameters
        SendTrigger(player, 1001, 87, 1, 0, 0);

        //Broadcast text notification -someone became the jawa
        jkStringClear();
        jkStringConcatPlayerName(player);
        jkStringConcatSpace();
        jkStringConcatASCIIString("is the Jawa!");
        jkStringOutput(-3, -1);

        //Play the "Jawa Call" globally
        PlaySoundGlobal(jawacall, 1, 0, 4);

      	// Increment player score
      	SetPlayerScore(jawa, GetPlayerScore(jawa) + became_the_jawa);
      	if(GetPlayerScore(jawa) > hi_score)
      	   {
         	hi_score = GetPlayerScore(jawa);
         	hi_player = jawa;
         	call check_score_limit;
      	   }

	//Unlock pulse (to increment score)
	jawa_score_ok = 1;

	Return;
     }
  Else 
  If(timerID = 5001)
     {
        player = GetParam(0);

        jkStringClear();
        jkStringConcatASCIIString("Welcome to Jawa Tag, ");
        jkStringConcatSpace();
        jkStringConcatPlayerName(player);
        jkStringConcatASCIIString("!");
        jkStringClear();
        jkStringOutput(player, -1);
     }
  Else
  If(timerID = 5002)
     {
	//Transform the player

      	//Change model and puppet mode
      	SetThingModel(jawa, jawa_mdl);
      	SetArmedMode(jawa, 6);

 	//Add inventory (easier to keep track)
	SetInv(jawa, 87, 1);

        // Set the player's model to fully lit
        SetThingLightMode(player, 0);

        // Set an icon
        // Send a TRIGGER_ICON with its parameters
        SendTrigger(player, 1001, 87, 1, 0, 0);

        //Broadcast text notification -someone became the jawa
        jkStringClear();
        jkStringConcatPlayerName(player);
        jkStringConcatSpace();
        jkStringConcatASCIIString("is the Jawa!");
        jkStringOutput(-3, -1);

        //Play the "Jawa Call" globally
        PlaySoundGlobal(jawacall, 1, 0, 4);

      	// Increment player score
      	SetPlayerScore(jawa, GetPlayerScore(jawa) + became_the_jawa);
      	if(GetPlayerScore(jawa) > hi_score)
      	   {
         	hi_score = GetPlayerScore(jawa);
         	hi_player = jawa;
         	call check_score_limit;
      	   }

	//Unlock pulse (to increment score)
	jawa_score_ok = 1;

	Return;
     }

   Return;

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

killed:

  if(verbose > 2) Print("Jawa Tag: Killed Begun");

  senderRef = GetSenderRef();
  killer = GetThingParent(GetSourceRef());
  player = senderRef;

  // Exit if killed: was sent by anything else than a thing
  if(GetSenderType() != 3) Return;

  // Remove the icon
  // Send a TRIGGER_ICON with its parameters
  SendTrigger(leaveplayer, 1001, 87, 0, 0, 0);
  SetInv(leaveplayer, 87, 0.0);

  // Set the player's model to Gouraud lit
  SetThingLightMode(player, 3);
  jawa = -1;

  If(killer == player)
     {
	//lower player score
        SetPlayerScore(player, GetPlayerScore(player) + suicide);
     }
  Else
     {
	// Increment player score
        SetPlayerScore(killer, GetPlayerScore(killer) + kill_jawa);
     }
  //Set killer as new jawa
  jawa_score_ok = 0;
  jawa = killer; 
  SetTimerEx(5002, 3, 0, 0);

  Return;

end


----------------
Once again, thanks in advance.

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

Tazz
2001-07-26, 2:26 AM #2
The code in the other post will only pick the players existing in the level by checking every "thing" in the level at that time. What you need to do is just register enough array entry so, those entries can be used as player ID, nothing else needs to be done.

------------------
http://millennium.massassi.net/ - Millennium
2001-07-26, 4:05 PM #3
Hideki -- back up. I think you were speaking Japanese for a second! [http://forums.massassi.net/html/wink.gif] Anyhow, I didn't quite understand what you meant. Also, does your answer cover the 'any level' perdicament I'm in, or was it something else?

Thanks for the patience while I re-learn cog.

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

Tazz
2001-07-27, 3:37 AM #4
I was answering this part.

Quote:
<font face="Verdana, Arial" size="2">
Also, can I use GetNumPlayers() somehow to make sure it doesn't pick over the number of players in the game?
</font>


So let me explain again in better ENGLISH [http://forums.massassi.net/html/wink.gif]

The code I posted in the other forum does care about the number of players in the level, so it doesn't go over the number of players existing in the level. What you really need to care rather is to place these in the symbols.

Code:
thing players[0] local
thing players[1] local
thing players[2] local
thing players[3] local


Unless you let your game to be played by more than 4 players, this works fine, otherwise(rarely) place more entries in the above code, which you should be placing in the symbols section. Which you already have...so no problem here.

And no, I haven't talked about 'any level' stuff yet [http://forums.massassi.net/html/smile.gif]

The print command in the startup gets done before the level appears on the screen(about a sec), so place some sleep to read that.

I think the cog itself is loaded properly in any level.

Btw in the code where it says "//Thanks to Hideki for the following code:" part,
GetThingType(potential) == 0x400
was meant to be
GetThingType(potential) == 10

Haven't been coding cog for a while myself [http://forums.massassi.net/html/smile.gif]

------------------
http://millennium.massassi.net/ - Millennium

↑ Up to the top!