szlend Posted January 15, 2008 Share Posted January 15, 2008 I'm working on a gamemode and have problems making a player spawn on spawnpoints defined by the map. My code is: function startMap(startedMap) local mapRoot = getResourceRootElement(startedMap) local spawns = getElementsByType("spawnpoint", mapRoot) local players = getElementsByType("player") for key, player in pairs(players) do local spawn = spawns[key] -- should get spawnpoint 1 for player 1 local posX = getElementData(spawn, "posX") local posY = getElementData(spawn, "posY") local posZ = getElementData(spawn, "posZ") local angle = getElementData(spawn, "angle") spawnPlayer(player, posX, posY, posZ, angle) outputChatBox(key) end end addEventHandler("onGamemodeMapStart", getRootElement(), startMap) <meta> <info author="Siyo" name="Spawn test" version="0.1" description="Spawn test" type="gamemode"/> <script src="spawn.lua" /> </meta> and the map <map> <spawnpoint posX="2495.1257324219" posY="-1686.6124267578" posZ="13.513834953308" angle="3.4530944824219"/> <spawnpoint posX="2519.9204101563" posY="-1678.9359130859" posZ="14.879755020142" angle="91.500610351563"/> <spawnpoint posX="2509.6416015625" posY="-1654.0524902344" posZ="13.655654907227" angle="135.68103027344"/> <spawnpoint posX="2487.0036621094" posY="-1647.6352539063" posZ="14.0703125" angle="181.4281463623"/> <spawnpoint posX="2471.869140625" posY="-1686.2700195313" posZ="13.5078125" angle="325.85275268555"/> <spawnpoint posX="2469.6413574219" posY="-1650.4163818359" posZ="13.471806526184" angle="183.62147521973"/> <spawnpoint posX="2452.4020996094" posY="-1646.6909179688" posZ="13.468873977661" angle="178.92138671875"/> </map> <meta> <info author="Siyo" version="0.1" type="map" description="spawning" gamemodes="spawn"/> <map src="sp_test.map" /> </meta> I have no idea, what I'm doing wrong. I'm sure that "startMap" function is called and I don't see any warnings or errors with "debugscript 3" either. The screen just stays black and says the map loaded fine. Some help would really be appreciated. PS. Sorry for my bad english ;D Link to comment
Ransom Posted January 15, 2008 Share Posted January 15, 2008 1. First, you need to fade the player camera. If no script is running that fades the camera, it stays black. Its purpose to make MTA look clean between games, instead of showing a floating CJ over a mountain in lala land or something: http://development.mtasa.com/index.php?title=FadeCamera 2. local spawns = getElementsByType("spawnpoint", mapRoot) I dont know a reason why mapRoot would be needed here 3. local spawn = spawns[key] -- should get spawnpoint 1 for player 1 I would do local spawn = spawns[math.random(1, #spawns)] -- choose a random spawn I'm not a master of script I may be wrong. Link to comment
szlend Posted January 15, 2008 Author Share Posted January 15, 2008 1. Ah, thank you . Works fine now. Knew I forgot something basic 2. Isn't mapRoot needed to get the map elements like spawnpoints, flags, objects, etc.? 3. I did that just to see if it works. It wont stay like that since my gamemode will have rounds anyways. Link to comment
Ransom Posted January 15, 2008 Share Posted January 15, 2008 on 2. I'm not too great on that subject but I know I'm doing a script with a custom element at the moment and it doesn't require the root arg. 3. Just put that since you asked about how to spawn with the points in the comment (it seemed) enjoy Link to comment
szlend Posted January 15, 2008 Author Share Posted January 15, 2008 2. Justed tested and it works fine without it. Thanks for the info 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