Page 1 of 1
conveyor belt help
Posted: May 1st, 2011, 8:45 am
by Nekoneko
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

Re: conveyor belt help
Posted: May 1st, 2011, 9:18 am
by Drofder2004
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

Re: conveyor belt help
Posted: May 1st, 2011, 9:23 am
by IzNoGoD
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
Re: conveyor belt help
Posted: May 1st, 2011, 9:23 am
by Nekoneko
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.
Re: conveyor belt help
Posted: May 1st, 2011, 10:23 am
by IzNoGoD
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.
Re: conveyor belt help
Posted: May 1st, 2011, 12:31 pm
by Nekoneko
Sounds good.
Ill try it out, but what is spawnstruct() ?
is it just some placeholder to get the origins ?
Re: conveyor belt help
Posted: May 1st, 2011, 1:02 pm
by IzNoGoD
spawnstruct() spawns a structure.
Example:
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
Now, the var is a structure, and you can define 1 (one) more level of vars.
Take a look at this:
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
Re: conveyor belt help
Posted: May 1st, 2011, 4:26 pm
by Nekoneko
Hm. Interesting.
Nice to know, thanks.
Re: conveyor belt help
Posted: July 16th, 2011, 9:31 pm
by Drofder2004
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?
Re: conveyor belt help
Posted: July 17th, 2011, 11:32 am
by Moustache
@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
