Forum

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

English Scripting Inquiries II

10 replies
To the start Previous 1 Next To the start

old Scripting Inquiries II

JasJack67
Super User Off Offline

Quote
So im working on a script that uses the sethour & setday commands. They work fine per debugging. I noticed that If I change the hour and day to something passed 0 hour, no plants spawntimer subtracts a day (adds a day) like it is suppose to.

So a plant with a growtime of 10 and a spawntimer of -9 will never mature as long as my script changes the day...INSTEAD of the changeday command when rolling over at midnight, or when you sleep passed the hour midnight (0).

Any idea what to add to a script to get the spawntimer to adjust correctly if I over-ride the changeday and sleep command? I have tried 100 different ways with using:

getlocal
setlocal

with using $tmp's... and $tmp=$tmp1+1...set $tmp1, im shorthanding this as an example, I tried to many ways to list here.

and also trying to force plants to the correct # with:

spawntimer ("self"), #;

If I stay awake at midnight with changeday at midnight the spawntimer works fine...it is about my over-riding that in a script when I change the day and hour...it does NOT work. Any ideas?

EDIT -----------------
Even after 100 tries using everything I could muster, i even tried to replace the plant when I changed the day...changing it to "plant" with a new correct spawntimer LOL and it really is a funny dam script. Cuz the event calls the plant to the original spawntimer. LOL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
on:time0 {
                  local $id,$id2,$tmp,$tmp1;
                        $id=currentid();
                        $tmp=spawntimer("self");
		              if ($tmp=-8){$tmp1=-7;
		              }elseif ($tmp=-7){$tmp1=-6;
		              }elseif ($tmp=-6){$tmp1=-5;
		              }elseif ($tmp=-5){$tmp1=-4;
		              }elseif ($tmp=-4){$tmp1=-3;
		              }elseif ($tmp=-3){$tmp1=-2;
		              }elseif ($tmp=-2){$tmp1=-1;
		              }elseif ($tmp>=-1){$tmp1=0;
                              }
                        $id2=create "object",114,getx("object",$id),getz("object",$id);
                        free "self";
                        event "plant","object",$id2;
                        spawntimer "object",$id2,$tmp1;
		              $needs=1;
		              timer "unit",1,1000,1,"farming";
                        freevar $id,$id2,$tmp,$tmp1;
}

I just wanted to show how hard I was trying to make it work
edited 2×, last 13.02.13 09:29:38 pm

old Re: Scripting Inquiries II

JasJack67
Super User Off Offline

Quote
thank you guys for your replies.

Ok Hurri I am going out on a limb and posting my script so maybe you can solve it...because I know your a freaking genius with this stuff

it's not perfect I know after I make it work I go back and clean it up as far as spacing and shorting anything I can.

but here goes nothing....

In my game.inf file I have taken power away from my on:sleep command as you will see with skipevent...I bring up my own menu where the players chooses 3 times to sleep, 3hours, 6hours, or 9 hours.

when I cut off the on:sleep and the player actually chooses a button, it leads them to the //Advance Time portion of the script, and then to sethour,setday commands. Heres where it got sticky. If the player slept over the 0 hour, no changeday event was taking place, because i skipped event on:sleep...BUT as you see I have added that so it WOULD happen (event "changeday")...with 3,6,9, hour sleep there is only a handful of hours that needed to be "redirected" for me to manually change the day and time. forcing a "changeday" event...those few hours have their own on:time# command way at the bottom.

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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
//Sleeping
	on:sleep {      
                        skipevent;
                        timer 0,1,1,"choosehours";
        }

        on:choosehours {
			clear;
			add "!4I have chosen to sleep. (AUTOSAVE)";                         
			add "!4How long should I sleep?";
                        add "";
                        add "!5If you are not under cover when sleeping, you";
                        add "!5will receive slight damage from the elements.";
                        add "";
                        add "!5Increased more the longer you sleep.";
                        add "!5Cover- Shelter, Hut, Treehouse, Tepee, Cave.";
                        add "";
                        add "!5Sleeping a full 9 hours regains more health";
                        add "!5per Survival skill level, then short sleep.";
			msgbox "Sleeping";
			button 0,"A quick 3 hours?",8,"click3";
			button 1,"A good 6 hours?",8,"click6";
			button 2,"A full 9 hours?",8,"click9";
			add "closemenu;";
			button 3,"Stay awake.",3;
        }
                        

	on:click9 {
		if (getplayervalue(4)>5){
			local $y;
			$y=gety("unit",1);
			if ($y>0){
				if (playerspotted()==0){
					if (((getplayervalue(2)>80)+(getplayervalue(3)>80))>0){ 
						speech "negative";
						msg "I am too hungry or thirsty to sleep now!",3;
						skipevent;
					}else{
						//Exhaustion
						consume 0,-45,-45,100;
		
						//Alcohol Stuff
						if ($s2g_alc>200){$s2g_alc=200;}
						$s2g_alc-=60;
						if ($s2g_alc<0){$s2g_alc=0;}

						//Free States
						freestate "unit",1,"dizzy";
						freestate "unit",1,"fuddle";

                                                //Lantern goes out
                                             if (count_stored("unit",1,4942)>=1){
		                                freetimers "self",1;
                                                freestate "unit",1,24;
                                                skipevent; 
                                                freestored "unit",1,4942;
                                                find 4937;
                                                find 4934;
                                                find 49;
                                                msg "The lantern has run out of oil!",3,6500;
                                             }

                                                //Handtorch goes out
			                     if (count_stored("unit",1,111)>=1){
                                                freetimers "self",1;
		                                freestate "unit",1,24;
                                                freestored "unit",1,111;
		                                find 24;
                                                msg "My handtorch has burned out",3,6500;
		                             }
                					
						//Damage if there is no Cover
					     if (count_behaviourinrange("object","cover")==0){
							$damage=random(12,20);
							damage "unit",1,$damage;
							freevar $damage;
						}else{
							//Treehouse Recover
							if (count_inrange("object",190)>0){
								consume 5,0,0,0;
							//Hut Recover
							}elseif (count_inrange("object",206)>0){
								consume 5,0,0,0;
							}
							$tmp1=skillvalue("survivor");
							$hp=((5+$tmp1)/5);
							heal "unit",1,$hp;
							freevar $tmp1,$hp;
                                                }

                                                //Advance Time
                                             if (hour()==23){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time23";
                                                closemenu;
                                             }
                                             if (hour()==22){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time22";
                                                closemenu;
                                             }
                                             if (hour()==21){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time21";
                                                closemenu;
                                             }
                                             if (hour()==20){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time20";
                                                closemenu;
                                             }
                                             if (hour()==19){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time19";
                                                closemenu;
                                             }
                                             if (hour()==18){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time18";
                                                closemenu;
                                             }
                                             if (hour()==17){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time17";
                                                closemenu;
                                             }
                                             if (hour()==16){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time16";
                                                closemenu;
                                             }
                                             if (hour()==15){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time15";
                                                closemenu;
                                             }
                                             if (hour()==14){sethour(23);closemenu;}
                                             if (hour()==13){sethour(22);closemenu;}
                                             if (hour()==12){sethour(21);closemenu;}
                                             if (hour()==11){sethour(20);closemenu;}
                                             if (hour()==10){sethour(19);closemenu;}
                                             if (hour()==9){sethour(18);closemenu;}
                                             if (hour()==8){sethour(17);closemenu;}
                                             if (hour()==7){sethour(16);closemenu;}
                                             if (hour()==6){sethour(15);closemenu;}
                                             if (hour()==5){sethour(14);closemenu;}
                                             if (hour()==4){sethour(13);closemenu;}
                                             if (hour()==3){sethour(12);closemenu;}
                                             if (hour()==2){sethour(11);closemenu;}
                                             if (hour()==1){sethour(10);closemenu;}
                                             if (hour()==0){sethour(9);closemenu;}
						       //Autosave
						       autosave;
                                                       play "sleep.wav";
                                                       msg "Game Saved!",4;
					  }
				}else{
					speech "negative";
					msg "I should not sleep now!",3;
					skipevent;
				}
			}else{
				speech "negative";
				msg "Sleeping in the water?",3;
				msg "Not a good idea...",3;
				skipevent;
			}
			freevar $y;
		}else{
			speech "negative";
			msg "I'm not tired enough!",3;
			skipevent;
		}
	}

	on:click6 {
		if (getplayervalue(4)>5){
			local $y;
			$y=gety("unit",1);
			if ($y>0){
				if (playerspotted()==0){
					if (((getplayervalue(2)>80)+(getplayervalue(3)>80))>0){ 
						speech "negative";
						msg "I am too hungry or thirsty to sleep now!",3;
						skipevent;
					}else{
					        //Exhaustion
						consume 0,-30,-30,45;
		
						//Alcohol Stuff
						if ($s2g_alc>200){$s2g_alc=200;}
						$s2g_alc-=60;
						if ($s2g_alc<0){$s2g_alc=0;}

						//Free States
						freestate "unit",1,"dizzy";
						freestate "unit",1,"fuddle";

                                                //Lantern goes out
                                             if (count_stored("unit",1,4942)>=1){
		                                freetimers "self",1;
                                                freestate "unit",1,24;
                                                skipevent; 
                                                freestored "unit",1,4942;
                                                find 4937;
                                                find 4934;
                                                find 49;
                                                msg "The lantern has run out of oil!",3,6500;
                                             }

                                                //Handtorch goes out 
			                     if (count_stored("unit",1,111)>=1){
                                                freetimers "self",1;
		                                freestate "unit",1,24;
                                                freestored "unit",1,111;
		                                find 24;
                                                msg "My handtorch has burned out",3,6500;
		                             }
                					
						//Damage if there is no Cover
						if (count_behaviourinrange("object","cover")==0){
							$damage=random(6,12);
							damage "unit",1,$damage;
							freevar $damage;
						}else{
							//Treehouse Recover
							if (count_inrange("object",190)>0){
								consume 6,0,0,0;
							//Hut Recover
							}elseif (count_inrange("object",206)>0){
								consume 6,0,0,0;
							}
							heal "unit",1,4;
					        }

                                                //Advance Time
                                             if (hour()==23){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time20";
                                                closemenu;
                                             }
                                             if (hour()==22){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time19";
                                                closemenu;
                                             }
                                             if (hour()==21){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time18";
                                                closemenu;
                                             }
                                             if (hour()==20){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time17";
                                                closemenu;
                                             }
                                             if (hour()==19){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time16";
                                                closemenu;
                                             }
                                             if (hour()==18){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time15";
                                                closemenu;
                                             }
                                             if (hour()==17){sethour(23);closemenu;}
                                             if (hour()==16){sethour(22);closemenu;}
                                             if (hour()==15){sethour(21);closemenu;}
                                             if (hour()==14){sethour(20);closemenu;}
                                             if (hour()==13){sethour(19);closemenu;}
                                             if (hour()==12){sethour(18);closemenu;}
                                             if (hour()==11){sethour(17);closemenu;}
                                             if (hour()==10){sethour(16);closemenu;}
                                             if (hour()==9){sethour(15);closemenu;}
                                             if (hour()==8){sethour(14);closemenu;}
                                             if (hour()==7){sethour(13);closemenu;}
                                             if (hour()==6){sethour(12);closemenu;}
                                             if (hour()==5){sethour(11);closemenu;}
                                             if (hour()==4){sethour(10);closemenu;}
                                             if (hour()==3){sethour(9);closemenu;}
                                             if (hour()==2){sethour(8);closemenu;}
                                             if (hour()==1){sethour(7);closemenu;}
                                             if (hour()==0){sethour(6);closemenu;}
						       //Autosave
						       autosave;
                                                       play "sleep.wav";
                                                       msg "Game Saved!",4;
                                          }
				}else{
					speech "negative";
					msg "I should not sleep now!",3;
					skipevent;
				}
			}else{
				speech "negative";
				msg "Sleeping in the water?",3;
				msg "Not a good idea...",3;
				skipevent;
			}
			freevar $y;
		}else{
			speech "negative";
			msg "I'm not tired enough!",3;
			skipevent;
		}
        }

	on:click3 {
		if (getplayervalue(4)>5){
			local $y;
			$y=gety("unit",1);
			if ($y>0){
				if (playerspotted()==0){
					if (((getplayervalue(2)>80)+(getplayervalue(3)>80))>0){ 
						speech "negative";
						msg "I am too hungry or thirsty to sleep now!",3;
						skipevent;
					}else{
					        //Exhaustion
						consume 0,-11,-11,20;
		
						//Alcohol Stuff
						if ($s2g_alc>200){$s2g_alc=200;}
						$s2g_alc-=60;
						if ($s2g_alc<0){$s2g_alc=0;}

						//Free States
						freestate "unit",1,"dizzy";
						freestate "unit",1,"fuddle";
                                                 
                                                //Lantern goes out
                                             if (count_stored("unit",1,4942)>=1){
		                                freetimers "self",1;
                                                freestate "unit",1,24;
                                                skipevent; 
                                                freestored "unit",1,4942;
                                                find 4937;
                                                find 4934;
                                                find 49;
                                                msg "The lantern has run out of oil!",3,6500;
                                             }

                                                //Handtorch goes out
			                     if (count_stored("unit",1,111)>=1){
                                                freetimers "self",1;
		                                freestate "unit",1,24;
                                                freestored "unit",1,111;
		                                find 24;
                                                msg "My handtorch has burned out",3,6500;
		                             }
                					
						//Damage if there is no Cover
						if (count_behaviourinrange("object","cover")==0){
							$damage=random(5,8);
							damage "unit",1,$damage;
							freevar $damage;
						}else{
							//Treehouse Recover
							if (count_inrange("object",190)>0){
								consume 4,0,0,0;
							//Hut Recover
							}elseif (count_inrange("object",206)>0){
								consume 4,0,0,0;
							}
							heal "unit",1,2;
                                                }

                                                //Advance Time
                                             if (hour()==23){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time17";
                                                closemenu;
                                             }
                                             if (hour()==22){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time16";
                                                closemenu;
                                             }
                                             if (hour()==21){
                                                event "changeday",0,0;
                                                timer 0,1,1,"time15";
                                                closemenu;
                                             }
                                             if (hour()==20){sethour(23);closemenu;}
                                             if (hour()==19){sethour(22);closemenu;}
                                             if (hour()==18){sethour(21);closemenu;}
                                             if (hour()==17){sethour(20);closemenu;}
                                             if (hour()==16){sethour(19);closemenu;}
                                             if (hour()==15){sethour(18);closemenu;}
                                             if (hour()==14){sethour(17);closemenu;}
                                             if (hour()==13){sethour(16);closemenu;}
                                             if (hour()==12){sethour(15);closemenu;}
                                             if (hour()==11){sethour(14);closemenu;}
                                             if (hour()==10){sethour(13);closemenu;}
                                             if (hour()==9){sethour(12);closemenu;}
                                             if (hour()==8){sethour(11);closemenu;}
                                             if (hour()==7){sethour(10);closemenu;}
                                             if (hour()==6){sethour(9);closemenu;}
                                             if (hour()==5){sethour(8);closemenu;}
                                             if (hour()==4){sethour(7);closemenu;}
                                             if (hour()==3){sethour(6);closemenu;}
                                             if (hour()==2){sethour(5);closemenu;}
                                             if (hour()==1){sethour(4);closemenu;}
                                             if (hour()==0){sethour(3);closemenu;}
						       //Autosave
						       autosave;
                                                       play "sleep.wav";
                                                       msg "Game Saved!",4;
				        }
				}else{
					speech "negative";
					msg "I should not sleep now!",3;
					skipevent;
				}
			}else{
				speech "negative";
				msg "Sleeping in the water?",3;
				msg "Not a good idea...",3;
				skipevent;
			}
			freevar $y;
		}else{
			speech "negative";
			msg "I'm not tired enough!",3;
			skipevent;
		}
        }

        on:time15 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(0);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time16 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(1);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time17 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(2);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time18 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(3);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time19 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(4);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time20 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(5);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time21 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(6);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time22 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(7);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }
        on:time23 {
                  local $tmp,$tmp2;
                  $tmp=day();
                  $tmp2=$tmp+1;
                  setday($tmp2);
                  sethour(8);
                  freetimers 0,1;
                  freevar $tmp,$tmp2;
        }

when I noticed that the spawntimers dont work on those 'handful" of hours, I was referring to my plants scripts specifically above ...so here is the on:changeday for them I refer too.

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
id=114
name=Corn
group=stuff
icon=gfx\cornstalk3.bmp
model=gfx\cornstalk3.b3d
fx=16
scale=0.4
swayspeed=2
swaypower=5
col=2
health=100
mat=leaf
growtime=9
var=water,Watered,0,0
var=needs,Needs,0,0
var=die,Die,2,0
var=watered,Effects,0,0
script=start
	on:examine {
		msg "It's a cornstalk.",0,2500;

	}
	
	on:kill {
		$tmp=1;
	        $tmp2=spawntimer("self");
		if ($tmp2>-5){$tmp=2;}
		if ($tmp2>-1){$tmp=3;}
                create "item",131,getx("self"),getz("self"),$tmp;
	        corona getx("self"),getz("self");
                freevar $tmp,$tmp2;
	}

	on:plant {
		spawntimer "self",-8;
		$needs=1;
		timer "unit",1,1000,1,"farming";
	}
	
	on:changeday {
                local $tmp,$tmp1;
                $tmp=spawntimer("self");
                $tmp1=$tmp+1;
                spawntimer "self",$tmp1;
                freevar $tmp,$tmp1;
		if ($difficulty > 1){
			if ($needs==(1)){
                                if (getweather()==1){
                     	                 timer "self",1,1,"watered";
				}
				if ($water==(0)){
					$die--;
				}
				if ($die==1){
					addstate "self", 9;	
				}
				$water=0;
				$watered=0;
                     	        freestate "self", 25;
				if ($die==0){
					play "crack2.wav";
					free "self";
				}
			}
		}
	}
	
	on:watered {
		if ($watered==0){
			        freestate "self", 9;
			        addstate "self", 25;
                                statecolor "self", 25, 0,100,120;
			        $watered=1;
			        $water=1;
			        if ($difficulty>2){
				      $die=2;
			        }else{
				      $die=3;
			        }
			        color 100,100,300;
			        timer "self",10000,1,"unwater";
		}
	}
	
	on:unwater {
		color 255,255,255;
	}
script=end

my on:plant command sets the spawntimer to -8 with a growtime of 9...the first 5 lines of the script on:changeday is where im having the trouble...trying to make the spawntimer reduce it's growtime by 1

p.s. I know the script can be shortened as those if hour commands I will change to elseif ofcoarse...im just trying to get it to work first and the spawntimer is just the last hurdle I cannot figure out why the dam plant wont grow cuz the spawntimer is not changing on my changing the day manually with setday().

p.p.s i dont know why the "code" tag didnt work above, wierd.
edited 5×, last 14.02.13 02:00:07 am

old Re: Scripting Inquiries II

Hurri04
Super User Off Offline

Quote
@user JasJack67: man, you should really learn how to use indentations/shifting. this is bad, really bad


here you go...
create a file in the sys folder, name it "sleeping.s2s" and write this into it:
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
page=sleeping_select_duration
title=Select the sleeping duration
text=start
!4I will go to sleep now.
!4This will autosave the game.

!5If possible I should find a cover
!5to protect myself from damage from
!5the elements while I sleep.

!5Fitting covers are:
!5A shelter, hut, treehouse, tepee 
!5or a cave.

!5The longer I sleep the more
!5refreshed I will feel.
!5A high survival skill will also
!5help to endure the night better.

!5How long shall I sleep?
text=end
button=sleeping9, Sleep for full 9 hours
button=sleeping6, Doze for 6 hours
button=sleeping3, Just nap for 3 hours

page=sleeping9
script=start
$sleeping_duration=9;
event "sleeping";
closemenu;
script=end

page=sleeping6
script=start
$sleeping_duration=6;
event "sleeping";
closemenu;
script=end

page=sleeping3
script=start
$sleeping_duration=3;
event "sleeping";
closemenu;
script=end

and this is the code for the rest of the sleeping, put that whereever your former script was. it has all 3 durations in it.
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//Sleeping
on:sleep {
	if (getplayervalue(4)>5){
		if (gety("unit",1)>0){	
			if (playerspotted()==0){
				if (((getplayervalue(2)>80)+(getplayervalue(3)>80))>0){
					speech "negative";
					msg "I am too hungry or thirsty to sleep now!",3;
					skipevent;
				}else{
					skipevent;
					dialogue "sleeping_select_duration", "sys\sleeping.s2s";
				}
			}else{
				speech "negative";
				msg "I should not sleep now!",3;
				skipevent;
			}
		}else{
			speech "negative";
			msg "Sleeping in the water?",3;
			msg "Not a good idea...",3;
			skipevent;
		}
	}else{
		speech "negative";
		msg "I'm not tired enough!",3;
		skipevent;
	}
}

on:sleeping {
	//Exhaustion
	consume 0,-45,-45,100;
	
	//Alcohol Stuff
	if ($s2g_alc>200){$s2g_alc=200;}
	$s2g_alc-=60;
	if ($s2g_alc<0){$s2g_alc=0;}
	
	//Free States
	freestate "unit",1,"dizzy";
	freestate "unit",1,"fuddle";
	
	//Lantern goes out
	if (count_stored("unit",1,4942)>=1){
		freetimers "self",1;
		freestate "unit",1,24;
		skipevent;
		freestored "unit",1,4942;
		find 4937;
		find 4934;
		find 49;
		msg "The lantern has run out of oil!",3,6500;
	}
	
	//Handtorch goes out
	if (count_stored("unit",1,111)>=1){
		freetimers "self",1;
		freestate "unit",1,24;
		freestored "unit",1,111;
		find 24;
		msg "My handtorch has burned out",3,6500;
	}
	 
	//Damage if there is no Cover
	if (count_behaviourinrange("object","cover")==0){
		if($sleeping_duration==9) {
			$damage=random(12,20);
		}elseif($sleeping_duration==6) {
			$damage=random(6,12);
		}elseif($sleeping_duration==3) {
			$damage=random(5,8);
		}
		damage "unit",1,$damage;
	}else{
		//Treehouse Recover
		if (count_inrange("object",190)>0){
			if($sleeping_duration==9) {
				consume 5,0,0,0;
			}elseif($sleeping_duration==6) {
				consume 6,0,0,0;
			}elseif($sleeping_duration==3) {
				consume 4,0,0,0;
			}
		//Hut Recover
		}elseif (count_inrange("object",206)>0){
			if($sleeping_duration==9) {
				consume 5,0,0,0;
			}elseif($sleeping_duration==6) {
				consume 6,0,0,0;
			}elseif($sleeping_duration==3) {
				consume 4,0,0,0;
			}
		}
		
		if($sleeping_duration==9) {
			$tmp1=skillvalue("survivor");
			$hp=$tmp1/5;
			$hp++;
			heal "unit",1,$hp;
		}elseif($sleeping_duration==6) {
			heal "unit",1,4;
		}elseif($sleeping_duration==3) {
			heal "unit",1,2;
		}
	}
	
	//Time forwarding
	$day=day();
	$hour=hour();
	$minute=minute();
	if(($hour+$sleeping_duration)>=24) {
		sethour 23;
		setminute 59;
		timer 0, 2000, 1, "sleeping_finish";
	}else{
		sethour ($hour+$sleeping_duration);
	}
	
	//Autosave
	autosave;
	play "sleep.wav";
	msg "Game Saved!",4;
}

on:sleeping_finish {
	sethour (($hour+$sleeping_duration)-24);
	setminute ($minute-2);
}

if you sleep over midnight then it'll set you to 23:59, wait 2 ingame-minutes which are about 2 seconds so it's 00:01 and the changeday event should be triggered naturally. then it starts a timer to set you to the right wake-up time.

use a fast s2 cmd timer and s2 cmd flash with the colour set to black to simulate that the player has his eyes closed and sleeps, idk.
there should also be some command to play the snoring sound...

also dont always use that s2 cmd freevar and s2 cmd temp shit, it's really useless if the variable is created again anyway when you sleep the next time

old Re: Scripting Inquiries II

JasJack67
Super User Off Offline

Quote
Hurri...your a madman!

hey...i did exactly as you said. When I click the Zzz sleep button in the character menu, the menu closes and nothing happens.
no sleeping....no menu...nothing, the character menu just closes.
so the skipevent/dialogue commands is not opening the .s2s file it appears? i don't see the problem.

EDIT....
ok I got the menu to open by making a on:dialogue1 command

1
2
3
4
}else{
     skipevent;
     timer 0,1,1,"dialogue1";
}
1
2
3
on:dialogue1 {
     dialogue "sleeping_select_duration", "sys\sleeping.s2s";
}
placing it right under the "skipevent"

Now when i hit the Zzz button to sleep the menu opens but no matter what time I chose to sleep 3,6,9 the window closes and nothing happens. It is weird to me cuz ONE TIME i hit the sleep 6 hours button it DID work but the hour was set to 0 hour instead of the correct time. i will try some things while I wait for your reply.

EDIT2...
So i lit a handtorch and when I hit the Zzz to sleep the torch should go out as a result...but it is not...so the .s2s file is not triggering the event "sleeping" at this time it appears....will keep looking.

EDIT3...

WOOHOOOO! GOT IT! ∗

i had changed 2 things: In this fist script I think you missed brackets around the sethour set minute command.
1
2
3
4
5
6
7
8
9
10
11
if(($hour+$sleeping_duration)>=24) {
          sethour 23;
          setminute 59;
          timer 0, 2000, 1, "sleeping_finish";
     }

     if(($hour+$sleeping_duration)>=24) {
          sethour(23);
          setminute(59);
          timer 0, 2000, 1, "sleeping_finish";
     }
and in the .s2s I add "global" to the event and that made it work!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
page=sleeping9
script=start
$sleeping_duration=9;
event "sleeping","global";
closemenu;
script=end

page=sleeping6
script=start
$sleeping_duration=6;
event "sleeping","global";
closemenu;
script=end

page=sleeping3
script=start
$sleeping_duration=3;
event "sleeping","global";
closemenu;

THANK YOU Hurri4! I love this script in comparison to what I had. I must again take my hat off to you bro. You must know I can't express my gratitude enough for your help around here...THANK YOU!
edited 3×, last 14.02.13 11:00:37 am

old Re: Scripting Inquiries II

Hurri04
Super User Off Offline

Quote
then does something happen when you press the 'Z' key on your keyboard or whatever you have assigned to sleep?

try to replace
1
event "sleeping";
in the lines 29, 36 and 43 with
1
timer 0, 1, 1, "sleeping";
maybe it just has to be delayed until the dialogue is closed.

note that it was half past 3 in the morning when I wrote this so there might be some errors included
I suggest you experiment with some different things. after all, you also want to learn something, right?

old Re: Scripting Inquiries II

Hurri04
Super User Off Offline

Quote
nice to see it works

to be honest I have no idea why there have to be brackets at the sethour and setminute commands. at the instances where I used them myself it only is because there is a calculation...


there's just another thing I noticed:
you might want to put the autosave stuff directly under my line 118 and another time into the "sleeping_finish" event so that it doesnt save at 23:59 when you haven't even slept to the end yet.

and you can remove line 110 ("$day=day();") as I didnt even need the day for it to work^^
To the start Previous 1 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview