Scripting Questions
2,429 replies So I was writing a script for a storage,
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!
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}
}
}
$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
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.
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.
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.

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.
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
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?
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
closemenu but prevent it from even opening via
skipevent.
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


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.
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
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
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
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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;
}
}
}
$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
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
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;
}
}
}
$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
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}
}
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
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
}
}
$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.
Sadly, it does not work.
I code, therefore I exist. | Visit my blog for Lua tips and other interesting info
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

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
is the console showing up some errors? if yes, then type debug and try again and then show us the report.
I dont see any problem with my script.
if fact the storage shouldnt even be opening because there is no
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.
if fact the storage shouldnt even be opening because there is no

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
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:
It worked fine on EnginEEr.
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
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";
}
}
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