Jump to content

Creating the map doesn't work ,


coNolel

Recommended Posts

hello guys ,

i have got a problem while making a little multi arenas scripts, everything as i think is okay  , but in the fact when i select the room it doesn't create the map

here is it the full codes

addEvent("onPlayerChooseRoom", true)
addEventHandler("onPlayerChooseRoom", root, function (dimNum)
outputChatBox("triggered."..dimNum)
end)

Arena = {}
Arena.__index = Arena

Arena.gamemode = {
	["DeathMatch"] = {
	["Name"] = "DeathMatch",
	["Data"] = "DeathMatch",
	["Players"] = {},
	["MaxPlayers"] = 16,
	["Dimension"] = 2,
	["State"] = "not there",
		["Map"] = {
			["Objects"] = {},
			["SpawnPoints"] = {},
			["Pickups"] = {},
			["Markers"] = {}
				}
	},

		["Race"] = {
	["Name"] = "Race",
	["Data"] = "Race",
	["Players"] = {},
	["MaxPlayers"] = 32,
	["Dimension"] = 3,
	["State"] = "not there",
		["Map"] = {
			["Objects"] = {},
			["SpawnPoints"] = {},
			["Pickups"] = {},
			["Markers"] = {}
				}
	},


}

Arena.Maps = {
["DeathMatch"] = {},
["Race"] = {}

}

function Arena.Select(thePlayer, gamemode)
if ( gamemode ~= "" ) then
		--if ( #Arena.gamemode[gamemode]["Players"] < Arena.gamemode[gamemode]["MaxPlayers"] ) then
			if ( getElementData(thePlayer, "Arena") ~= Arena.gamemode[gamemode]["Data"] ) then
			table.insert(Arena.gamemode[gamemode]["Players"], thePlayer)
			setElementData(thePlayer, "Arena", Arena.gamemode[gamemode]["Data"])
			triggerClientEvent(thePlayer, "HideLobby", getRootElement())
			triggerClientEvent(thePlayer, "Note", getRootElement(), "Success", "You have successfully joined the "..Arena.gamemode[gamemode]["Name"].." Room")
			loadTheMap(Arena.gamemode[gamemode]["Data"])
			return true
			else
			triggerClientEvent(thePlayer, "NoteTwo", getRootElement(), "info", "You are already in the "..Arena.gamemode[gamemode]["Name"].." Room ! ")
			return false
			end
		--end
end
end


addEvent("Arena.Select", true)
addEventHandler("Arena.Select", getRootElement(), Arena.Select)

function getTheMaps ()
 -- no maps here, arena is empty
 Arena.Maps["DeathMatch"] = {}
 Arena.Maps["Race"] = {}


-- getting the maps for each arena asd qweweqeq :p

	for index , resource in ipairs(getResources ()) do
	local theMap = getResourceName(resource)

		if ( string.find(theMap, "[DM]" or "race-" , 1 , true) ) then
		local theMapName = getResourceInfo(resource, "name")
		outputChatBox(theMapName)
		table.insert(Arena.Maps["DeathMatch"], { theMap, theMapName } )
		
		elseif ( string.find(theMap, "Race", 1 , true) ) then
		local theMapName = getResourceInfo(resource, "name")
		outputChatBox(theMapName)
		table.insert(Arena.Maps["Race"], { theMap, theMapName } )
			
		end	
	end
end

addEventHandler("onResourceStart", getRootElement(getThisResource()), getTheMaps)
function RandomMap(list)
local map
	if ( list ~= "") then
	local id = math.random(#Arena.Maps[list])
	if id > 0 then
	map = id
	
	end
	return map
	end
end

function getMapName(list, id , version)

local theMapName = "N/A"
	if ( list ~= "" and id > 0 and #Arena.Maps[list] >= 0 ) then
	
	theMapName = Arena.Maps[list][id][version]

	end 
	return theMapName -- 1 resourceName 2 meta name
end

function loadTheMap(gamemode)
if (gamemode ~= "" ) then
Arena.gamemode[gamemode]["Map"]["Objects"] =  {}
Arena.gamemode[gamemode]["Map"]["SpawnPoints"] =  {}
Arena.gamemode[gamemode]["Map"]["Markers"] =  {}
Arena.gamemode[gamemode]["Map"]["Pickups"] =  {}


		local mapId = RandomMap(gamemode)
		local mapResource = getMapName(gamemode, mapId, 1 )
		local mapName = getMapName(gamemode, mapId, 2 )
		local meta = xmlLoadFile(":"..mapResource.."/meta.xml")
		
		if ( meta ) then 
			local mapChild = xmlFindChild(meta, "map",0 )
			
			if ( mapChild ) then
			local mapSource = xmlNodeGetAttribute(mapChild, "src")
			local mapFile = xmlLoadFile(":"..mapResource.."/"..mapSource)
			
			if ( mapFile ) then
				local childrens = xmlNodeGetChildren(mapFile)
				
				for _ , child in ipairs(childrens) do
				local item_id = xmlNodeGetAttribute(child , "id")
				local item_model = xmlNodeGetAttribute(child , "model")
				local item_posX = xmlNodeGetAttribute(child , "posX")
				local item_posY = xmlNodeGetAttribute(child , "posY")
				local item_posZ = xmlNodeGetAttribute(child , "posZ")
				local item_rotX = xmlNodeGetAttribute(child , "rotX")
				local item_rotY = xmlNodeGetAttribute(child , "rotY")
				local item_rotZ = xmlNodeGetAttribute(child , "rotZ")
				local item_type = xmlNodeGetAttribute(child , "type")
				local item_vehicle = xmlNodeGetAttribute(child , "vehicle")
				local item_size = xmlNodeGetAttribute(child , "size")
				local item_alpha = xmlNodeGetAttribute(child , "alpha")
				local item_collision = xmlNodeGetAttribute(child , "collision")
				local item_scale = xmlNodeGetAttribute(child , "scale")

				if ( string.find(item_id, "object", 1 , true ) or string.find(item_id, "AMT", 1 , true ) ) then
				table.insert(Arena.gamemode[gamemode]["Map"]["Objects"], { item_model, item_posX, item_posY, item_posZ, item_rotX, item_rotY, item_rotZ, item_alpha, item_collision, item_scale, Arena[gamemode]["Dimension"] })
				elseif ( string.find(item_id, "spawnpoint", 1 , true) ) then
				table.insert(Arena.gamemode[gamemode]["Map"]["SpawnPoints"], { item_vehicle,item_posX, item_posY, item_posZ, item_rotX, item_rotY, item_rotZ, Arena[gamemode]["Dimension"]} ) 
				
				end
				
				end
			
			end
			
			end
			for _ , player in ipairs(Arena.gamemode[gamemode]["Players"] ) do 
			Arena.createMap(player, Arena.gamemode[gamemode]["Data"], mapName)
			outputChatBox("creating map")
			end
		else
		outputChatBox("Loading map failed")
		loadTheMap(gamemode)
		end
		xmlUnloadFile(meta)
end
end

function Arena.createMap(thePlayer, Mode, Map)
outputChatBox("creating map for the player : "..getPlayerName(thePlayer))
outputChatBox("creating the map in the "..Mode.." room .")
outputChatBox("creating map : "..Map)

triggerClientEvent( thePlayer, "Arena:CreateMap", getRootElement(), Arena.gamemode[Mode]["Map"]["Objects"],  Arena.gamemode[Mode]["Map"]["Pickups"],  Arena.gamemode[Mode]["Map"]["Markers"])
local randomSpawn = math.random(#Arena.gamemode[Mode]["Map"]["SpawnPoints"])
local Spawn = Arena.gamemode[Mode]["Map"]["SpawnPoints"][randomSpawn]

fadeCamera(thePlayer, true)

if ( Arena.gamemode[Mode]["State"] == "not there") then
spawnPlayer(thePlayer, Spawn[2] , Spawn[3], Spawn[4])
setElementDimension(thePlayer, Arena.gamemode[Mode]["Dimension"])
local veh = createVehicle(Spawn[1],Spawn[2],Spawn[3],Spawn[4],Spawn[5],Spawn[6],Spawn[7])
setElementDimension(veh, Arena.gamemode[Mode]["Dimension"])
warpPedIntoVehicle(thePlayer, veh)
setCamerTarget(thePlayer, thePlayer)

end
end

addCommandHandler("join",
function (thePlayer)
Arena.Select(thePlayer, "DeathMatch")

end)

addCommandHandler("m",
function ()
outputChatBox("ja")
outputChatBox(Arena.gamemode["DeathMatch"]["Map"]["Objects"])
outputChatBox(Arena.gamemode["DeathMatch"]["Map"]["SpawnPoints"])
outputChatBox(Arena.gamemode["DeathMatch"]["Map"]["Markers"])
outputChatBox(Arena.gamemode["DeathMatch"]["Map"]["Pickups"])
end)

and for Client creating map's objects :

addEvent("Arena:CreateMap", true)
addEventHandler("Arena:CreateMap", getRootElement(), function ( Objects,Pickups, Markers )
outputChatBox("it works !")

	for _, _Object in ipairs(Objects)
	local obj = CreateObject(_Object[1],_Object[2],_Object[3],_Object[4],_Object[5],_Object[6],_Object[7])
	if ( _Object[10] ) then
	setObjectScale(obj, _Object[10])
	end
	
	setElementDimension(obj, _Object[11])
	
	if ( _Object[9] and _Object[9] == "false") then
	
	setElementCollisionEnabled(obj, false)
	end
	
	end

	for _ , _pickup in ipairs(Pickups) do
	local col = createColSphere(_pickup[3],_pickup[4],_pickup[5], 3.0)
	setElementDimension(col , _pickup[6])

	if ( _pickup[1] == "nitro" ) then
		local pick = createObject( 2221, _pickup[3], _pickup[4], _pickup[5] )
		setElementData( col, "type", "nitro" )
		setElementDimension( pick, _pickup[6] )
		
	elseif ( _pickup[1] == "repair" ) then
		local pick = createObject( 2222, _pickup[3], _pickup[4], _pickup[5] )
		setElementData( col, "type", "repair" )
		setElementDimension( pick, _pickup[6] )
	elseif ( _pickup[1] == "vehiclechange" ) then
		local pick = createObject( 2223, _pickup[3], _pickup[4], _pickup[5] )
		setElementDimension( pick, _pickup[6] )
		setElementData( col, "type", "vehchange" )
		setElementData( col, "changeTo", _pickup[2] )
	
	end
	end
	
end)

 

Edited by coNolel
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...