Author Topic: votemap, but for gamemodes  (Read 2009 times)

0 Members and 2 Guests are viewing this topic.

Offline Splitzle

  • Newbie
  • *
  • Posts: 6
  • Karma: 1
votemap, but for gamemodes
« on: February 12, 2017, 11:40:54 AM »
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: [Select]
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." )

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: votemap, but for gamemodes
« Reply #1 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.
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline Splitzle

  • Newbie
  • *
  • Posts: 6
  • Karma: 1
Re: votemap, but for gamemodes
« Reply #2 on: February 12, 2017, 02:34:47 PM »
You forgot to reload the map .. if you change the gamemode you need to reload the map otherwise it isn't doing anything.
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