Geramy92 Posted July 28, 2009 Share Posted July 28, 2009 Hello, Can Anyone help me? I want to save the coordinates of me by tipping "/savepos" in a file local fileHandle = fileOpen("koord.txt") function savepos(theplayer,command,text) if fileHandle then local x,y,z = getElementPosition(thePlayer) local koordinaten = "Koordinaten:" ..x.. "," ..y..","..z.." //"..text..-- check if the creation succeeded fileWrite(fileHandle, koordinaten) -- write a text line fileClose(fileHandle) else outputChatBox("Failed to openFile.",thePlayer)-- close the file once you're done with it end end addCommandHandler("savepos", savepos) but always there is the error Failed to openFile why? Link to comment
ArmedGuy Posted July 28, 2009 Share Posted July 28, 2009 actually saving pos is better to an xml or map... i got a script thats working for this, i just gotta find it first lol Link to comment
Lordy Posted July 28, 2009 Share Posted July 28, 2009 First, do you have that "koords.txt" in your resource folder? If you don't you need to createFile first. Also you wouldn't want to close it every time you call the function, rather use fileFlush to save it and close it on resource stop, or add more ways to open it. Link to comment
Geramy92 Posted July 28, 2009 Author Share Posted July 28, 2009 the file koords.txt is in the foulder of the resource Link to comment
DutchCaffeine Posted July 28, 2009 Share Posted July 28, 2009 Hello,Can Anyone help me? I want to save the coordinates of me by tipping "/savepos" in a file local fileHandle = fileOpen("koord.txt") function savepos(theplayer,command,text) if fileHandle then local x,y,z = getElementPosition(thePlayer) local koordinaten = "Koordinaten:" ..x.. "," ..y..","..z.." //"..text..-- check if the creation succeeded fileWrite(fileHandle, koordinaten) -- write a text line fileClose(fileHandle) else outputChatBox("Failed to openFile.",thePlayer)-- close the file once you're done with it end end addCommandHandler("savepos", savepos) but always there is the error Failed to openFile why? O man, o man, o man ... uhm i write this whole command from scratch. End look to it and see the difference. addCommandHandler("savepos", function(player, cmd, txt) local fh = fileOpen("cords.txt"); if not fh then fh = fileCreate("cords.txt"); if not fh then -- Now it is wrong! We don't have any permissions to create a file... outputChatBox("I can't create the file 'cords.txt'. Please contact an administrator", player); outputServerLog("Can't create the file 'cords.txt'. Please check the folder rights."); -- Return void. To prevent other actions. return; end end local x, y, z = getElementPosition(player); local fString = "[" .. txt .. "]\n" .. tostring(x) .. ", " .. tostring(y) .. ", " .. tostring(z) .. "\n\n"; fileWrite(fh, fString); fileClose(fh); outputChatBox("Youre coordinates are succesfully saved!", player); end); Couple of questions: Why open a file before you start an function, and close the file when you are in the function? Why do you append a integer value to a string? Answer them please, and learn! Alexander actually saving pos is better to an xml or map...i got a script thats working for this, i just gotta find it first lol Why? Do you got an good reasen for that? I also write all my saved positions to a txt file. If i want a map file i'll get my coords in the mta editor. Link to comment
DutchCaffeine Posted July 28, 2009 Share Posted July 28, 2009 okay thank you Your welcome. But please read my message again, there are a couple of questions. Link to comment
ArmedGuy Posted July 28, 2009 Share Posted July 28, 2009 Well Alexander, depends what you gonna do with the coors. If you just gonna use them to put them into an script to for example spawn a car then you can use a .txt, or even easier just put the game in windowed, open admin panel, select urself and write the coors directly to the script. But If you gonna use a command like if you want to save a pos, then go to it later then xml is better. Link to comment
DutchCaffeine Posted July 28, 2009 Share Posted July 28, 2009 Well Alexander, depends what you gonna do with the coors. If you just gonna use them to put them into an script to for example spawn a car then you can use a .txt, or even easier justput the game in windowed, open admin panel, select urself and write the coors directly to the script. But If you gonna use a command like if you want to save a pos, then go to it later then xml is better. True. But mostly i use it to get a coordinate fast, to put something like a pickup or something there. And using the admin panel, you need a set of big brains to keep them in mind. And keep in mind that i'm to lazy to write it down. Link to comment
robhol Posted July 28, 2009 Share Posted July 28, 2009 I made a resource to simplify storing coordinates in different formats, I might release it tomorrow. Edit: or now. https://community.multitheftauto.com/index.html?p ... ils&id=368 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