English Scripting Questions

2,429 replies
Goto Page
To the start Previous 1 2 ... 119 120 121 122 Next To the start
17.02.11 07:58:11 pm
Up
EngiN33R
Moderator
Offline Off
So I was writing a script for a storage,
Code:
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!
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 08:02:45 pm
Up
Hurri04
Super User
Offline Off
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.
17.02.11 08:07:15 pm
Up
EngiN33R
Moderator
Offline Off
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?
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 08:12:16 pm
Up
Kirschkaffee
User
Offline Off
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?
17.02.11 08:15:11 pm
Up
Hurri04
Super User
Offline Off
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.
17.02.11 08:16:45 pm
Up
EngiN33R
Moderator
Offline Off
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.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 08:20:58 pm
Up
Hurri04
Super User
Offline Off
if you were so kind to post the whole script again we most likely would be able to help you better
17.02.11 08:31:00 pm
Up
EngiN33R
Moderator
Offline Off
This WAS the whole script It's applied to a storage, so a script in an entity in-game.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 08:35:50 pm
Up
Kirschkaffee
User
Offline Off
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
17.02.11 08:44:19 pm
Up
EngiN33R
Moderator
Offline Off
Code:
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;
          }
     }
}
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 08:53:48 pm
Up
Hurri04
Super User
Offline Off
so how about changing the rest of the things I mentioned earlier?
17.02.11 08:57:22 pm
Up
EngiN33R
Moderator
Offline Off
Oops, it must be the old version, sorry!
Code:
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;
          }
     }
}
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 09:07:53 pm
Up
Hurri04
Super User
Offline Off
Code:
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
17.02.11 09:08:42 pm
Up
Kirschkaffee
User
Offline Off
Code:
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.
17.02.11 09:14:23 pm
Up
EngiN33R
Moderator
Offline Off
Sadly, it does not work.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 09:16:32 pm
Up
Kirschkaffee
User
Offline Off
which one, and whats wrong now?
17.02.11 09:32:42 pm
Up
EngiN33R
Moderator
Offline Off
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
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
17.02.11 09:38:20 pm
Up
Kirschkaffee
User
Offline Off
is the console showing up some errors? if yes, then type debug and try again and then show us the report.
17.02.11 09:39:24 pm
Up
Hurri04
Super User
Offline Off
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
17.02.11 10:19:24 pm
Up
Kirschkaffee
User
Offline Off
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:

Code:
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 2 ... 119 120 121 122 Next To the start