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 → Help with grass cog
Help with grass cog
2002-10-01, 4:15 PM #1
Ya, I need help with this little beasty.

What I want it to do is place grass around the player as he walks. The problem is that only one grass stalk moves, and the others stay still. I only want to move those stalks that are a certain distance away from the player. Also I would like to place it above the terrain in my level... but I have no idea on how to do that. Anyways heres the cog:

Code:
# Jedi Knight Cog Script
#
# grass.COG
#
# A cog which plants grass in a certian radius around the player. 
# The catch is it has to land on top of the terrain.
#
# [Hellcat]
# This Cog is Not supported by LucasArts Entertainment Co

flags=0x240

symbols

int 	i=0				local
int 	player=-1			local

int	g_dist=2			local

flex	randx=0				local
flex	randy=0				local

vector	grass_pos				local

template	grass_mdl

message 	startup
message	pulse

end

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

code
startup:
	sleep(1);

	player = GetLocalPlayerThing();

	while (i<101)
	{
		//Get the players position
		grass_pos = GetThingPos(player);

		//Make some random values within the boudry
		randx = (Rand() * g_dist) - (g_dist/2);
		randy = (Rand() * g_dist) - (g_dist/2);

		grass_pos = VectorSet((VectorX(grass_pos) + randx), (VectorY(grass_pos) + randy), (VectorZ(grass_pos)));

		grass0i = CreateThingAtPos(grass_mdl, 0, grass_pos, '0 0 0'); 

		i = i + 1;
	}

	setpulse(0.5);

return;
# ........................................................................................

pulse:
	i=0;
	for(i=0; i < 101; i=i+1) 
	{
		PrintFlex(VectorDist(GetThingPos(player), GetThingPos(grass0i)));

		If (VectorDist(GetThingPos(player), GetThingPos(grass0i)) >=(g_dist/2))
 		{
			//Get the players position
			grass_pos = GetThingPos(player);

			//Make some random values within the boudry
			randx = (Rand() * g_dist) - (g_dist/2);
			randy = (Rand() * g_dist) - (g_dist/2);

			grass_pos = VectorSet((VectorX(grass_pos) + randx), (VectorY(grass_pos) + randy), (VectorZ(grass_pos)));

			SetThingPos(grass0i, grass_pos);
		}
	}


return;
# ........................................................................................

end


Its pretty simple. Any ideas?
Team Battle.
2002-10-01, 4:52 PM #2
Set the Z-section of the vector for creation to the players current Z - 50 or so. Then use FireProjectile to create it, it makes sure that projectiles are within the limits of the sector. Or if your not gonna have a ton of low areas around the player, or better yet, your grass can 'fall' to ground level with a downward momentum, then just use the players current Z. Otherwise it might put it a room below you, not sure though.

Worth a shot.
2002-10-01, 8:35 PM #3
hmm, I could make the stalks the explosion using fireprojectile. I will try that.

But anyone got any ideas on why it moves only one stalk?
Team Battle.
2002-10-01, 8:58 PM #4
I think with arrays you have to define the variables. So up there you'll have to add the int grass0, then the int grass1, etc. etc. until you have like int grass101. Pain in the *** , but thats what copy and paste is there for. I could be wrong though, i just define all my variables.
2002-10-01, 8:59 PM #5
Oh, never mind. The i needs to be in []'s. For example, Instead of grass0i, it should be grass0, I think thats probably causing it.
2002-10-01, 11:43 PM #6
Opps! hehe. I have to define it aswell. grr [http://forums.massassi.net/html/biggrin.gif]

Oh well. It works now, thanks!
Team Battle.
2002-10-01, 11:47 PM #7
Is there away to not define the variables from 0 to 100? It would be very handy not to need to.
Team Battle.
2002-10-02, 1:15 AM #8
I don't really think so Hellcat, as JK's array system isn't really an array system, all it really does is get the varible offseted from what you defined.

In another words grass0 when "i" is 2

grass0
grass1
grass2 <-- will pick this one
grass3

and as a matter of fact it doesn't even have to have the same name, it could be

grass0
massassi
bla
seifer
owns

Although don't quote me on that, I can't really remember :
2002-10-02, 2:58 AM #9
Ya, I think your right. Thats a bit of a pitty [http://forums.massassi.net/html/frown.gif]
Team Battle.
2002-10-02, 4:14 AM #10
GBK used heap verbs in a couple of his cogs that contol the world surfaces, changing them from dflt to their normal mats. It might work here, but this sounds like his RVTCS or what ever tis called.

------------------
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
2002-10-02, 5:07 AM #11
Quote:
<font face="Verdana, Arial" size="2">CreateThingAtPos(grass_mdl, 0, grass_pos, '0 0 0');</font>


If the player starts in sector 0, then that's alright, but otherwise the grass won't appear on startup.

Strange that level editors confuse models with templates and things... JEDicts. [http://forums.massassi.net/html/tongue.gif]

Quote:
<font face="Verdana, Arial" size="2">while (i<101)</font>


Using a counting variable to run a code block so many times is what the for loop was made for. Using while is no more inefficient, but using the for loop is a lot more convenient.

Quote:
<font face="Verdana, Arial" size="2">SetThingPos(grass0, grass_pos);</font>


SetThingPos() does not update a thing's sector when it moves it. So if you take the grass outside of sector 0, it will disappear. If this were MotS and you knew the sector, SetThingPosEx() would be useful.

Quote:
<font face="Verdana, Arial" size="2">Then use FireProjectile to create it, it makes sure that projectiles are within the limits of the sector.</font>


FireProjectile() also gives its projectile the correct sector if it is created in a sector other than the parent's, and it will not fire through walls. Creating the grass as a projectile's explosion is a much better solution that using SetThingPos().

Yeah, Seifer, that's how JK's arrays work - like a variable offset. Kudos to Fardreamer for posting that. [http://forums.massassi.net/html/wink.gif]

------------------
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
Author of the JK DataMaster, Parsec, Scribe, and the EditPlus Cog Files.
2002-10-02, 6:14 AM #12
Quote:
<font face="Verdana, Arial" size="2">Originally posted by Hellcat:
Is there away to not define the variables from 0 to 100? </font>


Quote:
<font face="Verdana, Arial" size="2">Originally posted by Descent_pilot:
GBK used heap verbs in a couple of his cogs </font>



Just to dispell any mythos surrounding them, the Heap verbs are perfectly stable. When used correctly - and they are a cinch to use - they never crash JK. I should know. I use them quite often.


Heaps are great for when you dont know whow many variables you'll need, or if the needed amount would be inconvenient to declare. Dont be afraid to use them.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.
2002-10-02, 11:37 AM #13
I am quite afraid to use them, but only due to my somewhat midieavl fear of that which I am unaware of.

Quote:
<font face="Verdana, Arial" size="2">
seifer
owns
</font>


Hehe.
Cordially,
Lord Tiberius Grismath
1473 for '1337' posts.
2002-10-02, 11:52 AM #14
Well, Im currently using them in 2 cogs for the GBK tools alone . . . perhaps more in the future (Im not sure just how many cogs I will include with it)...


I think Ive masterd them . . . perhaps I will write a tutorial... [http://forums.massassi.net/html/eek.gif]

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.
2002-10-02, 1:53 PM #15
Oh, that would be cool if you wrote a tutorial!

Thanks for the help people.
Team Battle.
2002-10-02, 5:48 PM #16
Yeah, I'd like a tutorial on those heap verbs of yours, GBK, They sound really useful!

And if its not too nosey, what exactly were you planning on doing with the grass cog, Hellcat? I could think of a few ideas, but i was just wondering. [http://forums.massassi.net/html/smile.gif]
2002-10-02, 7:07 PM #17
I was going to use it for my terrain level:

http://forums.massassi.net/html/Forum5/HTML/008734.html

But I will work on it later. For now I need to finish some other stuff before I get to the level [http://forums.massassi.net/html/biggrin.gif]


GBK does RVTCS control stuff like 3do view distances? If so when will it be released?
Team Battle.
2002-10-02, 7:21 PM #18
"View distances" is practically all that the rvtcs does control. If an object's position is within the specified range from the player, it exists. If not, it doesnt.


It isnt "released" yet, but it is perfected and MP compatable, and you can use it if you want... Email me.

------------------
I used to believe that we only want what we can't have. I was wrong. The truth is, the wonderful truth is, we only want what we think we can't have.

JK editing resources.
And when the moment is right, I'm gonna fly a kite.

↑ Up to the top!