Jump to content

[REL] In-Game Map Editor


Recommended Posts

Maybe it should work with

objectid[0]["User: XetaQuake"]["Nick: [GP_A]XetaQuake" ] = createObject(2414, 2131.0314941406, 2137.0732421875, 9.671875, 0, 0, 0)  

And with defining the tables before too..

Hmm, now i tried this:

fileWrite (madeFile, "objectid[" ..i.. "] [""User: ".. creatorUserLoad .."] [""Nick: ".. creatorNickLoad .."] = createObject(" .. model .. ", " .. x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz .. ") \r\n") 

But then i get "loading script failed":

offedit.lua:314: ´)´ expected near ´"User: "´

Also i´am not sure that this will export a ["User: XetaQuake"]

Yes, the 2nd one would work but objectid must be defined as 3d table.

And that means? :lol: Sorry ^^

loadstring() returns a functions and using () you call it to execute the string.

You could do something like this:

  
local executeCode = loadstring( "print( 'hello world' )" ) 
-------- 
executeCode() -- this will print "hello world" 
  

Yea, but stuff like this are already used in the script, i think:

  
[..] 
loadstring(buffer)() 
[..] 
  

->

  
[..] 
buffer = fileRead(mFile, filessize) 
[..] 

->

  
[..] 
local mFile = fileOpen(""..mapname..".o23") 
[..] 
local filessize = fileGetSize (mFile) 
[..] 
  

I think the method to load the map file are already good, but anything is wrong.

I doesn´t understand why the script not just ignore the letters?

Other ideas, or explanations pleas?

Link to comment

Look at this:

str = "string""..string 
  
  
  
  
 

And ask yourself why "..string" is red? If you don't know why, learn it: http://www.lua.org/pil/2.4.html

Also, you don't have to start string with "" at the start and its end, like

str = ""..woot.." hmm, what?" 

You can:

str = woot .." hmm, what?" 

Yes, the 2nd one would work but objectid must be defined as 3d table.

And that means? :lol: Sorry ^^

That means, in your map file (.o23) you need to create a table: objectid which is 3D (3 dimensional) because that's how your table looks. Try to create a script like this:

objectid[0]["User: XetaQuake"]["Nick: [GP_A]XetaQuake" ] = createObject(2414, 2131.0314941406, 2137.0732421875, 9.671875, 0, 0, 0) 

And add it to meta.xml. You will get error message saying you try to index '?', why? Because objectid is not created in that script. It seems to be too advanced for you... I'd recommend you try it with OO (object-oriented, http://www.lua.org/pil/16.html ) coding, but it's for more advanced users.

Link to comment

And you have to escape the "" which you want to be in the file.. like

so " would be \".

variable = 1

string ="omg"

functionName(variable, string.."\"quotemark")

would return

functionName(1, "omg"quotemark")

But then the second " after omg would end it so you have to use the \" not "

If I made any sense good, If I didn't, blame me, but I can't explain better :P

Link to comment
Look at this:
str = "string""..string 
  
  
  
  
  
  
 

And ask yourself why "..string" is red? If you don't know why, learn it: http://www.lua.org/pil/2.4.html

Also, you don't have to start string with "" at the start and its end, like

str = ""..woot.." hmm, what?" 

You can:

str = woot .." hmm, what?" 

Uhm, i know that "" is wrong! I just tried to answer on LordAzamth tip, to create ["User: XetaQuake"]

Also i says that ""User: " looks realy stupid for my eyes!

Try to create a script like this

... *looking upwards*

I thank you, LordAzamth, \" was the key :), now it looks like this (ORIGINAL SNIPPET FROM MAP FILE!)

objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(2000, 2160.7631835938, 2198.2272949219, 11.245628356934, 0, 0, 0) 

The script looks like this:

fileWrite (madeFile, "objectid[" ..i.. "] [\"User: "..creatorUserLoad.."\"] [\"Nick: "..creatorNickLoad.."\"] = createObject(" .. model .. ", " .. x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz .. ") \r\n") 

:) Thanks

Now back to 50p, now i get your mentioned error message:

attempt to index field ´?´ (a nile value)

You sayed that "objectid is not created in that script", but my question is now, which script do you mean? Do you mean the map file? And what do you mean exacly with "not created"

Link to comment

When you use loadstring() it's like executing a script, that is running a lua script. So how do you expect the script to have a table that doesn't exist.

Working with multi-dimensional arrays in Lua is much different from C/C++, PHP, etc. because if you want to make an array like,

int objectid[ 100 ][ 32 ][ 32 ]; 

You need to make a loop which makes them:

objectid = { } 
for i=1, 100 do 
    objectid[ i ] = { } -- make a table inside of a table ( objectid[ 100 ][ ] ) 
    for j=1, 32 do 
        objectid[ i ][ j ] = { } -- make another table inside the 2nd dimension ( objectid[ 100 ][ 32 ][ ] ) 
    end 
end 

(Similar code must be included in the "map" file (in your case: .o23), which is dealt as a lua script)

Link to comment

Hi 50p and others :)

I defined objectid now as 3d table. Unfortunately, i get lots of warnings about nil values/bad arguments:

[02:04:32] WARNING: offedit.lua: Bad argument @ 'getObjectModel' - Line: 311

[02:04:32] WARNING: offedit.lua: Bad argument @ 'getElementPosition' - Line: 312

[02:04:32] WARNING: offedit.lua: Bad argument @ 'getObjectRotation' - Line: 313

[02:04:32] WARNING: offedit.lua: Bad argument @ 'getElementData' - Line: 316

[02:04:32] WARNING: offedit.lua: Bad argument @ 'getElementData' - Line: 317

[02:04:32] ERROR: ...Server/mods/deathmatch/resources/offedit/offedit.lua:318: attempt to concatenate local 'rz' (a nil value)

I think its because of the 3d table, is there anything wrong?:

  
function saveThisMap ( player, cmd, mapname ) 
    if mapname then 
        local madeFile = fileCreate("" ..mapname.. ".o23")                -- attempt to create a new file             
        fileWrite(madeFile, "--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor! \r\n \r\n") 
        for i=0,maxobjects do 
         objectid[i] = { } 
          for j=0,maxobjects do 
           objectid[i][j] = { } 
            for k=0,maxobjects do 
             objectid[i][j][k] = { } 
             if objectid[i][j][k] then 
                local model = getObjectModel (objectid[i]) 
                local x, y, z = getElementPosition(objectid[i]) 
                local rx, ry, rz = getObjectRotation(objectid[i]) 
                local creatorUserLoad = getElementData ( objectid[i], "creatorUserSave" ) 
                local creatorNickLoad = getElementData ( objectid[i], "creatorNickSave" ) 
                fileWrite (madeFile, "objectid[" ..i.. "] [\"User: "..creatorUserLoad.."\"] [\"Nick: "..creatorNickLoad.."\"] = createObject(" .. model .. ", " .. x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz .. ") \r\n") 
           end 
          end 
         end 
        end 
        outputChatBox ( "Map saved as: " ..mapname.. "", player ) 
        fileClose ( madeFile ) 
    else 
        outputChatBox ( "No map name specified.  Please use /savemap <name>", player ) 
    end 
end 
addCommandHandler( "savemap", saveThisMap ) 
  

I looks on this problem now some time, and put getObjectModel, getElementPosition, getObjectRotation etc. element to objectid[j][k] instead of objectid (because of my 3d table) - but its still the same.

Possible everything works with my /savemap function, but another snippet from offedit.lua gets in trouble. But i looked up and down the complete script three times.

Link to comment

You didn't understand me correctly... You think you can make a map (or something) and use loadstring() to load that map. Well, you can but you must make that table inside the file (.o23) but you make it inside function saveThisMap() which is pointless if objectid table already exist in that script. You should practice with loadstring() a bit first before you start loading file with it.

Link to comment
You should practice with loadstring() a bit first before you start loading file with it.

Ohhh okay, but its not realy easy to pratice with loadstring(), i tried now some basic ideas on the loadmap function (which include loadstring).

So i added a 3d table on loadmap:

  
        for i=0,maxobjects do 
         objectid[i] = { } 
          for j=0,maxobjects do 
           objectid[i][j] = { } 
            for k=0,maxobjects do 
             objectid[i][j][k] = { } 
             if objectid[i][j][k] then 
  

and i tried to rewrite the loadmap function a little bit.

At the end, it looks like this:

  
function loadMapLua ( player, cmd, mapname ) 
    if mapname then 
        local mFile = fileOpen(""..mapname..".o23")   
        if mFile then    
        for i=0,maxobjects do 
         objectid[i] = { } 
          for j=0,maxobjects do 
           objectid[i][j] = { } 
            for k=0,maxobjects do 
             objectid[i][j][k] = { } 
             if objectid[i][j][k] then 
            clearObjects (player) 
            objectid[i][j][k] = nil 
            objectid[i][j][k] = {} 
            outputChatBox ( "Map loaded: " ..mapname.. "", player )  --output success 
            local buffer                                -- temporary the whola lua file 
            local filessize = fileGetSize (mFile)       --get file size 
            buffer = fileRead(mFile, filessize)         -- read the file length 
            loadstring(buffer)()                        --load lua to string 
            fileClose(mFile)         -- close the file once we're done with it 
        else --if no such map 
            outputChatBox ( "Map " ..mapname.. " failed to load.  Perhaps it doesn't exist?", player ) --output fail 
        end  
             end 
            end 
          end 
        end 
    else 
        outputChatBox ( "No map name specified.  Please use /loadmap <name>", player ) 
    end 
end 
addCommandHandler( "loadmap", loadMapLua ) 
  

But well, it doesn´t work.

I am sure, you mean that i should change loadstring(buffer)() and not the complete function, i read now some information pages in english and german, unfortunately it doesn´t help me much, there just talking about stuff you already says me (thanks for this). But i can´t find documents there write about my problem/questions i have. But now, i understand the problem on this, but i doesn´t can solve it

Well, you can but you must make that table inside the file (.o23) but you make it inside function saveThisMap() which is pointless if objectid table already exist in that script.

Do you mean realy the map file? (for example mymap.o23) I should write lua code in this file?

Link to comment
Well, you can but you must make that table inside the file (.o23) but you make it inside function saveThisMap() which is pointless if objectid table already exist in that script.

Do you mean realy the map file? (for example mymap.o23) I should write lua code in this file?

That's exactly what I was telling you!

loadstring() is not MTA's function to load maps. It's a Lua function to execute Lua code, that's why you need to make your "map" (.o23) lua code. Maps in MTA are in XML format, so your map is different and you use MTA's functions in that map (.o23), like createObject.

Link to comment

Hi,

i tried it now again...and modifies the map file:

  
--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor!  
  
objectid = {} 
maxobjects = 2500 
  
function() 
        for i=0,maxobjects do 
         objectid[i] = { } 
          for j=0,maxobjects do 
           objectid[i][j] = { } 
            for k=0,maxobjects do 
             objectid[i][j][k] = { } 
             if objectid[i][j][k] then 
objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(2000, 2160.7631835938, 2198.2272949219, 11.245628356934, 0, 0, 0)  
             end 
            end 
          end 
        end 
end 
  

(I modifies it with my hands, because i doesn´t need to script it for automatic generation when it doesn´t work - So i can test it first)

But i get this error (EDIT:) when i load the map using /loadmap:

offedit.lua:336: attempt to call a nil value

Line 336:

loadstring(buffer)()                        --load lua to string 

Let me guess: I made anything wrong :lol:

Man, its realy not easy that´s true...i scripted already some scripts, but that´s...not funny. The problem is, i absolutely need it

Help pleas

Link to comment

Function must have a name to be called afterwards. You haven't named the function in any ways but if you want to execute that code you simply remove line with "function()" and the last "end" which closes it. Also, from what I can see in that file you would loop 2500 times to create 2500 objects (same object, same position) use break to stop the loop.

Link to comment

Oh thanks 50p!

Now i am able to load the map :shock::)

it looks like this (writes with hands):

--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor!  
  
objectid = {} 
maxobjects = 2500 
  
  
        for i=0,maxobjects do 
         objectid[i] = { } 
          for j=0,maxobjects do 
           objectid[i][j] = { } 
            for k=0,maxobjects do 
             objectid[i][j][k] = { } 
             if objectid[i][j][k] then 
objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(2000, 2160.7631835938, 2198.2272949219, 11.245628356934, 0, 0, 0)  
             break 
             end 
            end 
          end 
        end  

-------------------

Now, i tries to generate maps like the one above automaticaly when saving map.

Currently it (/savemap) looks like this:

function saveThisMap ( player, cmd, mapname ) 
    if mapname then 
        local madeFile = fileCreate("" ..mapname.. ".o23")                -- attempt to create a new file             
        fileWrite(madeFile, "--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor! \r\n \r\n objectid = {} \r\n maxobjects = 2500 \r\n \r\n  for i=0,maxobjects do \r\n  objectid[i] = { } \r\n  for j=0,maxobjects do \r\n  objectid[i][j] = { } \r\n  for k=0,maxobjects do \r\n  objectid[i][j][k] = { }\r\n  if objectid[i][j][k] then \r\n") 
        for i=0,maxobjects do 
            if objectid[i] then 
                local model = getObjectModel (objectid[i]) 
                local x, y, z = getElementPosition(objectid[i]) 
                local rx, ry, rz = getObjectRotation(objectid[i]) 
                --local creator = getClientName ( player ) 
                --local creatorUser = getAccountName ( getClientAccount ( player )  ) 
                local creatorUserLoad = getElementData ( objectid[i], "creatorUserSave" ) 
                local creatorNickLoad = getElementData ( objectid[i], "creatorNickSave" ) 
                fileWrite (madeFile, "objectid[" ..i.. "] [\"User: "..creatorUserLoad.."\"] [\"Nick: "..creatorNickLoad.."\"] = createObject(" .. model .. ", " .. x .. ", " .. y .. ", " .. z .. ", " .. rx .. ", " .. ry .. ", " .. rz .. ") \r\n") 
                 
                fileWrite(madeFile, "  break \r\n end \r\n end \r\n end \r\n end \r\n") 
            end 
        end 
        outputChatBox ( "Map saved as: " ..mapname.. "", player ) 
        fileClose ( madeFile ) 
    else 
        outputChatBox ( "No map name specified.  Please use /savemap <name>", player ) 
    end 
end 
addCommandHandler( "savemap", saveThisMap ) 

But then, my map looks crap:

--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor!  
  
 objectid = {}  
 maxobjects = 2500  
  
  for i=0,maxobjects do  
  objectid[i] = { }  
  for j=0,maxobjects do  
  objectid[i][j] = { }  
  for k=0,maxobjects do  
  objectid[i][j][k] = { } 
  if objectid[i][j][k] then  
objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(2000, 2046.2290039063, 1414.0323486328, 9.671875, 0, 0, 0)  
  break  
 end  
 end  
 end  
 end  
objectid[1] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(5000, 2048.4353027344, 1413.0714111328, 11.671875, 0, 0, 0)  
  break  
 end  
 end  
 end  
 end  
  

As you can see, the ends and the breaks gets writen after every object. How can i create it only after the last object?

Link to comment

Hi all.

First, i want to thanks 50p for all the great help. :)

Second, a question about a new ERROR i get. I think its not so heavy to solve for peaple there know whats wrong :lol:

/savemap works already perfect, but i have trouble with /loadmap, but it works also quite okay for the first successes.

So my Problem:

When i load a saved map, only the first object on the mapfile gets loaded and are visible in the world!

I get this ERROR when i load a map:

ERROR: [string "--File Generated with OffRoader23´s In-Game..."]:14: attempt to index field ´User: XetaQuake´

And the map file looks like this (generated by script):

--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor!  
  
 objectid = {}  
 maxobjects = 2500  
  
  for i=0,maxobjects do  
  objectid[i] = { }  
  for j=0,maxobjects do  
  objectid[i][j] = { }  
  for k=0,maxobjects do  
  objectid[i][j][k] = { }  
  if objectid[i][j][k] then  
  
objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(2000, 2082.5437011719, 1567.2075195313, 9.8203125, 0, 0, 0)  
objectid[1] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"] = createObject(5000, 2083.306640625, 1567.3236083984, 9.8203125, 0, 0, 0)  
  
  break  
  end  
  end  
  end  
  end  
  

anybody ideas why only the first object loads, and not all the objects after the first object too?

Link to comment

Possible anybody knows whats the problem, when i post the /loadmap function that loads the map:

function loadMapLua ( player, cmd, mapname ) 
    if mapname then 
        local mFile = fileOpen(""..mapname..".o23")   
        if mFile then    
            clearObjects (player) 
            objectid = nil 
            objectid = {} 
            outputChatBox ( "Map loaded: " ..mapname.. "", player )  --output success 
            local buffer                                -- temporary the whola lua file 
            local filessize = fileGetSize (mFile)       --get file size 
            buffer = fileRead(mFile, filessize)         -- read the file length 
            loadstring(buffer)()                        --load lua to string 
            fileClose(mFile)         -- close the file once we're done with it 
        else --if no such map 
            outputChatBox ( "Map " ..mapname.. " failed to load.  Perhaps it doesn't exist?", player ) --output fail 
        end  
    else 
        outputChatBox ( "No map name specified.  Please use /loadmap <name>", player ) 
    end 
end 
addCommandHandler( "loadmap", loadMapLua ) 

I already tried some things with the mapfile, like set the object only objectid[0] [99] [99] instead of objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"]. Just to prevent possible reasons. But thats not work.

Can anybody help me pleas?

Link to comment

You create table objectid in the "map" file. But then you're trying to index a nil value!

You act like

objectid[0]["User: XetaQuake"]
is a table, but it's a nil. Since it's not specified as a table anywhere!

What IS a table in the map file:

objectid[0][0]
since you are specifying some numbers. (2500)

You'll need to figure another way or have something else that helps I guess... =/

Link to comment

Hi Gamesnert,

as i written already, i tested it with numbers too:

I already tried some things with the mapfile, like set the object only objectid[0] [99] [99] instead of objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"]. Just to prevent possible reasons. But thats not work.

So it would look like this:

--File Generated with OffRoader23's In-Game MTA DatchMatch Map Editor!  
  
 objectid = {}  
 maxobjects = 2500  
  
  for i=0,maxobjects do  
  objectid[i] = { }  
  for j=0,maxobjects do  
  objectid[i][j] = { }  
  for k=0,maxobjects do  
  objectid[i][j][k] = { }  
  if objectid[i][j][k] then  
  
objectid[0][99][99] = createObject(2000, 2082.5437011719, 1567.2075195313, 9.8203125, 0, 0, 0)  
objectid[1][99][99] = createObject(2000, 2083.306640625, 1567.3236083984, 9.8203125, 0, 0, 0)  
  
  break  
  end  
  end  
  end  
  end  

But, yea, as i said already: it doesn´t work :cry:

I get this ERROR when using numbers:

ERROR: [string "--File Generated with OffRoader23´s In-Game..."]:14: attempt to index field ´?´

I am wondering, why the first objects loads when i use objectid[0] ["User: XetaQuake"] ["Nick: [GP_A]XetaQuake"], but not the second object.

And when i use objectid[1] [99] [99], no objects loads. lol

Any ideas pleas?

Link to comment

Hi...

oh man, assuming i fix the /loadmap problem, there is another problem i think:

adopted i save a existing map with already existing objects - who will be the creator of the old objects, there was loaded?

Unfortunately, the script doesn´t add just the new objects on a existing map file, the script creates a complete new map on the same name.

So there will be no ElementData on all the already existing objects.

i am at my wits' end, there a so many problems every and every time i get a step forward. I hope somebody gets a clever idea to prevent all problems, or hopefully OffRoader23 or any other person creates a update to save username and nickname on the objects ;(

XetaQuake

Link to comment

Because some guys build crap (blocking streets or just flooding with objects). And then its like impossible to delete the object, because whe gets around 4000+ objects in the map file.

So when one or two peaple build crap - there must stay for ever...or i spend 45 minutes to delete one object - including shutting down the editor or the map :lol:

Since two weeks, the editor is offline now...because of the crap.

And with saving the creator, whe can filtering the person who build crap and delete any object from that user over username

Link to comment

We use a offedit .xml group...and we want that our users are able to build worlds.

But we can not sure taht around 20 users builds no crap, do you understanding? So, when one or two or three users build crap, its often "too late" to delete this user from this group. Also, and thats the most problem, we can not sure wich player builds this object! So i want to get the creator username...

Link to comment

Try with numbers but:

objectid[i][i][i] = createObject(....) 

I think you won't make it... people will. I won't make it for you because I wanted to do it for you I'd do the entire script. I can't see you in scripting, you are not learning anything... You had problem with "attempt to index '?' (nil value)" but you don't know how you fixed it.

And the code you tried with numbers [0][99][99] will not work because [0][99] is not a table when it's executed.

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