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 → Need some help with random choices.
Need some help with random choices.
2003-05-22, 6:10 PM #1
I have this cog,
Code:
# Jedi Knight Cog Script
#
# ACTOR_JEDI.COG
#
# JEDI Script - Actor Version, No Force
#
# [ST]
#
# NOT SUPPORTED BY LucasArts Entertainment Co. 

symbols

message     damaged
message     killed
message     created
message     skill

thing       darkjedi                         mask=0xfff  local

flex        damage                           local
int         damageType                       local

material    tip_mat=saberblue0.mat         local
material    side_mat=saberblue1.mat        local

template    tpl_wall=+ssparks_wall           local
template    tpl_blood=+ssparks_blood         local
template    tpl_saber=+ssparks_saber         local

int         victim                           local

end

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

code

created:

  darkjedi = GetSenderRef();
  Print("test");
  jkSetPersuasionInfo(darkjedi, 8, 16);  //copied from newplayer message
  jkSetSaberInfo(darkjedi, side_mat, tip_mat, 0.003, 0.001, 0.100, tpl_wall, tpl_blood, tpl_saber);
  jkSetFlags(darkjedi, 0x5);  //copied from newplayer message
return;

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

killed:

   darkjedi = GetSenderRef();

   ClearActorFlags(darkjedi, 0x80);
   jkClearFlags(darkjedi, 0x20);
   SetThingCurGeoMode(darkjedi, GetThingGeoMode(darkjedi));

   jkSetFlags(darkjedi, 0x8);

   Return;

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

damaged:

   darkjedi = GetSenderRef();

   damage = GetParam(0);
   damageType = GetParam(1);

   if(damageType & 1)                        // IMPACT
      damage = damage / 2;
   else
   if(damageType & 2)                        // ENERGY
      damage = damage / 2;
   else
   if(damageType & 4)                        // FIRE
      damage = damage / 10;
   else
   if(damageType & 8)                        // FORCE
      damage = damage;
   else
   if(damageType & 16)                       // SABER
      damage = damage;

   ReturnEx(damage);
   Return;

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

skill:
   bin = GetParam(0);
   if(bin = 24)                             // Force Pull
   {
      ReturnEx(-1);
      Return;
   }
   
   ReturnEx(-1);
   Return;


end

And I want it to use a random saber color when it is created, any ideas on how to make it work?

I know about adding all the stuff to the symbols section, but I can't figure out how to make it random...

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-05-22, 6:48 PM #2
Try this. I only have supported it for 4 colors. You'll have to add more, but this shows u how.
Code:
symbols
Message      Created                                                          
thing        DarkJedi                           local                         
Material     RedTipMat=SaberRed0.mat            local                         
Material     RedSideMat=SaberRed1.mat           local                         
Material     YelTipMat=SaberYellow0.mat         local                         
Material     YelSideMat=SaberYellow1.mat        local                         
Material     GrnTipMat=SaberGreen0.mat          local                         
Material     GrnSideMat=SaberGreen1.mat         local                         
Material     BluTipMat=SaberBlue0.mat           local                         
Material     BluSideMat=SaberBlue1.mat          local                         
Material     Side_mat                           local                         
Material     Tip_Mat                            local                         
template     tpl_wall=+ssparks_wall             local                         
template     tpl_blood=+ssparks_blood           local                         
template     tpl_saber=+ssparks_saber           local                         
flex         RandNumber                         local                         
end                                                                           
code
Created:
	DarkJedi=GetSenderRef();

  // Generate a random number and assign saber mats based on it.
	RandNumber = Rand();
	if(RandNumber < 0.25) { Tip_mat = RedTipMat; Side_mat=RedSideMat; }
	if((RandNumber >= 0.25) && (RandNumber < 0.5)) { Tip_Mat = YelTipMat; Side_Mat = YelSideMat; }
	if((RandNumber >= 0.5) && (RandNumber < 0.75)) { Tip_Mat = GrnTipMat; Side_Mat = GrnSideMat; }
	if((RandNumber >= 0.75) && (RandNumber <= 1)) { Tip_Mat = BluTipMat; Side_Mat = BluSideMat; }

  // Now set up the saber.
	jkSetSaberInfo(DarkJedi, side_mat, tip_mat, 0.003, 0.001, 0.120, tpl_wall, tpl_blood, tpl_saber);
	Return;
Remember that rand() only goes up to 1. If you want to go higher, you'll have to multiply by 2, or change the increments in the if statements.

------------------
"The Just shall live by faith." - Galatians 3:11
Catloaf, meet mouseloaf.
My music
2003-05-22, 6:57 PM #3
or you might try it this way.
i used this method to make a level play random sounds.
i think it should work.
Code:
//-SYMBOLS NEEDED...
symbols
#-----
material    tip_mat00
material    tip_mat01
etc...
material    side_mat00
material    side_mat01
etc...
int         tipMat_num=2
int         sideMat_num=2
int         a=0     local
int         b=0     local
#-----
end
#=====
//-CODE NEEDED
code
#-----
a = Rand() * tipMat_num;
b = Rand() * sideMat_num;
jkSetSaberInfo(darkjedi, side_mat0, tip_mat0[a], 0.003, 0.001, 0.100, tpl_wall, tpl_blood, tpl_saber);
#=====
end

tipMat_num and sideMat_num are the total number of that type of material that you have listed. youll need to change it in the cog itself.

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited May 22, 2003).]
Famous last words - "It seemed like a good idea at the time."
2003-05-22, 7:17 PM #4
Your way's better.
[http://forums.massassi.net/html/frown.gif]

------------------
"The Just shall live by faith." - Galatians 3:11
Catloaf, meet mouseloaf.
My music
2003-05-23, 4:02 AM #5
OK, I've tested it quite a few times, but it keeps assigning the first listed saber material, in this case blue. Could it not be working because its an actor cog?

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-05-23, 4:06 AM #6
Stormtrooper, can you post the cog as you have it please, or just that one section with the symbols

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

The Magician Saber System.

[This message has been edited by Descent_pilot (edited May 23, 2003).]
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-23, 4:29 AM #7
Sure, here it is, just the symbols and the startup section, if you need more, just tell me.
Code:
symbols

message      damaged                                                          
message      killed                                                           
message      created                                                          
message      skill                                                            

thing        darkjedi                           mask=0xfff                    local

flex         damage                             local                         
int          damageType                         local                         
##tip mats
material     tip_mat00=saberblue0.mat           local                         
material     tip_mat01=saberred0.mat            local                         
material     tip_mat02=saberorange0.mat         local                         
material     tip_mat03=saberyellow0.mat         local                         
##side mats
material     side_mat00=saberblue1.mat          local                         
material     side_mat01=saberred1.mat           local                         
material     side_mat02=saberorange1.mat        local                         
material     side_mat03=saberyellow1.mat        local                         

template     tpl_wall=+ssparks_wall             local                         
template     tpl_blood=+ssparks_blood           local                         
template     tpl_saber=+ssparks_saber           local                         

int          victim                             local                         
int          tipMat_num=1                                                     
int          sideMat_num=1                                                    
int          a=0                                local                         
int          b=0                                local                         
                                                                          

end                                                                           

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

code

created:

  darkjedi = GetSenderRef();
  jkSetPersuasionInfo(darkjedi, 8, 16);  //copied from newplayer message
  a = Rand() * tipMat_num;
  b = Rand() * sideMat_num;
  jkSetSaberInfo(darkjedi, side_mat0, tip_mat0[a], 0.003, 0.001, 0.100, tpl_wall, tpl_blood, tpl_saber);
  jkSetFlags(darkjedi, 0x5);  //copied from newplayer message
return;


------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

[This message has been edited by Stormtrooper (edited May 23, 2003).]
2003-05-23, 5:16 AM #8
OK, i accidentally put 1 instead of 4 in the top/sidemat_num part, but now it crashed the game at startup, any ideas?
Code:
symbols

message      damaged                                                          
message      killed                                                           
message      created                                                          
message      skill                                                            

thing        darkjedi                           mask=0xfff                    local

flex         damage                             local                         
int          damageType                         local                         
##tip mats
material     tip_mat00=saberblue0.mat           local                         
material     tip_mat01=saberred0.mat            local                         
material     tip_mat02=saberorange0.mat         local                         
material     tip_mat03=saberyellow0.mat         local                         
##side mats
material     side_mat00=saberblue1.mat          local                         
material     side_mat01=saberred1.mat           local                         
material     side_mat02=saberorange1.mat        local                         
material     side_mat03=saberyellow1.mat        local                         

template     tpl_wall=+ssparks_wall             local                         
template     tpl_blood=+ssparks_blood           local                         
template     tpl_saber=+ssparks_saber           local                         

int          victim                             local                         
int          tipMat_num=4                                                     
int          sideMat_num=4                                                    
int          a=0                                local                         
int          b=0                                local                         
                                                                              

end                                                                           

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

code

created:

  darkjedi = GetSenderRef();
  jkSetPersuasionInfo(darkjedi, 8, 16);  //copied from newplayer message
  a = Rand() * tipMat_num;
  b = Rand() * sideMat_num;
  jkSetSaberInfo(darkjedi, side_mat0, tip_mat0[a], 0.003, 0.001, 0.100, tpl_wall, tpl_blood, tpl_saber);
  jkSetFlags(darkjedi, 0x5);  //copied from newplayer message
return;

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

killed:

   darkjedi = GetSenderRef();

   ClearActorFlags(darkjedi, 0x80);
   jkClearFlags(darkjedi, 0x20);
   SetThingCurGeoMode(darkjedi, GetThingGeoMode(darkjedi));

   jkSetFlags(darkjedi, 0x8);

   Return;

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

damaged:

   darkjedi = GetSenderRef();

   damage = GetParam(0);
   damageType = GetParam(1);

   if(damageType & 1)                        // IMPACT
      damage = damage / 2;
   else
   if(damageType & 2)                        // ENERGY
      damage = damage / 2;
   else
   if(damageType & 4)                        // FIRE
      damage = damage / 10;
   else
   if(damageType & 8)                        // FORCE
      damage = damage;
   else
   if(damageType & 16)                       // SABER
      damage = damage;

   ReturnEx(damage);
   Return;

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

skill:
   bin = GetParam(0);
   if(bin = 24)                             // Force Pull
   {
      ReturnEx(-1);
      Return;
   }
   
   ReturnEx(-1);
   Return;


end


------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-05-23, 6:04 AM #9
Try removing the 0 before the [a] and . *SOMETIMES* (very rarely), jk will require that you omit numbers in an array rather than include them like usual. You also might even try adding an extra 0 if that doesn't work.

------------------
"The Just shall live by faith." - Galatians 3:11
Catloaf, meet mouseloaf.
My music
2003-05-23, 7:03 AM #10
adding the second 0 made it work, but it will give it a different color side and tip mat, like red and blue.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"
2003-05-23, 5:47 PM #11
okay, arrays in cog work like this
int red
int green
int blue
red[0] = red
red[1] = green
red[2] = blue

The problem is that the first array name (bob[0]) has to be the same as the symbol name (int bob [for example]) the other symbol names in the array can have any name you want as long as it not a vec if int/float/flex and vice versa.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-23, 6:37 PM #12
Oh, I see... the cog generates a random mat for BOTH the side and tip. Remove the "b" variable and change the "" to "[a]" in the "jkSetSaberInfo" verb.

------------------
"The Just shall live by faith." - Galatians 3:11

[This message has been edited by DogSRoOL (edited May 23, 2003).]
Catloaf, meet mouseloaf.
My music
2003-05-24, 5:28 AM #13
dude, thats not nessecary, it may even be conterproductive. He may want a differnt number of tips then sides.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-24, 6:43 AM #14
Why? [http://forums.massassi.net/html/confused.gif]
The side mat needs to match the tip mat, or you get something like a yellow saber with a purple tip. I can't see a reason why you would want different numbers of those mats.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!
Catloaf, meet mouseloaf.
My music
2003-05-24, 7:39 AM #15
good point. i forgot that the saber's tip and its side mat could end up being different when i posted that. oopsy [http://forums.massassi.net/html/redface.gif]
if you want them to be the same it would have to be like this:
Code:
//-SYMBOLS NEEDED...
symbols
#-----
material   tip_mat00     local
material   tip_mat01     local
etc...
material   side_mat00     local
material   side_mat01     local
etc...
int        sabMats_num=2     local
int        a=0     local
#-----
end
#=====
//-CODE NEEDED
code
#-----
a = Rand() * sabMats_num;
jkSetSaberInfo(darkjedi, side_mat0[a], tip_mat0[a], 0.003, 0.001, 0.100, tpl_wall, tpl_blood, tpl_saber);
#=====
end

that should make the tip and the side mats the same for the sabers, as long as you list them right in the symbols.

------------------
Famous last words - "It seemed like a good idea at the time."
Famous last words - "It seemed like a good idea at the time."
2003-05-24, 2:12 PM #16
Thats still wrong! grrr. Arrays go like this, and you c/p this, this is the cog you want, I really didn't want to type this out.
Code:
# replace the mats in symbols with something like this
material       side=name.mat       local
material       side1=name.mat      local
material       side2=name.mat      local
material       tip=name.mat        local
material       tip1=name.mat       local
material       tip2=name.mat       local

# Replace the created message with this
Created:
   darkjedi = GetSenderRef();
   a = Rand() * tipMat_num;
   b = Rand() * sideMat_num;
   jkSetPersuasionInfo(darkjedi, 8, 16);
   jkSetSaberInfo(darkjedi, side[a], tip, 0.003, 0.001, 0.1, tpl_wall, tpl_blood, tpl_saber);
   jkSetFlags(darkjedi, 0x8);
   Return;

What a bunch of noobs! I leave this place for a few weeks and its gone to the n00bs! Where's the vets when ya need 'em?

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-24, 5:01 PM #17
that could still make the tip mat and the side mat be different. most of the time they probably wouldnt match because your using two separate random numbers.
whats wrong with the way i just said?

------------------
Famous last words - "It seemed like a good idea at the time."

[This message has been edited by DSLS_DeathSythe (edited May 24, 2003).]
Famous last words - "It seemed like a good idea at the time."
2003-05-24, 6:53 PM #18
Your arrays aren't correct! What else is wrong? We need Stromtrooper's thoughts on the saber side/tip thingy. But they don't have to match. Cool saber effects, uber n00b vet like thingy. [http://forums.massassi.net/html/tongue.gif]

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-26, 6:31 PM #19
If the arrays were'nt correct, why did the cog only work with 2 zero's? And did you miss Stormtrooper complain about the mats not lining up? Obviously, he wants them the same.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!
Catloaf, meet mouseloaf.
My music
2003-05-26, 6:59 PM #20
I give up, this topic has gone to the n00bs. Look, people the arrays, thats not how they work. The base name (the name before the [int] in the code secton) should be the same as the start of the array in the symbols section, afterwords you can have any name below it, but thats when the reference with go. Maybe GBK or SM could do a better example or explination (yes, thats a recommendation [scary huh] to those great cogger(s) [and a complement, even scarier [http://forums.massassi.net/html/tongue.gif] ]) instead of me and my limited (just like everyone else) views.

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

The Magician Saber System.
Major projects working on:
SATNRT, JK Pistol Mod, Aliens TC, Firearms

Completed
Judgement Day (HLP), My level pack
2003-05-26, 7:20 PM #21
[http://forums.massassi.net/html/rolleyes.gif]

Though arrays may function properly that way, it doesn't necessarily mean it's the "official" way to do it just because you choose to set it up that way. Look at LEC's cogs, 00_door.cog, for example. It starts door0, and increases to door3. If you use only single-digits in your arrays, it's fine to use something like door0[a] (like LEC did, but they used "i" and I'm having trouble w/italics tags). If you have more, your setup would be better.

------------------
"The Just shall live by faith." - Galatians 3:11
To edit is human... To COG is divine!!

[This message has been edited by DogSRoOL (edited May 26, 2003).]
Catloaf, meet mouseloaf.
My music
2003-05-26, 11:04 PM #22
rand=rand()*100;

...Then just have if-statements to determine which hypothetical block the number is in.

You don't have to use 100, and who knows how you want to divide it, but that's really all there is to it.

------------------
"Anakin, when I tried to earn my knighthood by defeating a Sith Lord, I actually WON."
-Obi Wan Kenobi
2003-05-27, 4:30 AM #23
Sorry guys, I havn't been around lately.

When I changed it like the way DogSRoOL said "Oh, I see... the cog generates a random mat for BOTH the side and tip. Remove the "b" variable and change the "" to "[a]" in the "jkSetSaberInfo" verb." That made it have the same color mats, which is what I needed.
Then when I tried Descent_pilot's way, the saber wouldn't show up on the actor, but that was probably my fault, I probably didn't set it up right or something, I'll try to fix it later.

Thanks for the help everyone.

------------------
Look for my current project, The Force in Your Soul.
Last week I cudn't evn spel grajuat, but now I is one.

*Takes out his blaster and fires shots at the wall, the blastmarks leave the words "S-TROOPER WUZ 'ERE!!!"

↑ Up to the top!