Scripts / [SOLVED] Get Player Distance Traveled Stored As A Value?

Author
Message
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 21st Sep 2022 20:34
I've been thinking about this for hours and I can't figure it out. Is there a way to keep track of how far the player has traveled? Something like how far since the last check and if the player goes further than a given value then add +1 to a value? such as "If PlayerDistanceTraveled => X then distance = distance +1. I just can't figure out what I need to keep track of to get the player distance. How would I set the current start tracking position to the players current position and check the players current position to the previous start tracking position to see if the player has traveled far enough to add to the stored distance value? As I'm sure you can tell, I've been racking my brain to figure this out. I'm still a noob so it's hard. lol.

My end goal is to use the stored distance value to show the players distance on screen using number sprites to show it. I've figured out everything else except actually getting the value. I'm doing the same thing with a timer. It's already scripted and waiting for me to get done with this post so I can get back to making the sprite images I need to finish it. Any help will be appreciated. TIA

Keep Making Stuff You Enjoy.

The author of this post has marked a post as an answer.

Go to answer

Attachments

Login to view attachments
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 22nd Sep 2022 01:14
@ EyeFly
Try this one

https://youtu.be/li5KKNkjM5E
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
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

Attachments

Login to view attachments
PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 22nd Sep 2022 01:14 Edited at: 22nd Sep 2022 01:20
...
PM
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 03:05
Awesome! Thank you. I'll try it tonight. Ill post the results in a couple of days. I'm still working on the images. It's very much appreciated.
Keep Making Stuff You Enjoy.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2022 12:36 Edited at: 22nd Sep 2022 13:03
This post has been marked by the post author as the answer.
3Coms version tracks how far from a starting point you are i.e. if you were to move far away and then back to the start it will say you haven't moved at all
it's not clear if this is exactly what you are looking for or if you want how far the player moves in general (regardless of if moving back and forth on the spot etc)

edit: here's a version where you can choose which functionality you want
note: the actual distance shown is just a guess
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Attachments

Login to view attachments
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 22nd Sep 2022 14:57
@ smallg
Quote: "it's not clear if this is exactly what you are looking for or if you want how far the player moves in general (regardless of if moving back and forth on the spot etc)"


Not sure if I've got the op point, waiting for him to come here and clarify a bit, anyway, I wrote a script as a guide for him.
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
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 20:18 Edited at: 22nd Sep 2022 20:45
Thank you both for the scripts.

my end goal is to get the distance as a global value that I can use in another script that will pasate sprites on the screen (numbers). like 00000. then as the player moves through the game, the numbers will update like this, 00001, 00002, 00003, and so on. I was thinking the script would be something like "if travel_distance > 5 then g_ones_slot = g_ones_slot +1, travel_distance = 0 end" then it repeats and continues adding to the g_ones_slot until it gets to 9 then reset to zero and add +1 to g_tens_slot. like "if g_ones_slot > 9 then g_ones_slot = 0, g_tens_slot = g_tens_slot +1 end". and so on for the g_hundreds_slot through the g_ten_thousand_slot. then have all the numbers stay 99999 after 99999 (that should be high enough that the player shouldn't ever max it out). So maybe have the script only run as long as the g_ten_thousand_slot is less than 9 "if g_ten_thousand_slot < 9" Then run the travel distance script.

My other script will handle the sprites. I was thinking something like "if g_ones_slot == 0 then PasteSpritePosition(ones_slot_image0,23.21, 96.58)" and so on for sprites 1-9. Then the same for g_tens_slot through g_ten_thousand_slot.

I hope I explained that well enough. Like I said in my original post, I've been thinking a lot about this. I'm still learning about LUA and scripting. Looking at how you guy's make your scripts helps me learn a lot. I already have other scripts doing the same type of thing with other numbers. I just need these global values to get my HUD finished. And I don't want the distance to go lower if you go back to the starting area.

Thanks Again. You guy's are awesome!!!

Here's a couple of pics of my HUD and camcorder overlay so far. (I plan on adding a timer and the distance to the other side of the screen)
The HUD has a sanity bar, infection bar, cam/flashlight battery bar, 3 different slots for Almond waters, and a slot for antibiotics. The cam/flashlight battery bar also works on the camcorder overlay. But the timer hasn't been added yet. I just put 99:99:99 for now. I've been working on this for weeks. I had to learn a ton to get them working.

UPDATE I just took a closer look at your script (smallg), and I only want the flat distance. I don't want altitude added.



Keep Making Stuff You Enjoy.
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 20:30 Edited at: 22nd Sep 2022 20:41
here's my timer and distance HUD (it's not done yet. Still making changes to it). The numbers will be in the bigger sections and the names of them will be in the top sections. Like "Trapped Time" or "Time Played" and "Distance Traveled". Hoping people will want to compete for high scores on distance and time for how long you survived or escaped and for shortest distance to escape or longest distance traveled without dying. (with footage to prove they didn't just walk in circles or stand still and wait a long time to get a high time. lol) It will give people a reason to keep playing.

Keep Making Stuff You Enjoy.

Attachments

Login to view attachments
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 22:09
I think I have it figured out. I got smallg's script modified so it resets the distance at a set limit and each time it reaches that limit it adds +1 to g_ones_slot. And after g_ones_slot is greater that 9 it resets to 0. Now I just need to add the rest of the slots to the script.

Thanks to you guts again! Your help means a lot. I can now finish my HUD. Hopefully I'll have a video of my HUD working in the next couple of days. I'll post it in the work in progress section.
Keep Making Stuff You Enjoy.
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 22:16 Edited at: 22nd Sep 2022 22:31
I went ahead and marked smallg's script as answered. That script is more or less exactly what I needed. You both are awesome for the work you guys do. Once again, thank you.

With your (smallg) permission, I'd like to share the script when I'm finished with it. It'll just count up the global values for use in other scripts.
Keep Making Stuff You Enjoy.
3com
10
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 22nd Sep 2022 22:29
@ EyeFly
Glad to help.
Cool stuff btw.
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
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 22nd Sep 2022 22:32
@ 3com

Thank you. I can't wait to share my progress. It's been quite fun learning to make this game.
Keep Making Stuff You Enjoy.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 22nd Sep 2022 23:58
Quote: "UPDATE I just took a closer look at your script (smallg), and I only want the flat distance. I don't want altitude added."

ticking the ignoreY toggle in the behaviour will do that already.

and sure you can share your version of the script no problem with me
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
mikeven
12
Years of Service
User Offline
Joined: 31st Dec 2011
Location:
Posted: 23rd Sep 2022 12:55 Edited at: 23rd Sep 2022 12:56
Hello,

@Eyefly, thank you for sharing this interesting topic.

I tested the scripts posted by 3com and by smallg.

The script posted by 3com made indeed sense if the purpose was to compute the distance travelled from the start position of the player.

The script posted by smallg offers more options and that's why I especially tested it in a small project adapted for that purpose.

I came to the conclusion that two lines of smallg 's scripts has to be modified.

line 6 (in my editor) : 'local dis_travelled = 0' modified with this : 'dis_travelled = 0' to initialize that variable as a global one in order to share it with some other behaviors.
line 39 (in my editor) : 'Prompt(round(dis_travelled*0.01,1).."m")' modified with this : 'Prompt(round(dis_travelled*0.025,1).."m")'

indeed, I assume that the letter 'm' in the 'Prompt' instruction is referring to 'metres'.

If requested, I could upload a video demonstrating why I adjusted the scaling factor in line 39.
PM
EyeFly
3
Years of Service
User Offline
Joined: 8th Nov 2021
Location: Oregon, United States
Posted: 23rd Sep 2022 16:45
@ mikeven

Thanks for doing that. But I actually already modified smallg's script to work for my purposes. I took the calculated distance output and put a limit to how much it can tick up before reseting. I set the limit to 100 which is just about one floor tile length in my game. And each time the distance gets to the limit, it adds +1 to a global value I added (g_ones_slot). Then every time g_ones_slot is greater than 9, g_ones_slot rolls back to 0 and it adds +1 to g_tens_slot. And so on through g_hundred_thousand_slot. And I'm using those globals to paste number sprites to the screen that match my other HUD elements.

Heres a picture of my other HUD sections that are already finished. The numbers I'm using in this are the same ones I'm going to use for the distance.

Keep Making Stuff You Enjoy.

Login to post a reply

Server time is: 2024-11-21 15:45:47
Your offset time is: 2024-11-21 15:45:47