Scripts / Number Keypad scripting help.

Author
Message
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 20th Jun 2015 00:03 Edited at: 20th Jun 2015 00:04
Good evening,

I am currently working on a pack that contains various switches, keypads, levers and more.

I want to make something a little more special than just the standard, 'Press [E] to use switch', then a little light comes on and the door is unlocked. I want to create something that adds a little immersion to a game.

So, I have modelled and animated a keypad. The player will need to get a code to use on the keypad and enter the code using the numbers on their keyboard. When a number on the keyboard is pressed, it animates that button on the model in game.

I have that bit working, but, I can't figure out how to get the script to recognise a particular code before it opens the door.

If anyone is willing to help, I will give models in return, or money. I will be using this script with the switches, that I will be putting in the TGC store.

This is the keypad in question



and this is the script I have so far. Sorry if it isn't much, but, I am not great with code! I am still learning.




Thanks in advance for any help.

Cheers

Jay.




Attachments

Login to view attachments
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 20th Jun 2015 03:09
Well, here are 2 possibles.
1- Than I do not get your point exactly, because my standford english.
2- Than the script does not work, since it is untested.
3- due you do not say what the password number is, and howmany digits it have.

So assuming the pass = 1234 (you can change then to suit your needs)



Just to clarify:
I do not want any money, sice here everybody help me many times 4 free.

hth

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

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

PM
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 20th Jun 2015 05:39 Edited at: 20th Jun 2015 05:40
3Com - a quick look at that says you'd need to reset the password attempt if there are 4 keypresses and not the right code or the user could just press every number and get the password right. Yeah I know, coding off the top of your head is way too hard


OP, I have a couple of questions on this first.

1) Is the password going to change each time they play or fixed? (If password is found on paper or a wall etc. I assume fixed)
2) Where is the password going to be stored? It could be hardcoded in script or obtained from the entity name property.
3) Is * and # included in the password or are they "reset" and "unlock/open"?
3b) Only 4 numbers in password or more?
4) Is it numpad only or number keys as well (note: there's no hashtag on numpad)
5) Is pad locked out on failed attempt or do you just need a prompt to say "fail, try again?"

What timeframe - take a while to write and test this - reasonably simple to code but prone to error. Let me know and if I have the time and it fits your schedule I can code this up.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 20th Jun 2015 09:41
@3com,

Thanks so much for looking at the script and putting down your thoughts.

@!nullptr,

1 - The Password will be fixed. The player would find the code on a computer or another device.
2 - If I understand you correctly, the code would be stored within the script. This way, if needed, I can make a number of scripts that allow for different codes.
3 - * and # were just there as fillers. They do work and can be animated in the same way, but, I imagine they would be dormant.
3b - Four numbers for the code is enough I feel. I want immersion, not to annoy people with 16 digit codes.
4 - Not sure I follow you on this one. All keys can are animated, so, they can all be used.
5 - I haven't added any lights to indicate a lock out, so, I guess a message "Error - Try Again", would be sufficient.

There is zero time frame on this. If you manage to get it working, I will be happy regardless. I still have a lot of other models to make, so, I will keep myself busy with those.

I appreciate any time you put into this.

If you require the model for testing, let me know and I will send you a PM.

Cheers

Jay.




Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 20th Jun 2015 10:18 Edited at: 20th Jun 2015 10:22
Here: is a working script. lenght is variable in the password array. If some problems exist or you have some questions, feel free to ask (PM)
Use it as you want, delete the debug code(PromptDuration).


sorry it is not optimized and commented, but I did not have much time. I hope this helps.

Exited what you will do with my script. I need switches, so when do you release them?

Corno_1
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 20th Jun 2015 12:21 Edited at: 20th Jun 2015 12:26
Nice script Corno.

I was looking forward to doing this one myself but you saved me from the fun the job


@unfamilia
Quote: "2 - If I understand you correctly, the code would be stored within the script. This way, if needed, I can make a number of scripts that allow for different codes. "

My thoughts were if you put the password for the keypad in "name" properties then the same script could be used for multiple keypads. It would save non-coders/users from having to touch the script at all. nvm.


edited: typos
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 20th Jun 2015 13:45
Quote: "a quick look at that says you'd need to reset the password attempt if there are 4 keypresses and not the right code or the user could just press every number and get the password right. "

Yes I think so, but 04 am here, and I need go to the bed.

Nice script Corno_1

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

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

PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 20th Jun 2015 21:54
3Com, !nullptr and Corno1,

Thanks for all the assistance thus far.

Corno, your script works really well. It does exactly what I am after.

Just one more small question, if I may. Is it possible to change the location of PromptLocal? I have it set, so, when the player is within 150 units, it shows a local prompt, however, this is at the root of the object, which in this case, is the floor.

Is there a method in which to bring the local prompt up to eye level, preferably above the keypad?

Oh, by the way, you three check your PM box, I have left a little something in there for all your help.

Cheers

Jay.




cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 20th Jun 2015 23:25
Nice looking keypad and script fellas.

One problem I had with using a key pad script (a while back on a non animated model) was that when the player had acquired a few weapons, using the number keys (rather than then number pad on keyboard) would cycle through the weapons as well as entering numbers to the script. Script still worked but looked a bit odd. I couldn't think of a work-around back then, so opted for an alpha only key code.

Cheers.
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 20th Jun 2015 23:39
Quote: "using the number keys (rather than then number pad on keyboard) would cycle through the weapons as well as entering numbers to the script. Script still worked but looked a bit odd. I couldn't think of a work-around back then, so opted for an alpha only key code."

I had asked whether this should be scancoded off the numpad alone rather than numpad and numeric - for a different reason though. If hashtag was in use, numpad could not be solo'ed.

Didn't even occur to me that weapons are also going to bounce off the script. Nice pickup.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 21st Jun 2015 00:30
@cybernescence,

Good spot! I very rarely use weapons in my games. Not because I don't like violence or guns, but, I prefer to make puzzle games or horror games where the player doesn't have access to an inventory, in order to fight off the nasties!

I have been using the numpad on my keyboard, so, I wouldn't have noticed it anyway!

This is what it looks like in game.



I like the effect, but, for some reason , you need to enter it twice. The first time you enter it, it does unlock the door, but, it appears as though the collision isn't turned off. If you enter it a second time, the error sound plays on each key stroke and you can then walk through the doorway.

Cheers

Jay.




cybernescence
GameGuru Master
11
Years of Service
User Offline
Joined: 28th Jan 2013
Playing: Cogwheel Chronicles
Posted: 21st Jun 2015 02:15
That looks fantastic in game.

Not sure if any use as you may have it working exactly as you want, but a script attached for the door opening - opens if e.g. activated via IfUsed from another script (e.g. keypad).


Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 21st Jun 2015 02:15
Quote: "Is there a method in which to bring the local prompt up to eye level, preferably above the keypad?"

use the Text(x,y,size,txt) command

Quote: "I like the effect, but, for some reason , you need to enter it twice. The first time you enter it, it does unlock the door, but, it appears as though the collision isn't turned off. If you enter it a second time, the error sound plays on each key stroke and you can then walk through the doorway. "


I tested it with the standart door script and it unlocks the door, so you can open it. Maybe you must tweak the door script for your needs
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 21st Jun 2015 20:05 Edited at: 21st Jun 2015 20:13
@cybernescence

I am getting an error when I use your door script. I have looked to see if there any obvious errors, but, I can't see anything.



@Corno1,

How do I use the Text (x,y,size,text) function?

I tried Text(0,100,12,"Enter Code to OpenDoor"), but, it didn't work.

Am I supposed to lay it out like in the global.lua?



Cheers

Jay.




Attachments

Login to view attachments
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 21st Jun 2015 20:31
@unfamillia the size of textfield just go until 5. also x and y are in percent in my opinion...

Text(50,40,2,"Enter Code to OpenDoor")

this should work better.
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 22nd Jun 2015 08:49
@Corno,

Thanks for the tip. It shows up on screen now. Is there not a way to make the text appear on the object? Like PromptLocal? I have tried PromptLocal, but, it always appears at the base of the object, regardless where the model insert point is.

If there isn't a method suitable with script, I can always make a small decal and use that, I just thought it would be cleaner with code.

Cheers

Jay.




!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 22nd Jun 2015 09:45
Quote: "Is there not a way to make the text appear on the object?"

Only way this could be done is to calculate the relative angle of the player to the object since it's position can vary in relation to where you are looking. Can't see that being an easy piece of code off the top of my head.

Somebody might have the formula but even then, the positioning fidelity of the text is not particularly good either.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 22nd Jun 2015 10:51
Quote: "Only way this could be done is to calculate the relative angle of the player to the object since it's position can vary in relation to where you are looking. Can't see that being an easy piece of code off the top of my head.

Somebody might have the formula but even then, the positioning fidelity of the text is not particularly good either."


It's OK. I will use a decal instead. I can control the positioning easily then.

Thanks for the answer.

Cheers

Jay.




!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 24th Jun 2015 13:37 Edited at: 26th Jun 2015 01:03
Take a look at this vid unfamilia.

2 scripts. 1 on door, 1 on pad. Add password to door/gate name property and pad name property, any length. Click and run.

One script, many doors, auto detect. In vid, debug code is enabled, 1 switch to tun it off. User never need to touch script at all.



If that's what you're after buzz me a PM and I'll send you the script.
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM
Corno_1
GameGuru Tool Maker
13
Years of Service
User Offline
Joined: 3rd Nov 2010
Location:
Posted: 24th Jun 2015 15:24
Nice script !nullptr.
But it seems you want a scripting war
My dream is to develope games, which makes fun when I create it and fun when other people play it.
PM
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Jun 2015 15:39
impressive script !nullptr
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
unfamillia
Forum Support
13
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 24th Jun 2015 16:00
@!nullptr,

I bow to your greatness! That is exactly how I wanted it to work! Perfection, right there.

Great video.

Cheers

Jay.




CRGSOS
11
Years of Service
User Offline
Joined: 27th Dec 2012
Location: Southend on Sea UK
Posted: 24th Jun 2015 19:06
Perhaps this short script section to operate from the number pad will be of use? It avoids clash with weapons etc.

urvariable = 82 - g_Scancode
if urvariable > 0 then --convert np to numerals
if urvariable <= 3 then urvariable = 4 - urvariable
end
if urvariable <= 7 and urvariable >= 5 then urvariable = 11 - urvariable
end
if urvariable <= 11 and urvariable >= 9 then urvariable = 18 - urvariable
end
end
CRGSOS
PM
!nullptr
Forum Support
9
Years of Service
User Offline
Joined: 27th Mar 2015
Location: Australia
Posted: 24th Jun 2015 22:21 Edited at: 24th Jun 2015 22:23
Thanks guys. I thought about putting script here but I'll leave that decision to unfamilia as he may chose to release it with a door kit first.

@unfamilia - see PM

@corno
Quote: "But it seems you want a scripting war"

Never Sir. Much rather we join forces and create the greatest game ever known to man help each other out.

@CRGSOS
That's what I did with my script. It's off the numpad only (but easily adapted).
AKA SisterMatic (Steam)
Development/ Gaming Rigs
Sys 1: i7-4770 (3.5)/16Gb/128 SSD/3Tb/970gtx/2 x 23, 1 x 27 LCD - Sys 2: i7/8Gb/670gtx/1.5Tb/1 x 23 LCD - Sys 3: Amd Quad/8Gb/645gtx/1Tb/30" LCD
PM

Login to post a reply

Server time is: 2024-04-27 07:48:17
Your offset time is: 2024-04-27 07:48:17