Changing gametypes in script?

Is it possible to have a script change the game type of a server. I noticed that in the fivem resource it has resource_type 'gametype' { name = 'Freeroam' } in it but i’m looking to change that in a script after / as an event is ran. I know some servers do it but I’m unsure how.

Is this a possible thing in FiveM?

Have a look at mapmanager

server_export "getCurrentGameType"
server_export "getCurrentMap"
server_export "changeGameType"
server_export "changeMap"
server_export "doesMapSupportGameType"
server_export "getMaps"
1 Like

Looked trough map manager and found this, but that was about it.

function changeGameType(gameType)
    if currentMap and not doesMapSupportGameType(gameType, currentMap) then
        StopResource(currentMap)
    end

    if currentGameType then
        StopResource(currentGameType)
    end

    StartResource(gameType)
end
1 Like

Well, that’s exactly what you need, no?

I’m trying to change the game mode name without the map nonsense. I’m making it for my AOP Script. To pretty much display it on the server list like:

Capture

So basically change it from Freeroam to whatever is said in the script its self.

natives_server.lua

SetMapName(resource)
SetGameType(gametypeName)

I’m a little slow so If I use the below it would work?

ddEventHandler('chatMessage', function(player, playerName, message)
    if message:sub(1) == '/testcmd' then
	    if IsPlayerAceAllowed(player, "fax.cmds") then
            TriggerClientEvent("chatMessage", -1, "Another Msg to server", {239, 0, 0})
            CancelEvent()
            SetGameType(TestGametypeForList)
        else
            TriggerClientEvent("chatMessage", player, "^1Insignificant Permissions to run command.")
        end
	end
end)

So TestGametypeForList would be displayed on the list

Changing the gametype will restart that resource, meaning it’ll also restart a random compatible map.

You can try using tags instead to display additional information in that screenshot you sent.

Server.cfg:

# a comma-separated list of tags for your server
# for example: sets tags "drifting, cars, racing" or sets tags "roleplay, military, tanks"
sets tags "default"
1 Like

Tags? never knew they existed. So basically the whole gametype thing is not really possible unless it restarts the map or I do a bunch of re writing / editing.

Changing gamemode/gametype will restart maps yes.

1 Like

Thanks for the help :heart:

for me, changing the game type does not work

1 Like