Jump to content

Help creating spawnpoint?


Recommended Posts

Hello

I'm new to scripting, but wanted to try and see how far I could go scripting my own server. I've been following the wiki for most of it, and currently I'm stuck figuring out how to make the default spawn.

I'm following this page: https://wiki.multitheftauto.com/wiki/Resource:Mapmanager

Its pretty straight forwards until:

Note that "spawnpoint" is the type of the element, used in getElementsByType function; likewise, "id" is used in getElementByID function.

To load the map data, the main script needs access to the map resource itself. Now let's edit the script.lua file in "myserver" resource. Enter the following code:

Does this mean I have to make the script.lua resource? Or edit an existing one?

If I have to create a new one, the wiki says nothing about how to create the meta.xml for it.

Link to comment

Yeah but I meant specifically for that file

Would it just be:

<meta> 
        <info author="Evildropbear" version="1" name="script" description="Loads co-ordinates from map" type="script"/> 
        <script src="script.lua" type="server"/> 
</meta> 

If I use that, and then type in the console 'gamemode myserver mymap' nothing happens :oops:

Since the files are practically copied straight out of the wiki, I can't really see what might be wrong with them, but I'll post them anyway.

mymap.map

<map> 
   <spawnpoint id="spawnpoint1" posX="-1986.1390" posY="-1282.9088" posZ="23.9697" rot="63.350006103516" model="0"/> 
</map 

script.lua

function loadMap(startedMap) 
    mapRoot = getResourceRootElement(startedMap) 
end 
  
addEventHandler("onGamemodeMapStart", getRootElement(), loadMap) 
  
function joinHandler() 
    local spawn = getElementsByType("spawnpoint", mapRoot) 
    local x,y,z,r 
    for key, value in pairs(spawn) do 
        x = getElementData(value, "posX") 
        y = getElementData(value, "posY") 
        z = getElementData(value, "posZ") 
        r = getElementData(value, "rot") 
    end 
    spawnPlayer(source, x, y, z) 
    fadeCamera(source, true) 
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...