Jump to content

Position script


Zonex Favel

Recommended Posts

Made this position script because I wanted an easier way for spawn points too. It can use improvement but here it is

  
function getPos(thePlayer, command, place) 
    local x,y,z = getElementPosition(thePlayer) 
    local placeFile = place..".txt" 
    local posTxt = fileOpen(placeFile) 
    local mycoordinates = "X="..x.." Y="..y.." Z="..z 
    if posTxt then 
        fileWrite(posTxt, mycoordinates) 
    else 
        posTxt = fileCreate(placeFile) 
        fileWrite(posTxt, mycoordinates) 
    end 
    fileClose(posTxt) 
    outputChatBox("worked", thePlayer) 
end 
  
addCommandHandler("save", getPos) 
  

to use it just type "save " in the console and it will create a text file with that location name and the coordinates your at. You can also use "/save " in the chat window to execute it. If anyone has a better script or improvements to mine please post it! :D

Link to comment

Ok, and this is my version of the script, that saves your current position. I think, that it is better to keep all positions in one file.

function savePos(thePlayer,command,comment) 
    local x, y, z = getElementPosition(thePlayer) 
    hFile = fileOpen("pos.txt", false) 
    if hFile then 
        local temp 
        while not fileIsEOF(hFile) do 
        temp = fileRead(hFile, 500) 
    end 
        fileWrite(hFile,x .. ',' .. y .. ',' .. z .. ',' .. comment .. '\n') 
    else 
        hFile = fileCreate("pos.txt") 
        fileWrite(hFile,x .. ',' .. y .. ',' .. z .. ',' .. comment .. '\n') 
    end 
    outputChatBox("Saved!", thePlayer) 
    fileClose(hFile) 
end 
addCommandHandler ("pos", savePos) 

Link to comment
load positions? ;O

i can save positions the "Saved!" appears but how to teleport to there :roll: ?

in the server window of developers preview 2 there comes an error: Attempt to concatenate local 'coment'

Assuming "comment" was spelled correct:

This means the variable comment has no value (it points to nothing). The script in the first post here, doesn't check if the value of comment exists. To do this add something like:

if( comment ~= nil ) then

...

end

Link to comment
  • 2 weeks later...

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...