Scripts / saving player x,y,z

Author
Message
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 24th Jan 2019 09:24 Edited at: 24th Jan 2019 09:54
not sure if i have asked before but, is there anyway in lua of getting the player x,y,z position and the direction the player is facing and saving into a set of variables and then saving out as a file?

I have looked in global lua but cant see much to help in there, I might be missing something.

I know there is a savegame and loadgame in GG, but i only need to save these and other variabes, nothing else.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth, Roland D05 Synth Module, Bluedio Victory V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics. Acer Swift i3 Laptop with Intel Optane memory, Intel 620UHD GPU, Windows 10 64bit.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Jan 2019 11:02 Edited at: 24th Jan 2019 11:03
io read and write are default lua commands so no need to list them in global.lua
so
file = io.open("filename","mode")
io.write("data")
io.write("more data")
io.close(file)
you can use the save and load system as a guide or there's guides online such as this
the player data is all in the global.lua though, g_PlayerPosX (/ Y / Z) & g_PlayerAngX (/ Y / Z)

don't forget you will need to do the reverse in your maps too to load back that saved data
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 24th Jan 2019 11:43
I got the io commands ok, and can save and load general variables perfectly. It's just the conversion of the playerposition and direction he is facing confusing?

I am writing a save / load routine my self so I can load stuff in, check the variables after and destroy and spawn and move doors and alter collision. The GG save and load only works in standalone, I have done this so i can use in test game also.

Thanks smallg.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth, Roland D05 Synth Module, Bluedio Victory V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics. Acer Swift i3 Laptop with Intel Optane memory, Intel 620UHD GPU, Windows 10 64bit.
Belidos
3D Media Maker
9
Years of Service
User Offline
Joined: 23rd Nov 2015
Playing: The Game
Posted: 24th Jan 2019 11:57
I actually wrote a set of scripts to save variables to file when exiting a level, all you needed to do was list which variables you wanted saved and it would save them to a file in the script bank, and load them in again on the next level, can't find them at the moment, i'm sure i posted them on here somewhere, if i find them i'll put them up, that should give you an idea of how to write and read variables to files.

(i would write out how to do it here for you, but without looking at the script to refresh my memory i can't remember what i did, i have a terrible memory, if i'm not repeating something all the time i will forget it, that's why i don't like to script, i end up having to learn things over and over again every time i write a script lol).

Primary Desktop:
i7 7700,k NV1070 8GB, 16GB 3200mhz memory, 1x 2TB Hybrid, Win10.

Secondary Desktop:
i5 4760k, NV960 2GB, 16GB 2333mhz memory, 1x 2TB Hybrid, Win10.

Laptop:
i3, Intel 4000 series graphics, 6GB memory, 1x 500gb HDD, Win8.1.
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 24th Jan 2019 12:07
I used your excellent scripts as a basis for what I am trying to do here. Your scripts got me going, and they work really well.

Just can't seem to find a way to save and reload player x,y,z and direction facing.

It must to be able to be done, as the GG save and load does it, im sure, but the code is a bit heavy, can't seem to find what links with what in it.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth, Roland D05 Synth Module, Bluedio Victory V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics. Acer Swift i3 Laptop with Intel Optane memory, Intel 620UHD GPU, Windows 10 64bit.
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 24th Jan 2019 16:34
how are you reloading the player's position?
you will need to use one of the GG commands to reposition the player after you load the saved data
such as
SetFreezePosition(loadedX, loadedY, loadedZ)
SetFreezeAngle(loadedAngleX,loadedAngleY,loadedAngleZ)
TransportToFreezePosition()
(i forget if you need to freeze & unfreeze the player or not but i don't think so)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
AmenMoses
GameGuru Master
8
Years of Service
User Offline
Joined: 20th Feb 2016
Location: Portsmouth, England
Posted: 24th Jan 2019 19:10
No you don't need to Freeze/Unfreeze, in fact I recommend avoiding those commands entirely!

SetFreezePosition, SetFreezeAngle and TransportToFreezePosition functions work great though..

Been there, done that, got all the T-Shirts!
PM
Tarkus1971
Audio Media Maker
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: England, UK
Posted: 24th Jan 2019 22:18
cool thanks for your help smallg and amenmoses.
Aftershock Quad Core AMD FM2+ 3.5 GHz 8GB Motherboard and Processor, A7700k apu, Asus GT970 STRIX 4gb Nvidia gfx card.
King Korg Synth, Alesis SR18 Drum Machine, Akai MPX8 sample player, Roland Fantom XA Synth, Axus Digital AXK2 Digital Drum Kit, Novation Ultranova Synth, Waldorf Blofeld Synth, Roland D05 Synth Module, Bluedio Victory V Headphones, AKG K141 Studio Headphones, Lenovo Ideapad, with Windows 10 64bit, 8Gb Ram and AMD A10 7th Gen Graphics. Acer Swift i3 Laptop with Intel Optane memory, Intel 620UHD GPU, Windows 10 64bit.

Login to post a reply

Server time is: 2024-12-22 13:59:28
Your offset time is: 2024-12-22 13:59:28