Changing gametypes in script?


#1

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?


#2

Have a look at mapmanager

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

#3

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

#4

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


#5

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.


#6

natives_server.lua

SetMapName(resource)
SetGameType(gametypeName)

#7

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


#8

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"

#9

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.


#10

Changing gamemode/gametype will restart maps yes.


#11

Thanks for the help :heart: