Jump to content

Help, loading position from file.


Recommended Posts

Hello, I'm having a problem loading a position from a player file into the script, I saved the position as a string and now I can't load it. Here's what I have

The string goes like this:

Position: 0.000000,0.000000,100.000000
(I know that this will spawn me really high, that's not the point)

I've tried splitting it like this:

local x,y,z = fileRead(playerPos,28) 
split("x,y,z", ",") 
setElementPosition(player,x,y,z) 

And I just keep spawning at the same place, under the ground (As if the z coord equals to 0)

Also, I would like to know, since the position length can vary, how can I tell the script to grab the exact amount of numbers that are in the string?

For example: 0.000000,0.000000,100.000000 equals to 28 characters, but if it was 10.000000,0.000000,100.000000 it would equal to 29, how could I make the script know when is the end of the string? Because if I use fileRead(playerPos,29) and it's just 28 characters, it would grab the next thing on the file, making the Z coord unusable.

Thanks

Link to comment
  • Moderators
local thePosition = fileRead(playerPos, fileGetSize (playerPos)) 
local x,y,z = unpack(split(thePosition, ",")) 
if x and y and z then 
    setElementPosition(player,x,y,z) 
end 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...