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 2119 120 121 122 Next To the start

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
So I was writing a script for a storage,
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
on:start{
	$ironstoragelocked=true;
}

on:use{
	if ($ironstoragelocked==true){
		msg "I need a key!",3;
		speech "negative";
		closemenu;
	}else{
		local $gotornot=playergotitem 92;
		if ($gotornot>0){
			$ironstoragelocked=false;
			play "crack1.wav";
			speech "positive";
			msg "I opened it!",4;
		}
	}
}
And apparently, the closemenu part doesn't work, because I hear the negative speech, a message appears, but the storage still opens. Maybe I used a wrong command? Help please!

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
if you want to use word in variables you have to put quotation marks around them.
but I recommend to use numbers instead so you should replace the "true" with "0".

also you cant put a value into a variable in the same line in which you declare it to be local, further the name of the variable which you want to be local has to be written in quotation marks.

then there is the mistake that you have to use brackets around the parameter(s) of commands which return a value. s2 cmd playergotitem is one of these.

next you should replace the "false" with a "1" but the place where this line is written is completely wrong because this line is only executed if the variable it sets to 1 is 1. you see that it makes no sense because it would never be set to 1 that way.

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
Thanks for the tips, I fixed my errors, the script works without any errors - as it was earlier - though my main problem is not solved.
EngiN33R has written
the closemenu part doesn't work, because I hear the negative speech, a message appears, but the storage still opens. Maybe I used a wrong command?

old Re: Scripting Questions

Kirschkaffee
User Off Offline

Quote
maybe you should try a skipevent; in the part with the negative speech instead of closemenu, as far as i can see there aint no menu to be closed?

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
so as the variable is called "ironstoragelocked" I guess you made a new model for some iron storage like the wood storage and the stone storage in the original game...?

in this case you have to see that there is no menu opened at the time you use the storage - which is the very same time when the script is triggered.
so because of this you dont have to close the menu via s2 cmd closemenu but prevent it from even opening via s2 cmd skipevent.

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
I did not make a new model, just a storage with a lot of iron in it, hence iron storage.

skipevent still doesn't work - I replaced closemenu with it, just so you know.

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
if you were so kind to post the whole script again we most likely would be able to help you better

old Re: Scripting Questions

Kirschkaffee
User Off Offline

Quote
i think, Hurri wanted you to post the changed script. there has to be something wrong, if even the skipevent doesnt work, for it cancels the whole on:use

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
on:start{
	$ironstoragelocked=true;
}

on:use{
	if ($ironstoragelocked==true){
		msg "I need a key!",3;
		speech "negative";
		skipevent;
	}else{
		local $gotornot=playergotitem 92;
		if ($gotornot>0){
			$ironstoragelocked=false;
			play "crack1.wav";
			speech "positive";
			msg "I opened it!",4;
		}
	}
}

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
Oops, it must be the old version, sorry!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
on:start{
     $ironstoragelocked=1;
}

on:use{
     if ($ironstoragelocked==1){
          msg "I need a key!",3;
          speech "negative";
          skipevent;
     }else{
          local $gotornot=playergotitem (92); //if I understood you correctly
          if ($gotornot>0){
               $ironstoragelocked=0;
               play "crack1.wav";
               speech "positive";
               msg "I opened it!",4;
          }
     }
}

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
on:use{
	if(playergotitem(92)>0){	// if the player has a key ...
		$ironstoragelocked=1;	// 1 is unlocked
	}

	if ($ironstoragelocked==0){	// if it is locked (because it wasnt unlocked earlier because the player has no key)
		msg "I need a key!",3;
		speech "negative";
	}else{	// if it is unlocked
		play "crack1.wav";
		speech "positive";
		msg "I opened it!",4;
	}
}
that is all you need.
actually this script is a very easy one.

have you read the scripting tutorial yet?
edited 2×, last 17.02.11 09:55:10 pm

old Re: Scripting Questions

Kirschkaffee
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
on:start {
	$ironstoragelocked=0;
}

on:use {
	if ($ironstoragelocked==0) {
		msg "I need a key!",3;
		speech "negative";
	}
	elseif (playergotitem(92)>=1) {
		$ironstoragelocked=1;
		play "crack1.wav";
		speech "positive";
		msg "I opened it!",4;
	}
}

Try this. you dont need a special local variable for the playergotitem-request, you just have to care about the id is in brackets. Also string like "true" or "false" have to be in quotation marks when declaring variables like your that. i changed them with 0 for true and 1 for false.

I am not quite sure, whether you really have to declare the ironstoragelocked-variable in the start-event at all, for being a 0 means it is true, and by default an empty variable is 0, but it doesnt harm being declared.

old Re: Scripting Questions

EngiN33R
Moderator Off Offline

Quote
The one you sent, crate still opens. Now if you would just stop optimizing the script and try and fix the script so it would do its job

P.S. I added you on Skype.
EDIT1: Oh, I'll try Hurri's last one.
EDIT2: Hurri's one not working either

old Re: Scripting Questions

Hurri04
Super User Off Offline

Quote
I dont see any problem with my script.
if fact the storage shouldnt even be opening because there is no s2 cmd exchange command in the script which opens the storage.

Edit: found the problem.
you have to leave the skipevent; line away completely as there actually is no menu which opens or has to be prevented from opening because it only opens with the exchange command but as this command is not written in this part of the first if-check you just have to leave the skipevent; away and it should work fine.
edited 1×, last 17.02.11 09:54:38 pm

old Re: Scripting Questions

Kirschkaffee
User Off Offline

Quote
Okay here is the solution. There seems to be a problem with storage-objects.

On Mapping create a rock instead of a storage, into the rock this script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
on:load {
	model "gfx/storage.b3d";
	scale 1,1,1;
}

on:use {
	if (playergotitem (92)>0) {
		$a=1;;
	}

	if ($a==0) {
		msg "I need a key!",3;
		speech "negative";
	} else {
		play "crack1.wav";
		speech "positive";
		msg "I opened it!",4;
		exchange "self";
	}
}

It worked fine on EnginEEr.
edited 3×, last 17.02.11 11:14:29 pm
To the start Previous 1 2119 120 121 122 Next To the start
Log in to reply Scripts overviewStranded II overviewForums overview