Scripts / Text script

Author
Message
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 12th Jun 2014 21:49
Howdy people!

I am trying to make a very simple script that will allow a small amount of text to appear at the bottom of the screen to serve as information whent eh player is near something or needs to do something.

Here is what I have so far (I took the basis of the script from someone else - can't remember where I got it from though......)



What I want to happen, is when the player moves away from the candles I want the text to disappear and never appear again.

I initially tried to add Destroy(e) a the end, but, this obviously destroyed the candle entity. Then I thought, I could use a smaller entity behind the candles, as it wouldn't matter if that was destroyed. But, the trouble is, it was destroyed straight away. So, I added the little bit at the end that checks if the player is far enough away from the entity before it destroys it......obviously, the player starts far enough away, so, its destroyed before I even get there!

Any help on this would be great!

Also, has anyone worked on any scripts that would allow the doors to close automatically if the player is far enough away?

Cheers

Jay.

tomjscott
User Banned
Posted: 12th Jun 2014 22:17
Just add a local variable to track whether or not the prompt has been triggered yet. Then you can check that in the > 100 distance check and only destroy it if the prompt has already been displayed.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
tomjscott
User Banned
Posted: 12th Jun 2014 22:19


System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
tomjscott
User Banned
Posted: 12th Jun 2014 22:33
One more note. The change I made will only work if you are only using this on a single entity. If the script is attached to multiple entities then you would need to change it to the following:



Otherwise, when one is destroyed, they'll all get destroyed. Plus, get in the habit of having an init function in your scripts even if they are just empty. There is a bug that'll creep up on you and crash your level if you don't do this.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 12th Jun 2014 22:59
Thanks. I will try it now.

My scripting is terrible, but, I am always willing to try! This is what I did with FPI and by the end, I was making making mediocre scripts! Fingers crossed!

Have you any idea about the door script?

Cheers

Jay.

tomjscott
User Banned
Posted: 12th Jun 2014 23:02
Quote: "Have you any idea about the door script? "


It shouldn't be too hard, but I don't have the door script on this computer to make mods to. You would basically add a check for distance like you did in this script, but instead of destroying it you would play the close animation. Instead of the isTriggered as a condition to close you would use the information you have on whether the door is open. Not sure what variable is used for that off the top of my head.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 12th Jun 2014 23:04


I read what you had put above three times and still don't fully understand what I have to do.

Not sure if you can model or not, but, if you need anything modelled in return for your time, please feel free to ask. You could PM me if you would prefer.

Cheers

Jay.

AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 12th Jun 2014 23:22 Edited at: 12th Jun 2014 23:25
Sounds like you want it not to destroy the item but to just display the prompt once and once only if so just add a check like so





And don't use destroy(e) unless you want the entity destroyed =)

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
tomjscott
User Banned
Posted: 12th Jun 2014 23:36
Quote: "And don't use destroy(e) unless you want the entity destroyed =)"


True. Good point. I assumed he wanted it destroyed since that's what he had in code, but you're probably right. He probably doesn't want the entity itself destroyed in this case. I'm at work so I didn't put much thought into it.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
tomjscott
User Banned
Posted: 12th Jun 2014 23:42
Quote: "I read what you had put above three times and still don't fully understand what I have to do. "


I think you mostly have it. The door script is a fair bit of code so I don't want to change it here without testing since I might just make a dumb mistake, but two things I noticed. I thought that turning off the door collision timer was supposed to happen right after the door opens, but you have it as part of the check when the player is out of range. That should probably be above that distance check. Second, think you want to set door_pressed = 0 instead of door_pressed = 1 when you have triggered the close animation. Other than that I think it should work. If not and no one else steps in to help, I can give it a try when I get home and fix it for you.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 13th Jun 2014 00:00
tomjscott

Thanks for all your help so far mate.

Hope you have fun at work!

Cheers

Jay.

tomjscott
User Banned
Posted: 13th Jun 2014 00:04
Quote: "Thanks for all your help so far mate. "


No problem. I hope you are able to get all your issues resolved for your comp entry. Good luck.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jun 2014 12:35
for the door you can look at this to give you a better idea
http://fpscrforum.thegamecreators.com/?m=forum_view&t=207644&b=2&msg=2487838#m2487838

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 13th Jun 2014 22:01
@AuShadow

Your script works great, but, the text only flashes up for a split second.

I was going to add a delay, but, then I remembered that I don't know how to script!

Any ideas?

[href=http://touchoffear.co.uk][img]ht
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 13th Jun 2014 23:01 Edited at: 13th Jun 2014 23:14
Yep but just remember I'm doing this on my phone as my computer is down so it will be untested,







I think that's about right, just change delay to how many seconds to display the prompt for. If it doesn't work let me know the error, my PC is out at the moment so best I can do =)

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jun 2014 23:14 Edited at: 13th Jun 2014 23:27




fixed, just name it prompt_script.lua

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
AuShadow
GameGuru TGC Backer
10
Years of Service
User Offline
Joined: 2nd Dec 2013
Location: Australia
Posted: 13th Jun 2014 23:15
Lol yep have been re reading and editing my mistakes slowly sucks on such a small screen thanks Smallg

PC Specs: Windows 7 home 64-bit, Amd 7900 3gb DDR5 graphics, 8gb DDR3 Ram, Intel i7 3.4ghz

Feel free to visit and edit the public FPSCR resource wiki page: http://fpscrresource.wikispaces.com/home
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 13th Jun 2014 23:20
I tried the script. I renamed it to display_candles.lua and changed both the function names (init and main)

It errored out and said that it was expecting to end. So, I added an end at the bottom.

It loads fine, but, doesn't show any text.

Any ideas?

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jun 2014 23:29
oh yh missed that last end statement too
which script did u use? if u used AuShadow's you need to add the distance checks as he said (where the comment is inside the code)

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 13th Jun 2014 23:31
I used your script. Just above.

It just doesn't show anything.



That is what I have changed it to.

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 13th Jun 2014 23:33 Edited at: 13th Jun 2014 23:36
try changing the distance to a bigger number, the script looks ok to me



ah no i missed a line when i copied the distance check, sorry



paste this just below the playerDZ = stuff



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

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Hockeykid
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 13th Jun 2014 23:33
I've made some edits to the script. Give this a try, it should work:




Sean

tomjscott
User Banned
Posted: 13th Jun 2014 23:33
Here you go. I tested this myself and it works. Shows prompt for 5 seconds unless you back away before timer expires. Never shows prompt again once timer expires or you back away.



System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 13th Jun 2014 23:46
smallg,

Your script works perfectly. Thanks for putting the time!

HockeyKid! Long time no see! I didn't know you were frequenting the Reloaded forums?

tomjscott, smallg's script worked for me, but, thank you so much for trying something for me. I know other people will be able to get some use from them!

On a side note,

smallg, your autodoor script is awesome, but, I wanted it so that the player had to press 'E' to open the door rather than it opening when in range.
I did try to edit it, but, it doesn't work!



tomjscott
User Banned
Posted: 13th Jun 2014 23:51
I realized I can eliminate the timerStarted variable from my script. Here is a better version. Glad you got it working. I would suggest using this as it is cleaner than the other versions and includes the prerequisite init function as well.



System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
Hockeykid
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 13th Jun 2014 23:57 Edited at: 13th Jun 2014 23:59
Quote: "smallg, your autodoor script is awesome, but, I wanted it so that the player had to press 'E' to open the door rather than it opening when in range.

I did try to edit it, but, it doesn't work!"




I didn't test this, but give this a try:







Quote: "HockeyKid! Long time no see! I didn't know you were frequenting the Reloaded forums? "




I just bought reloaded the other day, I like helping people with scripting, so I've been reading through some of these threads.





Sean

unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 14th Jun 2014 00:02
Sean, PERFECT!

Thanks so much for that.

tomjscott, I tried your script, but, nothing appears for me.

The only thing I noticed was that you didn't have the player position math in yours? Was this not supposed to be there?

Hockeykid
16
Years of Service
User Offline
Joined: 26th Sep 2007
Location:
Posted: 14th Jun 2014 00:06
Quote: "The only thing I noticed was that you didn't have the player position math in yours?"


My text prompt script here should work:




Sean

tomjscott
User Banned
Posted: 14th Jun 2014 00:07
Quote: "The only thing I noticed was that you didn't have the player position math in yours? Was this not supposed to be there?"


I added a comment to replace the player distance check with the standard code. I personally have this wrapped into a global function called GetPlayerDist() so you don't have to have that bloated code in every single script. Just another good tip for anyone who is interested. I assure you that it works perfectly. You just need to replace the GetPlayerDist function call with the standard code for doing this. Or you can add the following to your global.lua file and never have to copy and paste that code again.



System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
tomjscott
User Banned
Posted: 14th Jun 2014 00:11
Quote: "My text prompt script here should work:"


Your script doesn't handle the case where the player backs away before the timer completes. If he backs away and comes forward again then the text reappears. I have that case handled.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 14th Jun 2014 00:18
tomjscott,

Sorry, I tried your script again and realised that when I said I had tried it, I had actually set the entities script to default (I was getting errors on loading and wanted to test other parts of the game)

smallg, tomjscott, HockeyKid, Thank you guys so much. I really appreciate you taking the time to help me with these scripts. The only way I can ever repay the favour is to help you guys with any models you might need. You can PM me or email me directly.

One further side note, does anyone know how to disable running? I don't want the player to be able to run (mean I know)

tomjscott
User Banned
Posted: 14th Jun 2014 00:21
Quote: "One further side note, does anyone know how to disable running? "


There is a property in the player start marker, I believe, that sets the run speed.

System Specs: OS - Windows 7 Home Premium 64-bit SP1, CPU - AMD Phenom II X4 945, 3.0Ghz, RAM - 8Gb DDR3, GFX Card - 2048MB NVIDIA GeForce GT 640, FPSC-R Version - Beta 1.007
unfamillia
Forum Support
14
Years of Service
User Offline
Joined: 26th Jul 2010
Location: Preston, Lancashire
Posted: 14th Jun 2014 00:40
I changed the properties in the start marker. I removed the players ability to jump as well. But, this doesn't seem to get transferred during the build process.

Never mind. This isn't a major issue.

Thanks for everyones help.

I will submit my game now as its my 30th tomorrow, so, I won't get chance to change or add anything else now.

Cheers

Jay.

smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 14th Jun 2014 01:23
no you cant currently control the player's movement via scripting.

personally i like to have prompts that wont disappear immediately on leaving the set range (i.e. only on delay) because that way if you did just happen to somehow walk past an object too fast and only caught a glimpse of the text it'll still be there when u go back but that's a minor thing

life's one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
TattieBoJangle
10
Years of Service
User Offline
Joined: 7th Jan 2014
Location: United Kingdom
Posted: 14th Jun 2014 16:17
Hi guys trying to use this LUA but keep getting No function what did you name it







PC SPECS: Windows 8 Pro 64-bit, Intel I7 (PASSMARK 9529) 4GHz CPU, Asus R9 3GB GPU (PASSMARK 6858) 32GB DDR3 MEM (PASSMARK 2842)
almightyhood
10
Years of Service
User Offline
Joined: 9th Oct 2013
Location:
Posted: 14th Jun 2014 16:29
might need a bit of code above the _main(e)




that might do it m8, the name is doornokey.lua

evga GeForce gtx 750 ti boost2.0 2gb gddr5. win 8.1 quad core 4gb ram.
PM
TattieBoJangle
10
Years of Service
User Offline
Joined: 7th Jan 2014
Location: United Kingdom
Posted: 14th Jun 2014 16:35 Edited at: 14th Jun 2014 16:40
renamed it to doornokey dhooo works on a blank map and get a StackHash_f40f error on a map built





PC SPECS: Windows 8 Pro 64-bit, Intel I7 (PASSMARK 9529) 4GHz CPU, Asus R9 3GB GPU (PASSMARK 6858) 32GB DDR3 MEM (PASSMARK 2842)

Login to post a reply

Server time is: 2024-09-08 03:51:04
Your offset time is: 2024-09-08 03:51:04