HU/Writing Gamemodes

From Multi Theft Auto: Wiki
Jump to navigation Jump to search

Ez az útmutató megpórbálja felvázolni a megfelelő gamemode írásának folyamatát. Ha csak az MTA-hoz való szkripteléssel kezdte, akkor érdemes lehet először megnézni a többi tutoriált is a Főoldalon.

Bevezetés

A gamemode az egy olyan resource, amely az indulást követően szabályozza az összes játékmenetet. Ez magába foglalhatja például azt, hogy egy játékos mit csináljon, játékosok spawnolása, csapatok létrehozása, meghatározza, hogy egy játékosnak mit kell tennie ahhoz, hogy nyerjen, vagy pontot szerezzen, és még sok más. Például a Race és a Deathmatch.

Mit jelent a "sajátos gamemode"?

Egyszerűen megfogalmazva, a megfelelő gamemode az, amely teljes mértékben kihasználja az MTA .map fájlrendszerét. Ez azt jelenti, hogy a gamemode-oknak nincsenek map specifikus adataik, mint például játékosok, vagy járművek pozíciói. Ehelyett a gamemode-oknak képesnek kell lenniük a .map fájlok betöltésére, amelyek meghatározzák ezeket az adatokat. Ezáltal a gamemode több mapot is tartalmazhat, emelett a játékosok létrehozhatnak .map fájlokat az MTA map editorjában, amely sokkal kényelmesebb, mint a kódírás.

A "sajátos gamemode" nyilvánvaló példája az MTA:Race. Ez sok lehetőséget tesz lehetővé a .map fájlon belül. A spawnpoint-ok, object-ek stb. módosításához nem kell a felhasználónak a gamemode-ot szerkeszteni.

Map Fájlok

A map fájlok alapvetően XML kiterjesztéssel rendelkező dokumentumok. Ezek egy, vagy több gamemode-ban a játszani kívánt környezetet határozzák meg. Ezek azonban nem változtatják meg a játék szabályait - ezeket a gamemode-ok határozza meg.

Each element in a map corresponds to a node in the .map file. There is standard syntax for common things like spawnpoints, objects and vehicles; however, for "special", gamemode specific information, you need to invent your own syntax.

Példa

Vegyük például a Capture the Flag gamemode-ot. A map-nak ehhez a gamemode-hoz elsősorban spawnpoint-okat és flag helyeket kell meghatároznia, valamint objekteket és járműveket. Egy egyszerűsített map fájl így nézhet ki:

<map>
    <spawnpoint id="spawnpoint1" posX="1959.5487060547" posY="-1714.4613037109" posZ="877.25219726563" rot="63.350006103516" model="0"/>
    <pickup id="Armor 1" posX="1911.083984375" posY="-1658.8798828125" posZ="885.40216064453" type="armor" health="50" respawn="60000"/>
    <flag posX="1959.5487060547" posY="-1714.4613037109" posZ="877.25219726563" team="blue" />
    ...
</map>

Két MTA elemet láthat - egy spawnpoint-ot és egy pickup-ot. Ami ennél is fontosabb, hogy ez a .map fájl tartalmaz egy "flag" sort, mely meghatározza a flag színét és helyzetét. A spawnpoint-ot és a pickup-ot egy külső recource is kezelheti, de az egyéni elemeket a gamemode-nak kell feldolgoznia.

Összefoglalva - pályakészítők ötleit várjuk, mint ahogy az MTA:Race-ben volt. A felhasználóknak nem kellene, hogy szükséges legyen, hogy egyáltalán hozzányúljanak a gamemode scripthez.

Példa a .map információinak kinyerésére

Ahogy azt korábban is említettük, a gamemode-nak szüksége van a map fájlban meghatározott egyéni elemek lekérésére és feldolgozására. Ez meglehetősen egyszerű, amint azt az alábbiakban bemutatjuk.

-- retrieve a table with all flag elements
local flagElements = getElementsByType ( "flag" )
-- loop through them
for key, value in pairs(flagElements) do
	-- get our info
	local posX = getElementData ( value, "posX" )
	local posY = getElementData ( value, "posY" )
	local posZ = getElementData ( value, "posZ" )
	local team = getElementData ( value, "team" )
	-- create an object according to the flag position
	createObject ( 1337, posX, posY, posZ )
	-- output the team that we created a base for
	outputChatBox ( "Base for team " .. team .. " created" )
end

The getElementsByType function retrieves a table of all the elements of a certain type (the type corresponds to the node name in the .map file). This works for both custom types and built-in MTA types (like "vehicle" or "player"). getElementData can be used to retrieve the xml attributes set in the .map file. In this simple example, an object is created at the flag's location and a message is outputted in the chatbox. In reality, you will of course need to do more during map loading, like in this case setting up collision shapes to detect players taking the flag.

Map manager

Having read the section above it should be clear that a gamemode should always consist of two parts:

  • The gamemode resource that always stays the same
  • Many different maps resources that give the gamemode map-specific information

Now instead of writing a map-loader for every single gamemode, the Map manager provides functions to load gamemodes and maps. Simply put, when you enter the correct command (for example 'gamemode ctf ctf-italy') it will start both resources 'ctf' and 'ctf-italy' while triggering an event (onGamemodeMapStart) to tell the 'ctf' resource that a map was loaded. The 'ctf' resource can then access the information 'ctf-italy' contains and start spawning players etc.

How to use the mapmanager

To use the mapmanager service, your gamemode resource has to be tagged as such first. More specifically you'll be setting the "type" attribute of its <info> tag to "gamemode" inside meta.xml. Also, you can set the "name" attribute to a friendly name (like "Capture the flag") that will be shown on ASE instead of the resource name.

<!-- meta.xml in "cowcatapult" gamemode -->
<meta>
    <info type="gamemode" name="Cow catapulting 2.0"/>
</meta>

If your gamemode is going to load custom maps, you should add handlers for

  • onGamemodeMapStart
  • onGamemodeMapStop (if any unloading is necessary)

These are fired when a map for your gamemode is started or stopped, and pass the map resource as a parameter. Within the handler function for these events you can extract all info you need from the resource's map files and configuration files.

Example

function startCtfMap( startedMap ) -- startedMap contains a reference to the resource of the map
    local mapRoot = getResourceRootElement( startedMap )        -- get the root node of the started map
    local flagElements = getElementsByType ( "flag" , mapRoot ) -- get all flags in the map and store them in a table
    -- go on loading information like in the example above
    -- spawn players etc.
end
addEventHandler("onGamemodeMapStart", getRootElement(), startCtfMap)

Making maps compatible

Maps are separate resources. This is done so no editing of the gamemode resource is ever necessary in order to create a custom map, and also allows you to pack map-specific scripts/config files with them.

To make a map compatible with your gamemode, open its resource's meta.xml and tag it as well: the "type" attribute must be set to "map", and the "gamemodes" attribute must be a comma-separated list (no spaces) of gamemode resource names that the map works with.

<!--map's meta.xml-->
<meta>
    <info type="map" gamemodes="cowcatapult,assault,tdm"/>
</meta>

Once you have everything set up, admins will use these two commands to start/stop gamemodes: /gamemode gamemodeName [mapName] (optional parameter allows picking an initial map, defaults to none) /changemap mapName [gamemodeName] (optional parameter specifies the gamemode to start the map with, defaults to the current one)

Map manager exports a few more access functions which you don't have to use, but may be useful.

What else should you do

There are several other resources that gamemodes should use/be compliant with.

Helpmanager

The helpmanager is ought to be the standard interface for players when they need help. If you use the helpmanager to display your gamemode's help, every player that used helpmanager before (e.g. in other gamemodes) will immediately know how to get there. It also displays help for different resources running resources in one window, if necessary.

There are basicially two ways to use the helpmanager:

  • Provide a simple text that explains how to use your gamemode
  • Request a GUI element from the helpmanager that will be displayed in its own tab in the helpmanager window and lets you add any GUI elements to it. This is the recommended way for gamemodes that need to display more complex information that needs its own GUI.

Read the helpmanager help page for details on how to do it.

Scoreboard

Scoreboard displays players and teams currently ingame. You add custom columns to it to provide map specific information. For example the column 'points' in the 'ctf' gamemode could represent the player's points gained through kills or captures. As usual, see the scoreboard help page for more information.

Map cycler

The map cycler controls what gamemodes and maps are played on a server. You can specifiy for example how many times in a row a map will be played until it switches to the next. To achieve this, you need to tell the map cycler when your gamemode finished (e.g. when a round ends).

Fordította

2018.11.11. Surge