Forum

> > Stranded II > Scripts > Scripting Questions
Forums overviewStranded II overview Scripts overviewLog in to reply

English Scripting Questions

2,429 replies
Page
To the start Previous 1 2112 113 114121 122 Next To the start

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
Jesterhead37 has written
Edit- Also, is there a way to make it that when I use attack2, it uses a different kind of behavior? for example, using a melee attack with a pistol?

1
2
3
4
5
6
7
8
9
10
on:attack2 {
	$target=scantarget([MELEE RANGE]);
	if(targetdistance()<[MELEE RANGE]) {
		$tclass=targetclass();
		if($tclass>0) {
			$tid=targetid();
			damage "$tclass", $tid, [DAMAGE-VALUE];
		}
	}
}
sorry, I dont know any solution for the other problem you have. my guess is that is has something to do with the speed that the unit moves with, but I also might be wrong with that.





@amstel bier9:
1
2
3
4
5
6
7
8
9
10
11
on:drop {
	local "$did";
	$did=currentid();
	timer "items", $did, [LENGHT OF TIME], 1, "sys\dfree.s2s";
}

on:create {
	local "$did";
	$did=currentid();
	timer "items", $did, [LENGHT OF TIME], 1, "sys\dfree.s2s";
}
this script goes into the defintion script of the pistol.
there have to be the two events on:dop and on:create because the on:drop event seems to be only triggered if there are no other items of that type left in your inventory, otherwise it triggers the on:create event. little bug in S2...

next you have to create a new file in your sys folder and call it "dfree.s2s".
open it with any text editing tool and write the following script into it:
1
free "self";

old Re: Scripting Questions

Xaeveax
User Off Offline

Quote
Alright thanks! I'll be putting that to use shortly. It's fine about the other thing. I think I might just not bother using it.

old Re: Scripting Questions

Psytechnic
User Off Offline

Quote
Hurri04 has written
sorry, I dont know any solution for the other problem you have. my guess is that is has something to do with the speed that the unit moves with, but I also might be wrong with that.


Ah hah! Your idea might have lead me to the answer!

When defining animations for units, one of them is "ani_attack=<start frame>,<end frame>,<speed of animation>"

I'm not sure about this, but maybe attacking is linked to animation, allowing only one attack per animational loop. If you make the play speed of the attack animation slower, it could reduce the number of attacks.

This is just a theory and I'd love to know how it is calculated, even if I'm wrong.

old Re: Scripting Questions

Xaeveax
User Off Offline

Quote
Yes! Your idea worked! I slowed the time from 0.5 to 0.01 and it had about a ten second gap between each attack! Brilliant guess!

old Re: Scripting Questions

pupp3tStudios
User Off Offline

Quote
haha Ideas work! Cookies for everyone cookie
On-topic:
when your riding a vehicle, how can you make it so that it can "shoot" bullets from froma section of its model? I made a jeep w/a turret on top. The height of the turret from the ground is the height of the pirate's body, for a good estimation.

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
write this script into the game.inf file above the line "script=start":
1
scriptkey=00, Jeep_Shooting
then write this below the line "script=start":
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
on:keyhit00 {event "jeep_shooting_start", "global";}
on:keyrelease00 {event "jeep_shooting_stop", "global";}

on:jeep_shooting_start {
	$jeep_riding=riding();
	if(type("unit", $jeep_riding)==[TYPE-NUMBER OF THE JEEP]) {
		timer "unit", $jeep_riding, [TIME BETWEEN TWO SHOTS], 0, "jeep_shot";
	}
}

on:jeep_shot {
	$jeep_shot_x=getx("unit", $jeep_riding);
	$jeep_shot_y=gety("unit", $jeep_riding);
	$jeep_shot_z=getz("unit", $jeep_riding);
	$jeep_shot_yaw=getyaw("unit", $jeep_riding);

	projectile [TYPE OF AMUNITION], $jeep_shot_x, $jeep_shot_y, $jeep_shot_z, 3, 2, $jeep_shot_yaw, [OFFSET], 0, [SPEED OF BULLETS], [DAMAGE DONE PER BULLET];
}

on:jeep_shooting_stop {
	freetimers "unit", $jeep_riding;
}
important:
choose an offset at the s2 cmd projectile command which is big enough so the bullet is spawned right in front of the opening of the turret and NOT anywhere behind it or in its rail. with an offset of 0 the bullet spawns right in the middle of the jeep's model (where the x-, y- and z- axis connect in your modelling programme).
you can put e.g. an area trigger at the very same position as the jeep in the editor and enter a value for the radius so you can have a better look at how big the offset has to be.
better make it a little bit too big than too small, when you are sitting in the jeep and firing bullets you cant see the point where the bullets appear anyway.

it also might be that you have to adjust the hight at which the bullet is spawned, you can easily do that by writing
1
$jeep_shot_y+=[ADDITIONAL HIGHT];
right after the command where the value is saved into the y-variable.


note: to try this out in-game you have to go to the options and select a certain key for the new scriptkey first.

old Re: Scripting Questions

Xaeveax
User Off Offline

Quote
This is probably easy, but what would the script be so that when I use an item, it shows a message. Not the message that comes on the left of the screen, but the one like msgbox's. The one that i would put in the definitions. I was guessing its something like :

on:attack2 {
     msg "[name]","[source]";
     }

But, I'm not sure. is that right? I want it to be a part of the item, not just one one map.

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
@amstel bier:
I'm afraid that this doesnt work properly, as you e.g. can see at the spikes from S1: there are no such in S2.

you might try to use the definition "behaviour=closekill" from the bang mushrooms but I dont know whether this is what you want.




@Jesterhead:
if you want a messagebox to appear then you have to use the command for it: s2 cmd msgbox:
1
2
3
on:attack2 {
	msgbox "title", "source";
}
and: yes, when you write this into the definition script of an item this wil lwork on every map.

old Re: Scripting Questions

amstel bier9
User Off Offline

Quote
mm.. ok,
and if i make a unit of it?
is it then posseble that i can stand on the unit,
cause I want lava.. and when you walk on it you will been hard hitting or just dying.
already thanks,

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
well... I guess you could try to use this script (adapted from the spike trap from the Extension Mod):
1
2
3
4
5
6
7
8
behaviour=closetrigger
var=radius,Radius,50,0
var=active,Aktiv,1,0
script=start
on:trigger {
	kill 1;
}
script=end

the problem is that this has to be an object because units cant have the closetrigger behaviour.
so if you want the lava to be animated you could try to make the actual lava a unit and then write a script into its definition script which creates an invisible cube (object) with the definition I wrote above on:edset + on:create at the same position where the lava has been created.

old Re: Scripting Questions

pupp3tStudios
User Off Offline

Quote
I'm not sure if this is considered a scripting question or a newbie question, but is it possible to make a unit have two behaviors instead of one? I'm trying to make an animal that can attack you, and get into the water. So when you think it's safe to be in the water, it follows you

old Re: Scripting Questions

Xaeveax
User Off Offline

Quote
Sounds cool Pupp3t. There is a way to do that, but I don't know it off by heart. I think it was Hurri04 that showed me.

Oh, and does anyone know how to make it that a unit will only come out at night? Like, around 20:00 (gametime) to around 7:00?

old Re: Scripting Questions

UnIdEnTiFiEd
User Off Offline

Quote
@jesterhead37 A nocturnal animal? defenanlty nothing ive tried before. but i think extention mod has it for the bat.

old Re: Scripting Questions

Xaeveax
User Off Offline

Quote
Yeah it does. I tried copy pasting the script but it didnt seem to do anything...

Edit- Sorry for all the questions, but how do you save sound effects so that they will be played by units? Lets say I have a... dog. I name the definition as sfx=dog. Right? Then I add the WAV sound effects called dog_idle1, dog_idle2, dog_spot, etc... does the game automatically run them? Or do I need to fix something up? Cuz they arent playing...

Edit AGAIN - nevermind. I found it out. though it plays em all at the same volume whether im right next to the unit or far away...
edited 2×, last 29.11.10 01:07:47 pm

old help

gusanos33
User Off Offline

Quote
hey how to build flying obiects ?
please help ! ;[

Sorry for bad english (polish user_
edited 1×, last 29.11.10 05:46:28 pm

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
Pupp3t has written
I'm not sure if this is considered a scripting question or a newbie question, but is it possible to make a unit have two behaviors instead of one? I'm trying to make an animal that can attack you, and get into the water. So when you think it's safe to be in the water, it follows you


you have to define the unit two times, one with the land-behaviour and one with the water-behaviour.

try to use the commands s2 cmd timer, s2 cmd playerdistance, s2 cmd getx, s2 cmd gety, s2 cmd getz, s2 cmd setpos, s2 cmd getyaw, s2 cmd setrot, s2 cmd create and s2 cmd free to start a local timer for each unit with a frequenz of about 1 second.
whenever this timer is being triggered check the distance between the unit at which the timer runs and the player,
then, if the player is so close that he definitely is being chased, check the hight of the unit (y) and if its low enough (normally a little avove 0, just try it out), then
create a new unit at the same place with the same rotation and free the old one.
if the original one was the land-unit spawn a water-unit and the other way around.

I'm not sure how good this will work, it might be a litle laggy when there are too many units of that type are after the player but there is no other way to do it (except of editing the source code).





@Jesterhead37:
well, unfortunately there are no events like on:8pm or on:7am, this would make the whole trick a lot easier.
but instead of that you can run a test map in the editor where you have to some settings first:
the map has to start on 0 o'clock on the first day
and on:changeday there should be a s2 cmd msg or s2 cmd msgbox or something.
then you best place an "arcarde game" info so you wont get hungry, thirsty or tired.

then you have to take a stop watch, start the map and wait while you stop the time in reallife it takes for one day ingame.
then you divide the value by 24 to get the time it takes for one ingame hour.

with this knowledge you can start a global timer which will activate each ingame hour by writing the solution of the little calculation in seconds into the s2 cmd timer command.
whenever this timer is activated a variable is increased by 1 so you can use the s2 cmd if command then to start an s2 cmd event (for each value of the variable a different one!) and on:changeday the variable is being set back to 0 manually to ensure that it stays synchronous.
you dont need to make 24 events if you dont need that many, of course. but the reset of the variable definitely has to be done.
I think you then can use the command s2 cmd ai_center to move the units from a secure place to the open (e.g. bats: cave -> open) and back.





@gusanos33:
it is impossible to build objects in the air ingame.
what you can do is move objects upwards when you are in the editor mode by pointing the mouse at the object and pressing space. by doing this three orbs at the end of three lines that are arranged in right angles and form a corner will appear. by clicking and holding the mouse button at one of the orbs you then can moce it into different directions.
to dissable this mode again, simply press space a second time.

old Re: Scripting Questions

pupp3tStudios
User Off Offline

Quote
Yeah, I just downloaded the source code and Blitz 3D. So, I'm gonna try and see if I can edit the codes and stuff. I'm not sure how, but I'll try heh.
To the start Previous 1 2112 113 114121 122 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview