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 259 60 61121 122 Next To the start

old Re: Scripting Questions

Gradir
User Off Offline

Quote
you can make it s2 cmd stopmusic on timer, or you could make it like:
1
process "listening",2000,"stopmusic_event";
and add a global event (in the game.inf) -
1
2
3
4
on:stopmusic_event
	{
	stopmusic;
	}

old Diary

Shadowacher
User Off Offline

Quote
Hey could anyone give me an example of adding a diary? I tried adding my own, but when I start the map, the diary menu pops up but it is empty.

old To shadowacher

Firecat
User Off Offline

Quote
A diary can be made it from two ways:

In the code
Put in your code this thing:
1
2
3
4
5
6
7
8
on:start {
clear;
	add "Hello";
	add "This is the text";
	add "thats all";
	diary "yay";
	free "self";
}
s2 cmd clear clears previous texts.
s2 cmd add puts the mensage.
s2 cmd diary is the diary laucher and the title.
s2 cmd free does not allow a repeat (i think).
Outside the code
Put in your code this thing:
1
2
3
4
on:start {
	diary "yay","diary.txt:*:","diary01";
	free "self";
}
Create a text file in Stranded folder/mods/Stranded II called diary(Or the name that you put in the ∗) and put in the text this:
1
2
3
4
5
//~diary01
Hello.
This is the text.

!4Green mensage

twice ways works so use the best.

aaand also thanks Gradir and DontKnowToScript for the help, but actually i start a new idea .

old Re: Scripting Questions

Shadowacher
User Off Offline

Quote
Thank you Firecat it worked great.

I have a few more questions though. How do I make a unit say something else after an event happens. I need a pirate to say something after I kill a group of snails. And could somebody put an example of adding the fire state? I tried but it says script error.

Also, is there a way to make an item explode or do damage to the player when used?
edited 2×, last 22.02.09 03:39:13 am

old Re: Scripting Questions

bezmolvie
User Off Offline

Quote
Why, as usual, isn't the following working: Timer wont work-it wont stop u from attacking, and the modes wont change.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#Iron Sword
id=933
name=Iron Sword
group=weapon
icon=gfx\sword.bmp
model=gfx\sword.b3d
scale=1.6
behaviour=blade
mat=metal
weight=1000
damage=3
info=A simple Iron sword
healthchange=0
script=start
	on:impact {
		$tmp=impact_class();
		$tmp2=impact_id();
		//+14 Bonus Damage on Flesh
		if (compare_material("$tmp",$tmp2,"flesh")==1){
			damage "$tmp",$tmp2,14;
			if (skillvalue("Sword")>=500){
				damage "$tmp",$tmp2,20;
				addstate "$tmp",$tmp2,"bleeding";
			}elseif (skillvalue("Sword")>=420){
				damage "$tmp",$tmp2,15;
				$tmp3=random (1,2);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=360){
				damage "$tmp",$tmp2,12;
				$tmp3=random (1,4);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=250){
				damage "$tmp",$tmp2,8;
				$tmp3=random (1,5);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=200){
				damage "$tmp",$tmp2,5;
				$tmp3=random (1,8);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}
			if ($swordattack==2) {
				$noattack=1;
				timer "unit",1,750,0,"swordtimer";
				damage "$tmp",$tmp2,6;
				$swordtimer=1;
			}elseif($swordattack==3){
				$noattack=1;
				timer "unit",1,1250;
				$swordtimer=1;
				heal "$tmp",$tmp2,5;
				$tmp4=random (1,15);
				if($tmp4==5){
					kill $tmp2;
				}
			}
		}
		freevar $tmp;
		freevar $tmp2;
		freevar $tmp3;
		freevar $tmp4;
		if (health("$tmp",$tmp2)==0){
	event "iskill_swordmaster","global";
		}
	}
	on:swordtime{
		$noattack=0;
		msg "ready",4;
		freetimers "unit",1;
	}
	on:attack1{
		if ($noattack==1){
			skipevent;
		}
	}
	on:use{
		event "attack2";
	}
	on:attack2{
		$swordattack+=1;
		if($swordsetattack==1) {
			msg "Slash",4;
		}elseif($swordsetattack==2) {
			msg "Lunge",2;
		}elseif($swordsetattack==3) {
			msg "Bash",3;
		}
	}
script=end
also, this is in unit 1 (player)
1
2
3
4
5
on:timer{
		if ($swordtimer==1){
			event "swordtime","global";
		}
	}

old Re: Scripting Questions

Gradir
User Off Offline

Quote
I don't get it, I don't know what are these vars like $swordattack and $swordsetattack
but I guess you should name the event on Unit 1 (player) on:swordtimer not on:timer ?

Anyway...
while testing my mod I've came upon a problem with cooking things while dropping near fire:
I didn't know that throwing things works also like dropping (event on:drop is executed while you throw things)
Now I need a way to prevent the script from going on while player THROWED an item, not DROPPED it, or I'd have to change the item's behaviour to "killthrow"

In fact the question is: how to block the ability to throw?

EDIT
never mind I used:
1
2
on:attack1
	{ skipevent; }
and it works fine
edited 2×, last 23.02.09 02:11:43 pm

old Re: Scripting Questions

bezmolvie
User Off Offline

Quote
ty. the vars are different... ill fix that...And it still dosn't work. Timers are non-existant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#Iron Broadsword
id=932
name=Iron Broadsword
group=weapon
icon=gfx\broadsword.bmp
model=gfx\broadsword.b3d
scale=1.6
behaviour=blade
mat=metal
weight=1250
damage=5
info=An iron sword with a very broad blade.
healthchange=0
script=start
	on:impact {
		$tmp=impact_class();
		$tmp2=impact_id();
		//+19 Bonus Damage on Flesh
		if (compare_material("$tmp",$tmp2,"flesh")==1){
			damage "$tmp",$tmp2,19;
			if (skillvalue("Sword")>=500){
				damage "$tmp",$tmp2,20;
				addstate "$tmp",$tmp2,"bleeding";
			}elseif (skillvalue("Sword")>=420){
				damage "$tmp",$tmp2,15;
				$tmp3=random (1,2);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=360){
				damage "$tmp",$tmp2,12;
				$tmp3=random (1,4);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=250){
				damage "$tmp",$tmp2,8;
				$tmp3=random (1,5);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}elseif (skillvalue("Sword")>=200){
				damage "$tmp",$tmp2,5;
				$tmp3=random (1,8);
				if ($tmp3==1) {
					addstate "$tmp",$tmp2,"bleeding";
				}
			}
			if ($swordattack==2){
				$noattack=1;
				timer "self",750;
				heal "$tmp",$tmp2,7;
				$swordtime=1
			}elseif($swordattack==3){
				$noattack=1;
				timer "self",1250;
				damage "$tmp",$tmp2,8;
				$tmp4=random (1,10);
				$swordtime=1
				if($tmp4==5){
					kill $tmp2;
				}
			}
		}
		freevar $tmp;
		freevar $tmp2;
		freevar $tmp3;
		freevar $tmp4;
		if(lives("$tmp",$tmp2)==1){
			event "iskill_swordmaster","global";
		}
	}
	on:attack1{
		if ($noattack==1){
			skipevent;
		}
	}
	on:use{
		event "attack2";
	}
	on:attack2{
		$swordsetattack++;
		if($swordsetattack==1) {
			msg "Slash",4;
		}elseif($swordsetattack==2) {
			msg "Lunge",2;
		}elseif($swordsetattack==3) {
			msg "Bash",3;
		}elseif($swordsetattack==4) {
			$swordsetattack=1;
			msg "Slash",4;
		}
	}
script=end
plus this in player (unit 1)
1
2
3
4
5
6
7
on:swordtimer{
		if ($swordtimer==1){
			$noattack=0;
			msg "ready",4;
			freetimers "unit",1;
		}
	}
edited 1×, last 24.02.09 10:25:57 pm

old Re: Scripting Questions

Gradir
User Off Offline

Quote
I'm trying to assign an object to the player so it will move when the player moves. Anyone thinks it's possible?

old Re: Scripting Questions

Tau
User Off Offline

Quote
very difficult... I assume the best workaround is a timer set to 0.05 seconds or something, asking for the players position and subtracting the previous positions, then changing the object's position depending on the values gained before. I have no idea how it could be done more elegant without touching the source. Maybe theres a way with game.inf but I don't know x_X.

old Re: Scripting Questions

DC
Admin Off Offline

Quote
yes. for this you need an event which is executed very frequently. create a 1 ms timer. it will be executed each frame.

then use s2 cmd setat "object",id,"unit",1; to set the item to the player position.
afterwards use s2 cmd setrot "object",id,0,getyaw("unit",1),0; to set the yaw rotation of the object to the rotation of the player.
finally use s2 cmd rpos "object",id,0,0,10; to move the object to the front of the player (if you want to have it in his front). you have to test around here. 10 might be okay but maybe you have to use a higher or lower value there to even see the object.

I didn't test it but that's the way it *SHOULD* work. maybe you also have to change the height of the object (setat will set it to the feet of the player).

please note that this takes a lot of speed and can slow down the whole game on pcs with a slow cpu because it has to parse your script each frame!

old Re: Scripting Questions

Gradir
User Off Offline

Quote
Thanks!
After experiments with making a unit that would follow the player I've read your posts and this works great. I just have to work a bit on rotation cause it doesn't want to work fine (if you look at one direction, the object is on the left side of screen, and if you look in the opposite direction, it's on the right side of the screen, while I want it to stay on one side, hmm)

old Re: Scripting Questions

DC
Admin Off Offline

Quote
try setrot "object",id,0,(getyaw("unit",1)+45),0; or something like that and try different values for +45 before moving it with rpos. you can also replace the two zeros in rpos to move the object on other axis.

old Re: Scripting Questions

Gradir
User Off Offline

Quote
Ok! It's working great with this basic code:
1
2
3
4
$id=currentid();
		setat "object",$id,"unit",1;
		setrot "object",$id,0,getyaw("unit",1),0;
		timer "self",30,1,"checkpos";
here is the result:
http://www.goplany.net/~gradir/screen0105.jpg

now I'm wondering how to make one texture on the object shiny and another not shiny, like on pistol model...

old Re: Scripting Questions

bezmolvie
User Off Offline

Quote
Im still having trouble with the sword. the timers arnt working and the bash/lunge wont do extra damage...

old Re: Scripting Questions

Gradir
User Off Offline

Quote
make sure the skill "Sword" is indeed "Sword" not "sword"

I don't know what are the vars "swordattack", "swordtime" and "swordtimer" - maybe they're supposed to be both "$swordtime"?
I'm pretty sure that phrase " timer "self",1250; " won't work until you make an on:timer event on that item, I'd suggest adding new events, and changing it to, for example
timer "self",1250,1,"newevent";

I also don't get this part:
1
2
3
4
5
6
freevar $tmp;
          freevar $tmp2;
          freevar $tmp3;
          freevar $tmp4;
          if(lives("$tmp",$tmp2)==1){
               event "iskill_swordmaster","global";
- You're freeing the vars and using them in the next line

old Immortal Sheep

CJ80
User Off Offline

Quote
I've looked all over for an answer to this question but no dice, hoping someone here can find what I'm missing -

I can't kill my sheep. I can beat them for hours with any number of weapons that kill all the rest of the animals, but the sheep won't die. The unit file has been tinkered with heavily, but I can't seem to see what would make a sheep immortal. Any help would be appreciated - The code is below:


### Sheep
id=15
name=Sheep
group=animal
icon=gfx\sheep.bmp
model=gfx\sheep.b3d
colxr=25
colyr=16
scale=7
behaviour=animal
health=5
speed=0.4
turnspeed=0.5
ani_idle1=4,9,0.01
ani_idle2=9,11,0.01
ani_idle3=12,15,0.01
ani_move=2,3,0.02
ani_die=15,16,0.1
sfx=sheep
loot=9,2
loot=96,1
loot=4943,1
loot=4982,4

script=start
     //Spawn 2xWool at Start
     on:start {
          local $id, $milk;
          $id=create("item",48,0,0,2);
          store $id,"self";
          freevar $id;
          $milk= (random(4));
     }
     //Add 3xWool per Night
     on:changeday {
          if (count_stored("self",48)<15){
               local $id;
               $id=create("item",48,0,0,3);
               $milk++;
               store $id,"self";
               freevar $id;
          } local $sheep;
if ((count_inrange("unit",15,$mapz,"self"))<20){
$sheep+=count_inrange("unit",15,250,"self");
if ($sheep>2){
if ($sheep<6){
if (random(10)=1){
create "unit",15,getx("self"),getz("self");
}
}
}
freevar $sheep;
}
     }
     //Get Wool on Use
     on:use {
          if (getplayerweapon()==106){
               if (playergotitem(106)>0){
                    if (health("self")>0){
                         if ($milk>0){
                              play "sheep_idle1.wav";
                              freestored "unit",1,106,1;
                              find 4953;
                              $milk--;
                         }else{
                              speech "negative";
                              msg "This sheep is all out of milk.",3;
                         }
                    }
               }
          }elseif (getplayerweapon()==4945){
               if (playergotitem(4945)>0){
                    if (health("self")>0){
                         if ($milk>0){
                              play "sheep_idle1.wav";
                              freestored "unit",1,4945,1;
                              find 4952;
                              $milk--;
                         }else{
                              speech "negative";
                              msg "This sheep is all out of milk.",3;
                         }
                    }
               }
          }elseif (count_stored("self")>0){
               if (health("self")>0){play "sheep_idle1.wav";}
               exchange "self",0;
          }else{
               msg "It has no wool!",3;
               speech "negative";
          }
     }
     
     //Whipping
     on:hit {
          ai_center;
     }
     //Kill
     on:kill {
          event "iskill_hunt","global";
          $s2g_sheepskilled++;
     }
script=end

old Re: Scripting Questions

Gradir
User Off Offline

Quote
Seems I can't help CJ80. Maybe, what would be strange, it's something with that code that spawns another sheep in the place of the first one... But it makes no sense

-------------
I'm still playing with visible player equipment... So far I've made a sleeve model which spawns when player have a clothing item in his inventory, and he equips a falchion:
SCREEN
the problem I encountered is, that the red sleeve model disappears when player is going forward and looking down at specific degrees (was it "pitch"? - around 75 points)
but I guess there is no way to fix it
To the start Previous 1 259 60 61121 122 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview