conveyor belt help

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

conveyor belt help

Post by Nekoneko » May 1st, 2011, 8:45 am

Hey, I need help on a conveyor belt type script.
I have script_brushmodels in my map named stream_0 .... stream_12, since i was going to put it in water, making it a stream.

the code:

Code: Select all

main{
streament=[];
	while(isdefined(getent("stream_"+streament.size,"targetname")))
	{
		streament[streament.size]=getent("stream_"+streament.size,"targetname");
	}
	for(i=0;i<streament.size-1;i++){streament[i] thread stream(streament[i+1],streament[0].origin,streament[streament.size-1].origin);}
	streament[streament.size-1] thread stream(streament[0],streament[0].origin,streament[streament.size-1].origin);
}

stream(nextent,start,end)
{
while(1){
while(self.origin!=end){self moveto(nextent.origin,0.5);wait 0.5;iprintln("move");}
wait 0.5;
self.origin=start;
}
}
I know it sounds hard to understand, but it basically calls for every stream ent the stream function, with its next entity to go after, the start point of stream_0 and the end point of stream_12

It works, but they somehow randomly move around and the distance between them gets always bigger, until they disappear from the map :D

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: conveyor belt help

Post by Drofder2004 » May 1st, 2011, 9:18 am

Over complicating things.
Get a single part of the stream working to go the correct route. Then set the steps to go off at an interval.

Look around the maping section, somebody has devoted his life to making things similar to this in the form of escalators :P
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: conveyor belt help

Post by IzNoGoD » May 1st, 2011, 9:23 am

Code: Select all

main
{
	streament=[];
	while(isdefined(getent("stream_"+streament.size,"targetname")))
	{
		streament[streament.size]=getent("stream_"+streament.size,"targetname");
	}

	start=streament[0].origin;
	end=streament[streament.size-1].origin;
	speed=300;

	for(i=0;i<streament.size-1;i++)
	{
		streament[i] thread stream(start,end,speed);
	}
}
stream(start,end,speed)
{
	while(true)
	{
		self moveto(end, distance(self.origin,end)/speed);
		wait distance(self.origin,end)/speed;
		self.origin=start;
	}
}
Edit: you set your start/end positions to be dynamic AKA using an entity's origin as start/end, but when you try to "get" that origin in a thread, it checks where said entity is NOW, and cause that entity is moving on its own too, all gets fucked up. xD
Last edited by IzNoGoD on May 1st, 2011, 9:25 am, edited 1 time in total.
LMGTFY!

Its not a glitch... Its the future!

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: conveyor belt help

Post by Nekoneko » May 1st, 2011, 9:23 am

ah lol. ye i saw him (had like 10 different escalators)
But most ones i saw were hardcoded, like they manually put in the start and the endorigin + this one should go over curves.
Ill still go check them out tho.

Edit: well it should check where the next entity is now, so they all follow each other.

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: conveyor belt help

Post by IzNoGoD » May 1st, 2011, 10:23 am

Well, try this:

Code: Select all

 
main
{
        streament=[];
        origins=[];
        while(isdefined(getent("stream_"+streament.size,"targetname")))
        {
                streament[streament.size]=getent("stream_"+streament.size,"targetname");
                origins[streament.size-1]=spawnstruct();
                origins[streament.size-1].origin=streament[streament.size-1].origin;
        }
 
        speed=300;
 
        for(i=0;i<streament.size-1;i++)
        {
                streament[i] thread stream(origins,i,speed);
        }
}
stream(origins,current,speed)
{
        while(true)
        {
                while(current<origins.size)
                {
                        self moveto(origins[current+1].origin,distance(self.origin,origins[current+1].origin)/speed);
                        self waittill("movedone");
                        current++;
                }
                current=0;
                self.origin=origins[current].origin;
        }
}
should follow the line.
LMGTFY!

Its not a glitch... Its the future!

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: conveyor belt help

Post by Nekoneko » May 1st, 2011, 12:31 pm

Sounds good.
Ill try it out, but what is spawnstruct() ?
is it just some placeholder to get the origins ?

IzNoGoD
CJ Worshipper
CJ Worshipper
Posts: 343
Joined: January 6th, 2009, 8:39 pm
Location: Netherlands/Holland

Re: conveyor belt help

Post by IzNoGoD » May 1st, 2011, 1:02 pm

spawnstruct() spawns a structure.

Example:

Code: Select all

thisisnotanentity=something;
Will not produce any errors

Code: Select all

thisisnotanentity.somesubvar=something;
Will produce errors, as the thisisnotanentity var is, well, not an entity. This can be solved by making the var into a structure, by using

Code: Select all

thisisnotanentity=spawnstruct();
Now, the var is a structure, and you can define 1 (one) more level of vars.

Take a look at this:

Code: Select all

player.primaryweapon="kar98k_mp";
This will not produce any errors, but

Code: Select all

player.primaryweapon.name="kar98k_mp";
player.primaryweapon.ammo=90;
player.primaryweapon.clip=5;
Will produce an error, but if you add the spawnstruct(); on top of it, it wont:

Code: Select all

player.primaryweapon=spawnsctruct();
player.primaryweapon.name="kar98k_mp";
player.primaryweapon.ammo=90;
player.primaryweapon.clip=5;
Adding one more level requires you to spawn another struct:

Code: Select all

player.weapon=spawnstruct();

player.weapon.primary=spawnstruct();
player.weapon.primary.name="thompson_mp";
player.weapon.primary.ammo=200;
player.weapon.primary.clip=20;

player.weapon.secondary=spawnstruct();
player.weapon.secondary.name="mp44_mp";
player.weapon.secondary.ammo=180;
player.weapon.secondary.clip=30;
You can add any number of layers there.
Good luck with it
LMGTFY!

Its not a glitch... Its the future!

Nekoneko
CJ Fan
CJ Fan
Posts: 170
Joined: April 18th, 2011, 3:48 pm

Re: conveyor belt help

Post by Nekoneko » May 1st, 2011, 4:26 pm

Hm. Interesting.
Nice to know, thanks.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13313
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Re: conveyor belt help

Post by Drofder2004 » July 16th, 2011, 9:31 pm

mr-cool wrote:spawnstruct really seems to be useful function. i think, there will be no problem now in conveyor belt problem.
cheers,
is this a bot?
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Moustache
CJ Worshipper
CJ Worshipper
Posts: 476
Joined: August 18th, 2008, 9:30 am

Re: conveyor belt help

Post by Moustache » July 17th, 2011, 11:32 am

@IzNoGoD:
Thanks for the great explanation, I didn't knew that.

And your script should give an error, you have main it should be main() of course :oops:

Post Reply

Who is online

Users browsing this forum: No registered users and 35 guests