• Print

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

0 Members and 1 Guest 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.

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: votemap, but for gamemodes
« Reply #3 on: February 12, 2017, 02:45:56 pm »
Did you tryed debuging= Like chek if the function rtgDone get called? then what Variables it gets then in the single parts print "Changing gamemode to:" that should give you feedback if it even gets called.

Code: Lua
  1. local function rtgDone ( t, ply, sandbox, bhop, terrortown )
  2.         local results = t.results
  3.         local winner
  4.         local winnernum = 0
  5.         PrintTable(t)
  6.         print("Sandbox: "..#sandbox)
  7.         print("bhop: "..#bhop)
  8.         print("TTT: "..#terrortown)
  9.  
  10.         for id, numvotes in pairs( results ) do
  11.                 if numvotes > winnernum then
  12.                         winner = id
  13.                         winnernum = numvotes
  14.                 end
  15.         end
  16.        
  17.         if #sandbox > 1 then
  18.                 ULib.consoleCommand( "gamemode sandbox" )
  19.                 print("Changing gamemode to Sandbox")
  20.         end
  21.         if #bhop > 1 then
  22.                 ULib.consoleCommand( "gamemode bhop" )
  23.                 print("Changing gamemode to bhop")
  24.         end
  25.         if #terrortown > 1 then
  26.                 ULib.consoleCommand( "gamemode terrortown" )
  27.                 print("Changing gamemode to TTT")
  28.         end
  29. end
  30.  

Try that and if it gives you feedback you should be fine then we can talk about other things.
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline Splitzle

  • Newbie
  • *
  • Posts: 6
  • Karma: 1
Re: votemap, but for gamemodes
« Reply #4 on: February 12, 2017, 02:59:36 pm »
This was shown in the server console and it wasn't there before, so I guess it is being called.

Code: [Select]
spl voted for: Sandbox
args:
callback        =       function: 0x216d1a70
options:
                1       =       Sandbox
                2       =       Bhop
                3       =       TTT
results:
                1       =       1
title   =       Switch gamemode to...
voters  =       3
votes   =       1
L 02/12/2017 - 17:55:06: Lua Error: addons/ulx/lua/ulx/modules/sh/vote.lua:414: attempt to get length of local 'sandbox' (a nil value)
addons/ulx/lua/ulx/modules/sh/vote.lua:414: attempt to get length of local 'sandbox' (a nil value)

Nothing was said in the game chat.
« Last Edit: February 12, 2017, 03:02:31 pm by Splitzle »

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: votemap, but for gamemodes
« Reply #5 on: February 12, 2017, 03:36:12 pm »
Well the error message simply means that you try to get the lenght from a not existing table.
With #sandbox you get the lenght of an array but it looks like sandbox isn't given. That could be because Sandbox wasnt selected .. you should disable the 3 Variable prints at the beginning and try again ^^' btw you shouldnt edit ULX files .. you should create a new file for that. ULib is also aviable without editing the vote.lua
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

  • Print