Scripts / anyway to only show a prompt once? [question]

Author
Message
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 10th Feb 2017 23:37
So, i'm just now starting to dabble with LUA. i watched one of the broadcasts where they showed altering the doorauto.lua script to open only when your flashlight is turned on. so i tried some expansions on that a little bit. i thought "how could i make it hint towards the player they need to turn on their flashlight. so i added a line

if if g_Entity[e]['plrvisible'] == 1 and g_PlayerFlashlight == 0 then
Prompt("it's too dark to see the locks")

(sorry i don't know how to use the snippits option) of course as i'm new to programming, and brand new to LUA i made some bumps and mistakes. but i figured everything out and properly made the message display AND have the doors open when you do turn the flashlight on. My question though, is there anyway to only have that prompt message displayed until the player successfully opens the door for the first time?
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 11th Feb 2017 07:27
Yes.

Make the prompt conditional with a flag and set the flag flag when the door is opened. For example:

Been there, done that, got all the T-Shirts!
PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 12th Feb 2017 02:23
Ok thanks for the advice. i'm still learning how to create/utilize flags like that. so that'll be really helpful, thanks AmenMoses
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Feb 2017 11:21
Boolean checks are more efficient than the '== 1' you see in most of the stock scripts because all numerical values in Lua are 64 bit floats, as GG is still compiled 32 bit this is going to be a lot slower than if you use true and false. The downside is you can't use booleans directly in a Prompt for debugging, instead you have to do something like:

if <boolean> then Prompt("<boolean>=true") else Prompt("<boolean>=false") end

But the main advantages are that a list of booleans is going to be way smaller than a list of numbers and if used as return values in functions the code can be much more readable.
Been there, done that, got all the T-Shirts!
PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 12th Feb 2017 19:29
ok.... so instead of checking for a numerical value. i should just check if an instance is 'true' or 'false'? thanks for the tip i'll keep that in mind. also, i learned that "if not" makes a very big difference from just "if" in that script you showed D:
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Feb 2017 19:48
I'm a bit old school, I tend to name variables in a more conversational sense and invert the logic if that makes for a more readable result. Of course what is readable for me might be complete gibberish to others, I've just taken on a job of maintaining 100k+ lines of C++ that was written by a team 20 years ago, it is full of gibberish to me but I'm sure the original programmers thought it perfectly readable.
Been there, done that, got all the T-Shirts!
PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 12th Feb 2017 20:45
could someone help me figure out what i've done wrong?

function delayedteleport_init(e)
end

function delayedteleport_main(e)
if g_Entity[e]['plrinzone']==true and g_KeyPressE==false then
Prompt("Press E to open door.")
end
if g_Entity[e]['plrinzone']==true and g_KeyPressE==true then
PlaySound(e,0)
ActivateIfUsed(e)
-- transport player somewhere else
TransportToIfUsed(e)
end
end

what i was aiming for is basically the trigger zone teleport. but i didn't want it to immediatly teleport the player (this goes back to my work around as to how to 'open' an unanimated premade entity). i was hoping to make a more immersive feeling for the player to use the E key as per usual, to open a door, and THEN have them teleported. i have the 2nd trigger zone on the map, and named it the same as the ifused field. it's not showing the prompt or teleporting if i push E inside the zone. just when i was thinking i was starting to understand LUA a little bit haha. (also if anyone wanted to show me how to utilize the code snippit feature that'd be appreciated too).
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Feb 2017 21:09 Edited at: 12th Feb 2017 21:12
I think you'll find 'plrinzone' returns a 1 or 0 as does g_KeyPressE.

As I said before most of the built in functions and scripts do, probably because they were converted from older system that did it that way.

You could wrap them in local functions if you want, i.e.:

function MyPlayerInZone(e)
return g_Entity[e].plrinzone == 1
end

function EPressed return g_KeyPressE == 1 end

Then your code becomes:

if MyPlayerInZone(e) and not EPressed then
Been there, done that, got all the T-Shirts!
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 12th Feb 2017 21:11 Edited at: 12th Feb 2017 21:13
1. Ok, forget what AmenMoses said. Use numbers. Numbers are a lot faster then boolean because boolean need an extra step to convert in 1 or 0. A PC always do everything in 1 or 0. That's why C has no boolean and Lua is based on C. What 32bit and 64bit has to do with I don´t know. 32bit applications just cut the 64bit number at the 32bit place. If you don´t want to launch a rocket with GG, use numbers:
http://www2.ing.unipi.it/~a009435/issw/extra/ariane5-benari.pdf.

2. Also, you use commands which need integers, so true and false make no sense here.

My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Feb 2017 21:17
Numbers in Lua are 64 bit in size so if A == 1 needs a 64 bit comparison plus 2 64 bit loads from memory (not to mention that they are also stored in memory in the first place). A 'true' Boolean in Lua is simply anything not 0 or nil, a simple check of a condition flag, much faster.

If you don't believe me read the performance section in the book written by the creator of the language!

There are no integers in Lua, zilch, nada, zip, the only numerical type is 64 bit double precision floating point.
Been there, done that, got all the T-Shirts!
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 12th Feb 2017 21:31
Quote: "If you don't believe me read the performance section in the book written by the creator of the language!"

I did and never heard something like that. Maybe you have a link?

Quote: "There are no integers in Lua, zilch, nada, zip, the only numerical type is 64-bit double precision floating point."

Ok, the command needs a 64bit float, so please write: 1.00000000000000000000000000000000000000. Better?
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 12th Feb 2017 21:38
Moses, so if i was wanting to use the True False checks instead of ==1 or ==0 i'd have to make them a local function, it wouldn't always work with the standard g_Entity[e][plrinzone] style ones pre made?

just trying to make sure i understand everything. as i've only done maybe 3 hours or so with LUA scripting.
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 12th Feb 2017 21:55 Edited at: 12th Feb 2017 21:57
g_Entity is a list, the key to the list is the 'e' value which basically just means the entity number which the engine give it when you drop it into the editor.

[e] is basically saying give me the entry in the list with the key e.

plrinzone is a field in the list entry so g_Entity[e].plrinzone (or g_Entity[e]['plrinzone'] which is the same thing) is just accessing the plrinzone field for the specified entity. The field happens to be numerical, probably because at some point it is interfaced with C++ code.

So yes if you want to you can use a function to change it to a true/false representation but in fact that is exactly what == 1 is doing! '==' is a function returning true or false (~= is a function returning the opposite).

Depends on how readable you want your code to be, if you are happy reading g_Entity[e]['plrinzone'] == 1 and understanding what your code is doing then stick with that.

btw, global variables are very slow to access, every time you use one Lua has to look it up in the global name table which takes time. If you are going to need access to the global variable many time uin your code you can do this:

local Ent = g_Entity[e]

then in your code you can do

if Ent.plrinzone == 1

The local variable does not have to be looked up, in fact in many cases it will be kept in a register, so it is extremely fast.

Happy coding and feel free to ask as many questions as you like, I have read the book!
Been there, done that, got all the T-Shirts!
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 12th Feb 2017 21:55

If you want to open a door and teleport player like the vid below:



so attach this script to your door direcly



Take this script as start point, due you can improve it, for example make some cut-scene and play it while teleport player, like resident evil does.

In order to use snippes, just hightlight the code and up you've the code tab, scrolldown and select LUA, and you are done.
hth

3com

Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 12th Feb 2017 22:18
Thanks 3com, but in this particular moment. what i'm looking for is a work around for a door that doesn't have an animation. like the ones from the pre-made entity buildings. So i can give the feeling of walking up to the door, interacting with it to 'open' it, but the player can't actual open it, as previously stated it's an unanimated door. Also, do you know how to create a cutscene and put it into the code? i'd love to get the older Resident Evil vibes where it shows a door open, and then you "appear on the other side"
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 12th Feb 2017 23:35
Not sure if it works, but look at the storyzone.lua. It plays a video. Maybe you need a timer too
StartTimer(e) and GetTimer(e) for a delayed transport.

Not tested:


Hope it helps
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 13th Feb 2017 16:20
Can imagine why you want to go inside a non-enterable buiding, most of them were modeled to be non enterables.
So you are right and doors are non-animate as well.
Why yo don't try with a enterable building/hut/house, with animate door?

If for some reason you prefer non-animate door, take into account those models are a single model, so you will has to edit model in a 3d soft, unattach the door, and animate it, then export door as X file, and add the animation frames to the fpe file; of course door should be dinamy, and attach the script to the door to play the anim.
Once you get this so you can make a video while door open and close; edit your vid for fine tune, and play it with storyzone.lua. Place some storyzone in your map, and set the video name in the proprties panel.

3com
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics

PM
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 13th Feb 2017 17:53
I'm not trying to make a player enter a building that's not supposed to be entered. I like the pre-made entities because they can help provide the look of a city street etc etc fairly quickly. the effect i'm looking for would be making it LOOK like you went inside one of those buildings. when in all reality you're being teleported to another area made to look like the inside of the building.
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM
Belidos
3D Media Maker
8
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 13th Feb 2017 18:23
So basically, you want something like this .... ?

https://www.tgcstore.net/product/24301

i5, NV960 2GB, 16GB memory, 2x 2TB Hybrid, Win10.
scythe_reaver
12
Years of Service
User Offline
Joined: 14th Nov 2011
Location:
Posted: 13th Feb 2017 22:07
basically yes. i've already learned how to do the teleporting part. the only thing i'm looking into now, is how i could use a fade transition like that. so it looks cleaner. rather than just *pop* and you're somewhere new
http://www.shrinkpictures.com/processed/phprZ6E7O_c2AM.jpg

\"I AM YOUR GOD OF DEATH\"
PM

Login to post a reply

Server time is: 2024-04-19 12:40:41
Your offset time is: 2024-04-19 12:40:41