Scripts / Playing with the Door LUA script having fun...

Author
Message
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 20th Jan 2014 00:46
Hi Guys I am playing with the Door.lua script having so much fun..

I think this could be the opening to some great stuff...



I have attached a PDF file to show what can be done



Hope it helps someone..
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 20th Jan 2014 07:06
Thanks for this, I'll have a look. I'm quite new to LUA

almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 20th Jan 2014 14:33
ok so this is the script for the door so far. but its locked as default



-- LUA Script - precede every function and global member with lowercase name of script + '_main'

-- Door Prompts 'Closed' can be opened with entity collected specified by 'USE KEY'



-- state to ensure user must release E key before can open/close again

door_pressed = 0



function door_main(e)

PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;

PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;

PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;

PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

if PlayerDist < 100 then

if g_Entity[e]['activated'] == 0 then

if g_Entity[e]['haskey'] == 1 then

Prompt("The door is locked. Press E key to unlock door");

if g_KeyPressE == 1 then

g_Entity[e]['activated'] = 1;

end

else

Prompt("The door is locked. Find a key to unlock door");

end

else

if g_Entity[e]['activated'] == 1 then

-- door is unlocked and closed

Prompt("Press E to open door");

if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then

SetAnimation(0);

PlayAnimation(e);

g_Entity[e]['animating'] = 1;

g_Entity[e]['activated'] = 2;

PlaySound0(e);

CollisionOff(e);

door_pressed = 1;

end

else

if g_Entity[e]['activated'] == 2 then

-- door is open

if g_KeyPressE == 1 and g_Entity[e]['animating'] == 0 and door_pressed == 0 then

SetAnimation(1);

PlayAnimation(e);

g_Entity[e]['animating'] = 1;

g_Entity[e]['activated'] = 1;

PlaySound1(e);

CollisionOn(e);

door_pressed = 1;

end

end

end

end





so my question is how to make it so the gate is unlocked by default?

and not needing a key?

as its not always the case with a door being locked, just closed.

this would be a great help later on im sure

have fun stay safe

hood
PM
Uman
GameGuru TGC Backer
20
Years of Service
User Offline
Joined: 22nd Oct 2004
Location:
Posted: 20th Jan 2014 16:54
I have tested the door and script a little earlier - see screen shot attached.



I am using the default door script, building and door you see in the screen shot and you can see the result. Ignore the distance the door is from the building as its placed away from the building so I can select it as an entity. Small entities like this cant be selected otherwise when a large entity is in the way apparently.



Anyway point being the result is the door does not animate (swing) but simply raises itself off the ground as seen. It does however end up with the collision turned off so you can walk through it into the building once key activated.



All in all not working as yet and personally I would not know why as much of everything seems to be hard coded and not working or very well at the moment.



Emrys
11
Years of Service
User Offline
Joined: 4th Nov 2013
Location: UK
Posted: 20th Jan 2014 17:05
Hi Uman, I maybe wrong but door you're using has no animation assigned to it so it doesn't know what do with the door when it's opening / closing.



/thanks for the info JC !



PM
Uman
GameGuru TGC Backer
20
Years of Service
User Offline
Joined: 22nd Oct 2004
Location:
Posted: 20th Jan 2014 17:17
Hi E30Legend,



Is there any other default stock door which comes with Reloaded then? I had not found one.



LeeBamber
TGC Lead Developer
24
Years of Service
User Offline
Joined: 21st Jan 2000
Location: England
Posted: 20th Jan 2014 18:40
If you drop down the chainlink fence gate, the key_iron and then edit the gate to enter Key in the field Use Key, then run. You can collect the key and open the gate with it

Hogging the awesome since 1999
J0linar
GameGuru TGC Backer
14
Years of Service
User Offline
Joined: 3rd Feb 2010
Location: Vienna, AT
Posted: 20th Jan 2014 20:46
@Lee

I have noticed something with the door, if you stay close and start sprinting you can run thru it, there might be some glitch somewhere

http://j0linar.carbonmade.com/
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Jan 2014 00:02 Edited at: 21st Jan 2014 00:47
thanks, works well!

i'm completely new to LUA so this might be inaccurate (have only ever done some basic coding with DBPro so forgive me if i'm making things difficult for myself but this at least makes sense for me)



anyway i added more annotations so you can see what each part does - should help people like me make some sense of the statements





if u want the door to not require a key use this code (still need to press E to open / close the door and leave the 'use key' field in the gate/door entity empty and if u dont want the messege on screen just remove the "prompt" line from the code (i'm sure there is an easier way but it works)





also it's worth testing any coding with the chain gate as LeeBamber said as it has an actual animation for opening and closing while all that the door does is get slightly higher off the ground (which you can stop by making it static) however both will become passable (no collision) once opened



@J0linar

i could not reproduce that, maybe u opened it by accident?

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
J0linar
GameGuru TGC Backer
14
Years of Service
User Offline
Joined: 3rd Feb 2010
Location: Vienna, AT
Posted: 21st Jan 2014 01:20
@smallg

hmm i will try to record it when i get from work/ should be sleeping by now



and thanks for the annotations, this should greatly help.

http://j0linar.carbonmade.com/
PM
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 21st Jan 2014 01:35
could not get the script for an unlocked door to work with reloaded, got tried to call nil or something like that error

have fun stay safe

hood
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Jan 2014 12:50 Edited at: 21st Jan 2014 12:58
tried to call nil error is a script error yh, i also had that when i renamed one of the exsisting scripts, did u maybe try calling it something other than door.lua?

edit; if u want to call the file something else you need to change the following code part
to




also remember to reload FPS creator after u edit the script



i forgot to mention if u use the gate entity u do need to update the 'main' field (under the AI scripts in game) from default.fpi to door.lua as well but that wouldnt cause your issue

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 21st Jan 2014 13:41
ah, I did rename the door actually, didn't think about it but its called "door unlocked" will get to it and do that now lol thanks a lot .



this might be why my sound loop script don't work also lol, will have to test them both now with the mods will let you know how it gets on

have fun stay safe

hood
PM
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 21st Jan 2014 13:55
well I got a new error after changing just the bit you said lol, something like door unlocked.lua.7 expected somewhere said yes engine did not crash but gate did not even show text when close to it ah I must be a doing something wrong somewhere lol. never mind I will test more later on tonight

have fun stay safe

hood
PM
AuShadow
GameGuru TGC Backer
11
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 21st Jan 2014 14:47
Maybe if you set'if g_Entity[e]['activated'] == 0 then, to == 1, early in the code it would set the door as unlocked, just thinking of a quick fix, because == 1 is unlocked but closed state I believe but I could be wrong

Just a hobbyist but hey putting together a FPSC Reloaded wiki with links to mods, effects and tutorials, made it fully public so anyone can edit it if anyone wants to help out anyway, here's the link,,,, very basic atm



http://fpscrresource.wikispaces.com/home
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 21st Jan 2014 18:01
@hood no spaces allowed i guess so use "door_unlocked.lua"



@aushadow "because == 1 is unlocked but closed state I believe" yep that would be correct, i see what u are saying but i think if u do that it kinda messes up the later checks and the door wo
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 21st Jan 2014 23:25
Hi Guys sorry I have not been on for a while..



I have been playing with this door code and can now Unlock the door with the key but you now have to find a remote lever to open and close the door but first the lever is stuck you need to find some oil to free it up.



All using the same Door Open Lock code I showed in my first post PDF as a starting template. You end up with two script files...

door_key_remote_lever.lua and remote_lever1.lua

I will be making another PDF to show this and I will attach the code files so you can play with it.



@Hood I had a little go at your problem - and it had me scratching my head a few times.. I could not believe what was happening on some of my attempts

but I did come up with some thing.. I will attach two files

door_no_lock.lua and door_use_lock.lua



They are both the same code but with diff names and a variable set to 1 or 0 to turn on or off the Key-lock part of the code...

Also remember to make sure the Door/Gate entity has the Use property set to nothing ( not using Key ).. this tripped me up swapping between using the lock and not using the lock...

The other nice thing about the editor is you can change the script on the fly with out going to the FPE file just right click on the Door and in the properties you will see the script it is using just press inside this name and you can choose another script.. once you are satisfied all is working then you should make the script name change in the FPE file.

Hope this helps..
PM
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 21st Jan 2014 23:29
Sorry did not realize I could only attach 1 file.. hear is the door_use_lock
PM
almightyhood
11
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 22nd Jan 2014 00:50
YAY tried and tested works perfectly thanks those scripts are added to my library of game assets now along with some music thanks again j_c nice 1

have fun stay safe

hood
PM
J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 23rd Jan 2014 21:11
Hi everyone

Here is my new adventure with the DOOR LUA script.



In this

- You find the key

- unlock the door

- but you can't open or close it here. You must find a hidden lever

- when you find the leaver it's stuck - you need some oil

- you find the oil and free the lever.

- you use the lever to open the remote door.



- oh and I added a function to try and show more than one prompt

for each door action . To try and tell more of a story.

( only one on screen at one time

they show one prompt wait then show the next..)

It's not as good as having all on screen at same time

We will have to wait for more Lee updates to get this..



Hope you enjoy it..
PM
Teabone
Forum Support
18
Years of Service
User Offline
Joined: 8th Jun 2006
Location: Earth
Posted: 24th Jan 2014 06:47
Just realized something, if you put a custom folder in the scriptbank and attempt to run your scripts out of there it wont work if it requires references from global.lua.



So you basically have to keep all your scripts in the root "scriptbank"

J_C
17
Years of Service
User Offline
Joined: 9th Nov 2007
Location:
Posted: 24th Jan 2014 13:38
global.lu



Dang! how did I miss that - I was having so much fun with door.lua I must have blinded myself to the global.lua silly silly me..



I just can't remember reading this.. thanks for this little prod in the right direction Teabone.. more toys to play with...
PM
BarZaTTacKS
10
Years of Service
User Offline
Joined: 3rd Feb 2014
Location:
Posted: 12th Feb 2014 17:00 Edited at: 12th Feb 2014 17:02
If you get the NIL value error it is because the file name of the LUA has to be the same as the name you have inside the script right before the main. Example below, the bold "door" part is what you should duplicate the file name to.





function door_main(e)

PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;

PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;

PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;

PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));
PM

Login to post a reply

Server time is: 2024-12-21 18:59:31
Your offset time is: 2024-12-21 18:59:31