Forum

> > Stranded II > Scripts > Calling all sheep
Forums overviewStranded II overview Scripts overviewLog in to reply

English Calling all sheep

19 replies
To the start Previous 1 Next To the start

old Calling all sheep

ModJuicer
Super User Off Offline

Quote
Is there a possibility that I can make all of one type of unit (or object or item or info) respond to the same code.
ex. make all sheep on island five times as big, purple and walking backwards.
something like this
1
2
3
4
on:start{
	scale -5,-5,5 ((something that makes it affect all sheep));
	color 152,0,255 ((something that makes it affect all sheep));
}
edited 1×, last 07.04.18 06:10:58 pm

old Re: Calling all sheep

Nova
User Off Offline

Quote
You can create a s2 cmd loop which only loops through the class "units" and the type ID of sheeps. To get the ID, move your mouse over the sheep icon in the map editor.
Pleace notice that scale doesn't change the collision boxes of units, and that you have to do the changes to color and scale every time you load the map, so better use on:load instead of on:start.

old Re: Calling all sheep

JasJack67
Super User Off Offline

Quote
Why not just change the "scale" and the "color" in the definition of the unit itself? That would make them all bigger and a different color?

Doing it ON:START or ON:LOAD is not needed if that is the only time your meaning to effect all of one type unit...just change it's definition in the units.inf file.

If you want to effect them "during" game play then a loop is needed.

example:
1
2
3
4
5
6
7
8
9
if(count("unit",14)>=1){                           //first see if any even exist
	loop("units", 14){                            //set loop to loop sheep ID
		$loop_id = loop_id();                   //assign a variable to the looping ID
		if(lives("unit", $loop_id) == 1){       //check to see if the unit is living
			color 100,100,100;
			scale -5,-5,5;
		}
	}
}

Note: after line #3 the sheeps ID is no longer 14, but is the variable $loop_id until the loop is finished looping. Everything after line #3 inside the loop that is referring to the units ID will be the assigned variable $loop_id...not the sheeps ID 14. (as you see in line 4)

You could put that script in a on:hit command or on:changeday or anything else, depending on when you want them all to be "affected". Even with a timer.
edited 3×, last 08.04.18 02:34:27 pm

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
So it would change the Id? I don't know if that would help anything. Maybe I could skip line 3... Wait, could I just keep the id the same by using 14 for that?

old Re: Calling all sheep

Nova
User Off Offline

Quote
Ignore that about changing the ID. There are two types of IDs in the game: a type ID and a object ID. It's not so easy to distinguish them because the game and the website call them the same. Type ID are unique for every class - all objects have object type IDs, all units have unit type IDs...

Every kind of object, unit, info, ... has its own type ID. Sheeps have the unit type ID 15. One of the big trees with vines has the object type ID of 15. These two are different because one is a unit and the other is an object.
Let's say you now place 3 sheeps on a new map in the editor. These sheeps all have the unit type ID of 15, but they also all have another kind of ID - the first placed sheep has the ID 100, the second the ID 101 and the third the ID 102.

If you want to loop through all sheeps you have to state the type and type ID of sheeps in the loop parameters. These are "units" and 15. If you now want to scale a sheep you have to state the typ and the unit ID. These are "unit" and (for example) 100. This would scale the first placed sheep on our example map.

I will write an example here. Please create a new map and just place one sheep on it. Now write this into the global script and then start the map by pressing F12.
1
2
3
4
5
6
7
8
9
10
on:load
{
	loop("units", 15)
	{
		$loop_id = loop_id();

		color 100, 100, 100, "unit", $loop_id;
		scale -3, -3, 3, "unit", $loop_id;
	}
}

Now you have a big, backwards walking sheep on your map.
The script works like this: First we say the game to execute this script every time the map / save is loaded. We need to do this because scaling and color changes are not saved with the map. The script itself loops through all units with the type ID 15. For every unit with that ID the script under the loop will be executed - we first save the current loop ID in the variable $loop_id. It will change for every unit and contain the ID of the sheep. Then we color and scale the unit with the loop ID. If you have for example 10 sheeps on your island, the inner functions will be called 10 times.

(Please notice that the unit type ID of sheeps is 15, not 14.)

old Re: Calling all sheep

JasJack67
Super User Off Offline

Quote
hmm...like i said, there is no point in doing this in an ON:LOAD command when all you have to do is set the COLOR and SCALE in the units DEFINITION. The unit will automatically spawn with its definition variables already set.


### Sheep
id=15
name=Sheep
group=animal
icon=gfx\sheep.bmp
model=gfx\sheep.b3d
colxr=25.............................set collision x
colyr=18.............................set collision y
scale=0.8............................set scale
color=255,255,255.................set color
behaviour=animal
health=100
speed=0.6
turnspeed=0.5
mat=flesh
ani_idle1=6,11,0.01
ani_idle2=11,13,0.01
ani_idle3=14,18,0.1
ani_move=1,2,0.02
ani_die=19,20,0.1
sfx=sheep
script=start

you can also scale using scale x, scale y, and/or scale z

...and don't ignore that about changing ID...inside the loop you have to re-define the ID using a variable...as is stated with the loop command, loop_id() is required with any loop. As you see Nova did the same thing i said to do using a variable $loop_id in line 7 and 8 as the ID...why ignore that when it very important to make a loop actually work.

Quote
Wait, could I just keep the id the same by using 14 for that?
No you can not the loop will not recognize the id.
edited 3×, last 13.04.18 12:04:15 am

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
will it keep looping like a cache 22 or something if the id's the same? idk anyway, the script isn't working well 4 me. I will probably need 2 research more on the code. Could someone just show me a code that will work 4 me and so I can use it and get used to it? Thanks
FRESH
edited 1×, last 13.04.18 05:25:51 am

old Re: Calling all sheep

JasJack67
Super User Off Offline

Quote
no, it just will not loop the units at all, cuz you didn't use loop_id() like the command loop requires to function. ya see? loop and loop_id() are both required for any loop to function.

It should also throw an error in debug mode, just do not remember for certain.

please note:
You do not have to use the variable $loop_id but it seems logical and is common here. Any variable would work:

$loop_id = loop_id():
$loopvar = loop_id():
$tmp= loop_id():
$any_var = loop_id():

Then use that variable for the ID within the loop...simple really.

There are instances where you may want to use the EXIT command to exit the loop at a specific time...example: I want to loop sheep until the dead sheep is found and then delete the dead sheep...THEN EXIT the loop. No need to continue looping sheep if it found the dead one and deleted it already. You can also use it to exit the loop for other reasons depending on what your trying to script. Got it?

format:
loop
     if{ script;
     }else{
          exit;
     }

or

     if{ script;
          exit;
     }

Quote
Could someone just show me a code that will work 4 me and so I can use it and get used to it? Thanks
I already did. Goto the /sys folder open unit.inf scroll to sheep ID=15 and just change the definitions of the sheep's scale and color. You don't need a script to do this on:load. YOU CAN make a script to run at on:load, im just saying you do not need to. YOU HAVE TO MAKE SURE THE SCRIPT YOU WRITE RUNS AFTER THE SHEEP ARE CREATED WHEN LOADING...IF IT RUNS PRIOR TO THE CREATION OF SHEEP THEN IT WILL NOT WORK CUZ NO SHEEP EXIST YET. You can achieve this by using a timer...set it for say 5000 so it will run 5 seconds later after every thing is created/loaded including the sheep.

Lastly, put the on:load script in the game.inf file not attached to the sheep in unit.inf or you will have a sheep trying to loop other sheep, that is different, you want the game to loop the sheep. If you want to attach on:load to the sheep you do not need a loop or on:load...just add the following script:

1
2
3
4
on:create{
	color 100,100,100;
	scale 5,5,5;
}

use on:create not on:load if attaching it to a sheep it'self...you then need to adjust the sheeps collision size in its definition manually using colx=, coly= or you will have a tiny collision spot on a huge sheep cuz collision does not automatically scale with the model.
edited 9×, last 13.04.18 06:27:24 am

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
I don't want to edit the main script, that's why I'm asking this question. Can U just upload a script that shows how to to do it IN ONE ISLAND? Plz, I'm not really good at reading directions as I am at figuring them out by myself. Thanks.

old Re: Calling all sheep

JasJack67
Super User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//adjust 3000 higher if needed

	on:load{
		timer 0,3000,1,"sheep";
	}

	on:sheep{
		if(count("unit",15)>=1){
			loop("units", 15){
				$loop_id = loop_id();
				color 100,100,100,"unit", $loop_id;
				scale 5,5,5,"unit", $loop_id;
			}
		}
	}

Put that in the game.inf file. I still think you would have to change the colyr= and colxr= in the sheep definition though, I do not recall a command to change the collision in script. So the sheep may have a tiny hitbox depending on how big you make them. The timer may need adjusted higher so on:sheep runs after the sheep is created when loading.

You can add a message temporarily to on:sheep to find out if the sheep where created first like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
//with message

	on:sheep{
		if(count("unit",15)>=1){
			loop("units", 15){
				$loop_id = loop_id();
				color 100,100,100,"unit", $loop_id;
				scale 5,5,5,"unit", $loop_id;
			}
		}else{
			msg "No sheep created!",3,20000;
		}
	}
edited 3×, last 17.04.18 07:05:55 pm

old Re: Calling all sheep

Nova
User Off Offline

Quote
@user JasJack67: I refer to this quote from you:
user JasJack67 has written
Note: after line #3 the sheeps ID is no longer 14, [...]

The sheep type ID is still 15, that didn't change. The loop and the scale/color command just use different kinds of IDs.


Changing the definition of sheeps sounds like no good idea. You would change EVERY sheep, on every map. You would also have to send these changed definition with your map if you want other players to play your stuff. Things like big, backwards walking sheep also don't sound like they should be standard, but that depends on what you want to achieve.

user JasJack67 has written
YOU HAVE TO MAKE SURE THE SCRIPT YOU WRITE RUNS AFTER THE SHEEP ARE CREATED WHEN LOADING...IF IT RUNS PRIOR TO THE CREATION OF SHEEP THEN IT WILL NOT WORK CUZ NO SHEEP EXIST YET. You can achieve this by using a timer...set it for say 5000 so it will run 5 seconds later after every thing is created/loaded including the sheep.

Are you sure about that? As far as I know, the load events are only fired after loading all the other stuff, including the units. Then again, I didn't write much for Stranded II in ages, so maybe I just don't remember that stuff exactly.
But even if this is the case, 1 millisecond should be enough. The game doesn't load stuff on the fly, but only at the beginning when the save is loaded / the map started. After 1 frame everything should be loaded, and a timer with 1 ms will wait at least until the next frame as far as I understand the game engine.

@user ModJuicer: What exactly didn't work about my script? I tested it and it worked without problems for me.

old Re: Calling all sheep

JasJack67
Super User Off Offline

Quote
Well, within the loop the ID 15 is not used, a variable you assigned to it, is used. That was my point. Ofcoarse the sheeps ID is still always 15...but ya don't use 15 in the loop do ya?

As far as the timer...yeah that is why I said you may need to adjust the timer, as for my mod my on:load is huge and there are things I want to happen in order , when loading...so in some cases the timer may need to be longer or shorter depending on your mod/scripts. I have actually found it useful to set a longer timer on:load for other reasons I won't get into here as to not derail his thread. I was just informing him, as he still has to create his script the way he needs it, to get his results.

He stated your on:load script wasn't working for some reason. I am giving him an alternative because he may have other things going on in his scripts that you and I are not aware of....I'm not saying your wrong about anything...but ya shouldn't tell someone to ignore what I say in my post... that's just rude.
edited 1×, last 21.04.18 01:28:15 pm

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
Quote
1
2
3
4
5
6
7
8
9
10
on:load
{
     loop("units", 15)
     {
          $loop_id = loop_id();

          color 100, 100, 100, "unit", $loop_id;
          scale -3, -3, 3, "unit", $loop_id;
     }
}

this code?

old Re: Calling all sheep

Nova
User Off Offline

Quote
Yes.
Please create a new map and just place one sheep on it. Now write this into the global script and then start the map by pressing F12. That will turn every sheep on the island into a big, horrible looking, backwards walking monster.

If you have any other question / if the script doesn't work for you, just ask.

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
Thanks so much it works perfectly
p.s. How can I add states ex. invulnerability object types in gameplay?
edited 1×, last 24.08.18 09:28:24 pm

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
For some reason addstate isn't working for me. Maybe I'm doing it wrong. If you can make the script work for you, plz post it. Thanks

old Re: Calling all sheep

Nova
User Off Offline

Quote
You didn't mention any script so I don't know what you're talking about. You need to post it if you want someone to look at it.

old Re: Calling all sheep

ModJuicer
Super User Off Offline

Quote
Oh. Can you show me a script anyway? I'm busy updating my mod webpage for Stranded II Enhanced . I might post it when I'm done.
p.s. a titanium platform almost complete for S2 Enhanced, I have now fixed the bugs that stopped people from modding platforms, and I have added an "everything on it" version for people who want everything but don't have the time and/or skill to add the Extensions - check it out!
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview