manawydan Posted March 11, 2016 Share Posted March 11, 2016 so, i am try make one gamemode, but i am get error in spawn core_server line 62,63 "spawnpoint" nil. --[[ Project: Humans vs Zombies Script: core_server author: Manawydan ]] local firtsPlayerZombie = nil local roundTimer = nil local playerTeam = createTeam("Survivors",0,0,255) local zombieTeam = createTeam("Zombies",255,0,0) local roundDuration = 10*60*1000 local playersTable = {} local playerSkins = {0,1,2,3} local zombieSkin = {5,6,7} function Start() local player_n = #UpdatePlayerTable() if(player_n>=2)then StartRoundNormal() else StartRoundNoPlayers() end end function UpdatePlayerTable() playersTable = {} for k,v in ipairs(getElementsByType("player")) do table.insert(playersTable,v) end return playersTable end function StartRoundNormal() SpawnPlayers() setTimer(SetFirtsPlayerZombie,10*1000,1) roundTimer = exports.missiontimer:createMissionTimer (roundDuration,true,"%m:%s",0.5,10,true,"default-bold",1,255,255,255) addEventHandler ( "onMissionTimerElapsed", roundTimer,OnTimerOver ) end function StartRoundNoPlayers() end function OnMapLoad(startedMap) mapRoot = getResourceRootElement(startedMap) outputChatBox("map started ok!") UpdatePlayerTable() StartRoundNormal() end addEventHandler ( "onGamemodeMapStart", root, OnMapLoad ) function OnGamemodeStart() outputChatBox("gamemode start ok") end addEventHandler ( "onGamemodeStart", resourceRoot, OnGamemodeStart ) function SpawnPlayers() local mapSpawns = getElementsByType("spawnpoint") print("number spawns: "..#mapSpawns.." players: "..#playersTable) for k,v in ipairs(playersTable) do local spIndex = mapSpawns[math.random(#mapSpawns)] local x = getElementData(mapSpawns[spIndex],"posX") local y = getElementData(mapSpawns[spIndex],"posY") local z = getElementData(mapSpawns[spIndex],"posZ") local rot = math.random(359) local skin = playerSkins[math.random(#playerSkins)] spawnPlayer(v,x,y,z,rot,skin) setPlayerTeam(v,playerTeam) end end function SetFirtsPlayerZombie() if(#UpdatePlayerTable()>=2)then firtsPlayerZombie = getRandomPlayer() triggerEvent("onPlayerBecameZombie",firtsPlayerZombie) outputChatBox("O player: "..getPlayerName(firtsPlayerZombie).." Virou Zombie!") end end function SetPlayerZombie() takeAllWeapons(source) setElementModel(source,zombieSkin[math.random(#zombieSkin)]) setElementData(source,"zombie",true) setElementHealth(source,200) setPlayerTeam(source,zombieTeam) end addEvent("onPlayerBecameZombie",true) addEventHandler("onPlayerBecameZombie",root,SetPlayerZombie) function OnTimerOver() end _getPlayerName = getPlayerName getPlayerName = function(player) return string.gsub(_getPlayerName (player),"#%x%x%x%x%x%x","") end meta: <meta> <info author="Manawydan" name = "Players Vs Zombies" version="1" type="gamemode" edf:definition="edf/playersVsZombies.edf" /> <script src="core_client.lua" type="client" /> <script src="core_server.lua" type="server" /> </meta> edf(inside gamemode edf folder): <def name = "Players Vs Zombies"> <element name = "spawnpoint" friendlyname = "spawnPoint"> <data name = "position" type = "coord3d" default="0,0,0"/> </element> </def> And a little test map: <map edf:definitions="Players_vs_Zombies,editor_main"> <pickup id="pickup (Colt 45) (1)" type="22" interior="0" amount="100" respawn="30000" dimension="0" alpha="255" posX="249.89999" posY="1800.5" posZ="7.4" rotX="0" rotY="0" rotZ="0"></pickup> <spawnpoint id="spawnpoint1" posX="250.10000610352" posY="1801.1999511719" posZ="7"/> </map> the problem is player not spawn, get error in line 62,63, say the position vector is nil. Anyone can help? Thanks Link to comment
Moderators Citizen Posted March 11, 2016 Moderators Share Posted March 11, 2016 spIndex is not the index of the spawn, but it is the spawn itself already ! (Like you did for the skin variable at line 66 (line 10 here)) function SpawnPlayers() local mapSpawns = getElementsByType("spawnpoint") print("number spawns: "..#mapSpawns.." players: "..#playersTable) for k, v in ipairs(playersTable) do local spawn = mapSpawns[math.random(#mapSpawns)] local x = getElementData(spawn, "posX") local y = getElementData(spawn, "posY") local z = getElementData(spawn, "posZ") local rot = math.random(359) local skin = playerSkins[math.random(#playerSkins)] spawnPlayer(v, x, y, z, rot, skin) setPlayerTeam(v, playerTeam) end end Link to comment
manawydan Posted March 11, 2016 Author Share Posted March 11, 2016 lol a noob error thanks man 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