General > Developers Corner

votemap, but for gamemodes

(1/2) > >>

Splitzle:
Alright, I'm very very very new to LUA and what I've made so far is just from copying parts of other things in ULX. I want to make a votemenu that will change the gamemode.

With the code shown below, I can get a menu to pop up but nothing happens when I select an option. Can someone tell me how to fix this? I pretty much don't know what I'm doing so this may be very very wrong code.


--- Code: ---local function rtgDone ( t, ply, sandbox, bhop, terrortown )
local results = t.results
local winner
local winnernum = 0
for id, numvotes in pairs( results ) do
if numvotes > winnernum then
winner = id
winnernum = numvotes
end
end

if #sandbox > 1 then
ULib.consoleCommand( "gamemode sandbox" )
end
if #bhop > 1 then
ULib.consoleCommand( "gamemode bhop" )
end
if #terrortown > 1 then
ULib.consoleCommand( "gamemode terrortown" )
end
end



function ulx.rtg( calling_ply )
local sandbox = "Sandbox"
local bhop = "Bhop"
local terrortown = "TTT"

if ulx.voteInProgress then
ULib.tsayError( calling_ply, "There is already a vote in progress. Please wait for the current one to end.", true )
return
end

local msg = "Switch gamemode to..."

ulx.doVote( msg, { sandbox, bhop, terrortown }, rtgDone )

end
local rtg = ulx.command( CATEGORY_NAME, "ulx rtg", ulx.rtg, "!rtg" )
rtg:defaultAccess( ULib.ACCESS_ADMIN )
rtg:help( "Starts a vote to switch the gamemode." )
--- End code ---

captain1342:
You forgot to reload the map .. if you change the gamemode you need to reload the map otherwise it isn't doing anything.

Splitzle:

--- Quote from: captain1342 on February 12, 2017, 01:47:36 PM ---You forgot to reload the map .. if you change the gamemode you need to reload the map otherwise it isn't doing anything.

--- End quote ---
I know, if I do "gamemode sandbox" in the server console it tells me that the gamemode was changed, then I reload the map. However with this it says nothing when an option is picked and reloading the map does nothing as well.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given

[0] Board index

Go to full version