.:HyPeX:. Posted October 6, 2013 Posted October 6, 2013 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
Castillo Posted October 6, 2013 Posted October 6, 2013 You can load the .map file with the XML functions and create everything with createObject.
.:HyPeX:. Posted October 6, 2013 Author Posted October 6, 2013 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)
.:HyPeX:. Posted October 6, 2013 Author Posted October 6, 2013 how could i do it then? is it the workout of getting the element right? (locals)
Castillo Posted October 6, 2013 Posted October 6, 2013 You must loop all the children in it. Use: xmlNodeGetChildren
.:HyPeX:. Posted October 6, 2013 Author Posted October 6, 2013 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)
Castillo Posted October 6, 2013 Posted October 6, 2013 No, start from 0, and loop all the children using the function I gave you.
.:HyPeX:. Posted October 6, 2013 Author Posted October 6, 2013 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)
Castillo Posted October 6, 2013 Posted October 6, 2013 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 )
.:HyPeX:. Posted October 7, 2013 Author Posted October 7, 2013 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
Castillo Posted October 7, 2013 Posted October 7, 2013 Yeah, I guess so, if it's the same code but different names, then it should work.
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