Jump to content

Map Loading


.:HyPeX:.

Recommended Posts

Hello, i know i can Createobjects with createObject(), but if i create a map within the map editor, then the .map will contain all the objects. Is there a function to actually load the .map? or i should create the object script 1 by 1, becouse if i load the map directly it would be alot easier.

Thanks.

HyPeX

Link to comment

should this work?

  
function CreateZombieArena() 
local xml = xmlLoadFile("ZombieArena.map") 
local Mapnode = xmlFindChild ( Map, "Object id", 0 ) 
local model = xmlNodeGetAttribute(xml, "model") 
local dimension = 50 
local Scale = xmlNodeGetAttribute(xml, "scale") 
local ZombieX = xmlNodeGetAttribute(xml, "posX") 
local ZombieY = xmlNodeGetAttribute(xml, "posY") 
local ZombieZ = xmlNodeGetAttribute(xml, "posZ") 
local ZombieRX = xmlNodeGetAttribute(xml, "rotX") 
local ZombieRY = xmlNodeGetAttribute(xml, "rotY") 
local ZombieRZ = xmlNodeGetAttribute(xml, "rotZ") 
  
for Mapnode do 
createObject( tonumber(model), tonumber(ZombieX),tonumber(ZombieY), tonumber(ZombieZ), tonumber(ZombieRX), tonumber(ZombieRY), tonumber(ZombieRZ), false ) 
setElementDimension( "Object id", dimension ) 
setObjectScale( "Object id", Scale 
end 
addEventHandler("LoadZombieArena", getRootElement(), CreateZombieArena) 

Link to comment

Like this?

  
function CreateZombieArena() 
local xml = xmlLoadFile("ZombieArena.map") 
local Mapnode = xmlFindChild ( Map, "Object id", 0 ) 
local model = xmlNodeGetChildren(xml, "model") 
local dimension = 50 
local Scale = xmlNodeGetChildren(xml, "scale") 
local ZombieX = xmlNodeGetChildren(xml, "posX") 
local ZombieY = xmlNodeGetChildren(xml, "posY") 
local ZombieZ = xmlNodeGetChildren(xml, "posZ") 
local ZombieRX = xmlNodeGetChildren(xml, "rotX") 
local ZombieRY = xmlNodeGetChildren(xml, "rotY") 
local ZombieRZ = xmlNodeGetChildren(xml, "rotZ") 
  
for i,node in ipairs(MapNode) do    
createObject[i]( tonumber(model), tonumber(ZombieX),tonumber(ZombieY), tonumber(ZombieZ), tonumber(ZombieRX), tonumber(ZombieRY), tonumber(ZombieRZ), false ) 
setElementDimension( "Object id", dimension ) 
setObjectScale( "Object id", Scale ) 
end 
end 
addEventHandler("LoadZombieArena", getRootElement(), CreateZombieArena) 

Link to comment

Like this?

  
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()), 
    function() 
    local xml = xmlLoadFile("ZombieArena.map")            
        local Mapnode = xmlNodeGetChildren(xml) 
        g_Objects = {}                             
        for i,node in ipairs(MapObjects) do 
        local model = xmlNodeGetChildren(Mapnode, "model") 
        local Scale = xmlNodeGetChildren(Mapnode, "scale") 
        local ZombieX = xmlNodeGetChildren(Mapnode, "posX") 
        local ZombieY = xmlNodeGetChildren(Mapnode, "posY") 
        local ZombieZ = xmlNodeGetChildren(Mapnode, "posZ") 
        local ZombieRX = xmlNodeGetChildren(Mapnode, "rotX") 
        local ZombieRY = xmlNodeGetChildren(Mapnode, "rotY") 
        local ZombieRZ = xmlNodeGetChildren(Mapnode, "rotZ") 
        g_Objects[i] = xmlNodeGetValue(model, scale, ZombieX, ZombieY, ZombieZ, ZombieRX, ZombieRY, ZombieRZ) 
        end 
    end 
) 
function CreateZombieArena() 
local ObjectCount = #g_Objects      
for i in g_Objects do 
createObject( tonumber(model), tonumber(ZombieX),tonumber(ZombieY), tonumber(ZombieZ), tonumber(ZombieRX), tonumber(ZombieRY), tonumber(ZombieRZ), false ) 
setElementDimension( "createObject", 50 ) 
setObjectScale( "createObject", Scale ) 
end 
end 
addEventHandler("LoadZombieArena", getRootElement(), CreateZombieArena) 

Link to comment
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        local xml = xmlLoadFile ( "ZombieArena.map" ) 
        local Mapnode = xmlNodeGetChildren ( xml ) 
        g_Objects = { } 
        for _, node in ipairs ( Mapnode ) do 
            local attrs = xmlNodeGetAttributes ( node ) 
            table.insert ( g_Objects, { attrs.model, attrs.scale, attrs.posX, attrs.posY, attrs.rotX, attrs.rotY, attrs.rotZ } ) 
        end 
    end 
) 
function CreateZombieArena ( ) 
    for index = 1, #g_Objects do 
        local ob = g_Objects [ index ] 
        local object = createObject ( tonumber ( ob [ 1 ] ), tonumber ( ob [ 3 ] ), tonumber ( ob [ 4 ] ), tonumber ( ob [ 5 ] ), tonumber ( ob [ 6 ] ), tonumber ( ob [ 7 ] ), tonumber ( ob [ 8 ] ), false ) 
        setElementDimension ( object, 50 ) 
        setObjectScale ( object, ob [ 2 ] ) 
    end 
end 
addEventHandler ( "LoadZombieArena", getRootElement(), CreateZombieArena ) 

Link to comment

if i want to load a 2nd arena but at a different function, this version of the code will work? (assuming the original is in a function before)

  
addEventHandler ( "onResourceStart", resourceRoot, 
    function ( ) 
        local xml = xmlLoadFile ( "Lobby.map" ) 
        local Mapnode = xmlNodeGetChildren ( xml ) 
        g_ObjectsLobby = { } 
        for _, node in ipairs ( Mapnode ) do 
            local attrs = xmlNodeGetAttributes ( node ) 
            table.insert ( g_ObjectsLobby, { attrs.model, attrs.scale, attrs.posX, attrs.posY, attrs.rotX, attrs.rotY, attrs.rotZ } ) 
        end 
    end 
) 
  
function CreateLobby ( ) 
    for index = 1, #g_ObjectsLobby do 
        local ob2 = g_ObjectsLobby [ index ] 
        local objectLobby = createObject ( tonumber ( ob2 [ 1 ] ), tonumber ( ob2 [ 3 ] ), tonumber ( ob2 [ 4 ] ), tonumber ( ob [ 5 ] ), tonumber ( ob [ 6 ] ), tonumber ( ob2 [ 7 ] ), tonumber ( ob2 [ 8 ] ), false ) 
        setElementDimension ( objectLobby, 0 ) 
        setObjectScale ( objectLobby, ob2 [ 2 ] ) 
    end 
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...