Zonex Favel Posted January 7, 2008 Share Posted January 7, 2008 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! Link to comment
[email protected] Posted January 8, 2008 Share Posted January 8, 2008 You might want to add a check whether the data really got saved to the file. Currently, it (is supposed to) always report "Worked!" back to the player (a file could be read-only) Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 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
Zonex Favel Posted January 8, 2008 Author Share Posted January 8, 2008 Cool Like your's better. Thanks for the help. I was trying to do that all day but I ended up with my script because I couldn't get it done. EDIT: Having trouble getting this to work, did you use other scripts? Link to comment
idiot Posted January 8, 2008 Share Posted January 8, 2008 rjcnz333 whats the meta? yes i am a noob... but i could need this script for a stunt/freeroam server Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 <meta> <info name="savePos" description="Save your current position" author="333"/> <script src="savepos.lua"/> </meta> You can use this resource only in folder. MTA: DM dp1 doesnt support fileCreate for zipped resources. Link to comment
idiot Posted January 8, 2008 Share Posted January 8, 2008 okay thx. but what are the commands to save & load positions? ;O /load ? Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 Write /pos to save your current position in pos.txt Link to comment
idiot Posted January 8, 2008 Share Posted January 8, 2008 what is wrong here? where must i create that pos.txt? i created it there where the savepos.lua is... is that the mistake? Link to comment
rjcnz333 Posted January 8, 2008 Share Posted January 8, 2008 You don't need to create any files. Just unzip this resource. Link to comment
idiot Posted January 10, 2008 Share Posted January 10, 2008 load positions? ;O i can save positions the "Saved!" appears but how to teleport to there ? in the server window of developers preview 2 there comes an error: Attempt to concatenate local 'coment' Link to comment
ChrML Posted January 10, 2008 Share Posted January 10, 2008 fileCreate and fileOpen should now work inside zipped resources from DP2 and newer. You also have a fileGetSize, so you can find the end of file without actually reading all of it. Link to comment
[email protected] Posted January 11, 2008 Share Posted January 11, 2008 load positions? ;O i can save positions the "Saved!" appears but how to teleport to there ? 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
hihohihohiho Posted January 21, 2008 Share Posted January 21, 2008 Write /pos to save your current position in pos.txt What is "" what are we suppose to put into this? Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now