• Print

Author Topic: Unknow Error In Console and cant use ULX adverts  (Read 6003 times)

0 Members and 1 Guest are viewing this topic.

Offline JJ_Ellis

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Unknow Error In Console and cant use ULX adverts
« on: October 19, 2015, 12:41:43 pm »
For some reason I keep receiving this error in console
[ERROR] addons/ulx/lua/ulx/modules/sh/chat.lua:281: 'end' expected (to close 'if' at line 252) near '<eof>'
  1. unknown - addons/ulx/lua/ulx/modules/sh/chat.lua:0
 
This is my code:

Code: Lua
  1. -- This module holds any type of chatting functions
  2. CATEGORY_NAME = "Chat"
  3.  
  4. ------------------------------ Psay ------------------------------
  5. function ulx.psay( calling_ply, target_ply, message )
  6.         ulx.fancyLog( { target_ply, calling_ply }, "#P to #P: " .. message, calling_ply, target_ply )
  7. end
  8. local psay = ulx.command( CATEGORY_NAME, "ulx psay", ulx.psay, "!p", true )
  9. psay:addParam{ type=ULib.cmds.PlayerArg, target="!^", ULib.cmds.ignoreCanTarget }
  10. psay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  11. psay:defaultAccess( ULib.ACCESS_ALL )
  12. psay:help( "Send a private message to target." )
  13.  
  14. ------------------------------ Asay ------------------------------
  15. local seeasayAccess = "ulx seeasay"
  16. if SERVER then ULib.ucl.registerAccess( seeasayAccess, ULib.ACCESS_OPERATOR, "Ability to see 'ulx asay'", "Other" ) end -- Give operators access to see asays echoes by default
  17.  
  18. function ulx.asay( calling_ply, message )
  19.         local format
  20.         local me = "/me "
  21.         if message:sub( 1, me:len() ) == me then
  22.                 format = "(ADMINS) *** #P #s"
  23.                 message = message:sub( me:len() + 1 )
  24.         else
  25.                 format = "#P to admins: #s"
  26.         end
  27.  
  28.         local players = player.GetAll()
  29.         for i=#players, 1, -1 do
  30.                 local v = players[ i ]
  31.                 if not ULib.ucl.query( v, seeasayAccess ) and v ~= calling_ply then -- Calling player always gets to see the echo
  32.                         table.remove( players, i )
  33.                 end
  34.         end
  35.  
  36.         ulx.fancyLog( players, format, calling_ply, message )
  37. end
  38. local asay = ulx.command( CATEGORY_NAME, "ulx asay", ulx.asay, "@", true, true )
  39. asay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  40. asay:defaultAccess( ULib.ACCESS_ALL )
  41. asay:help( "Send a message to currently connected admins." )
  42.  
  43. ------------------------------ Tsay ------------------------------
  44. function ulx.tsay( calling_ply, message )
  45.         ULib.tsay( _, message )
  46.  
  47.         if util.tobool( GetConVarNumber( "ulx_logChat" ) ) then
  48.                 ulx.logString( string.format( "(tsay from %s) %s", calling_ply:IsValid() and calling_ply:Nick() or "Console", message ) )
  49.         end
  50. end
  51. local tsay = ulx.command( CATEGORY_NAME, "ulx tsay", ulx.tsay, "@@", true, true )
  52. tsay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  53. tsay:defaultAccess( ULib.ACCESS_ADMIN )
  54. tsay:help( "Send a message to everyone in the chat box." )
  55.  
  56. ------------------------------ Csay ------------------------------
  57. function ulx.csay( calling_ply, message )
  58.         ULib.csay( _, message )
  59.  
  60.         if util.tobool( GetConVarNumber( "ulx_logChat" ) ) then
  61.                 ulx.logString( string.format( "(csay from %s) %s", calling_ply:IsValid() and calling_ply:Nick() or "Console", message ) )
  62.         end
  63. end
  64. local csay = ulx.command( CATEGORY_NAME, "ulx csay", ulx.csay, "@@@", true, true )
  65. csay:addParam{ type=ULib.cmds.StringArg, hint="message", ULib.cmds.takeRestOfLine }
  66. csay:defaultAccess( ULib.ACCESS_ADMIN )
  67. csay:help( "Send a message to everyone in the middle of their screen." )
  68.  
  69. ------------------------------ Thetime ------------------------------
  70. local waittime = 60
  71. local lasttimeusage = -waittime
  72. function ulx.thetime( calling_ply )
  73.         if lasttimeusage + waittime > CurTime() then
  74.                 ULib.tsayError( calling_ply, "I just told you what time it is! Please wait " .. waittime .. " seconds before using this command again", true )
  75.                 return
  76.         end
  77.  
  78.         lasttimeusage = CurTime()
  79.         ulx.fancyLog( "The time is now #s.", os.date( "%I:%M %p") )
  80. end
  81. local thetime = ulx.command( CATEGORY_NAME, "ulx thetime", ulx.thetime, "!thetime" )
  82. thetime:defaultAccess( ULib.ACCESS_ALL )
  83. thetime:help( "Shows you the server time." )
  84.  
  85. ------------------------------ Adverts ------------------------------
  86. ulx.adverts = ulx.adverts or {}
  87. local adverts = ulx.adverts -- For XGUI, too lazy to change all refs
  88.  
  89. local function doAdvert( group, id )
  90.  
  91.         if adverts[ group ][ id ] == nil then
  92.                 if adverts[ group ].removed_last then
  93.                         adverts[ group ].removed_last = nil
  94.                         id = 1
  95.                 else
  96.                         id = #adverts[ group ]
  97.                 end
  98.         end
  99.  
  100.         local info = adverts[ group ][ id ]
  101.  
  102.         local message = string.gsub( info.message, "%%curmap%%", game.GetMap() )
  103.         message = string.gsub( message, "%%host%%", GetConVarString( "hostname" ) )
  104.         message = string.gsub( message, "%%ulx_version%%", ulx.getVersion() )
  105.  
  106.         if not info.len then -- tsay
  107.                 local lines = ULib.explode( "\\n", message )
  108.  
  109.                 for i, line in ipairs( lines ) do
  110.                         local trimmed = line:Trim()
  111.                         if trimmed:len() > 0 then
  112.                                 ULib.tsayColor( _, true, info.color, trimmed ) -- Delaying runs one message every frame (to ensure correct order)
  113.                         end
  114.                 end
  115.         else
  116.                 ULib.csay( _, message, info.color, info.len )
  117.         end
  118.  
  119.         ULib.queueFunctionCall( function()
  120.                 local nextid = math.fmod( id, #adverts[ group ] ) + 1
  121.                 timer.Remove( "ULXAdvert" .. type( group ) .. group )
  122.                 timer.Create( "ULXAdvert" .. type( group ) .. group, adverts[ group ][ nextid ].rpt, 1, function() doAdvert( group, nextid ) end )
  123.         end )
  124. end
  125.  
  126. -- Whether or not it's a csay is determined by whether there's a value specified in "len"
  127. function ulx.addAdvert( message, rpt, group, color, len )
  128.         local t
  129.  
  130.         if group then
  131.                 t = adverts[ tostring( group ) ]
  132.                 if not t then
  133.                         t = {}
  134.                         adverts[ tostring( group ) ] = t
  135.                 end
  136.         else
  137.                 group = table.insert( adverts, {} )
  138.                 t = adverts[ group ]
  139.         end
  140.  
  141.         local id = table.insert( t, { message=message, rpt=rpt, color=color, len=len } )
  142.  
  143.         if not timer.Exists( "ULXAdvert" .. type( group ) .. group ) then
  144.                 timer.Create( "ULXAdvert" .. type( group ) .. group, rpt, 1, function() doAdvert( group, id ) end )
  145.         end
  146. end
  147.  
  148. ------------------------------ Gimp ------------------------------
  149. local gimpSays = {} -- Holds gimp says
  150. ulx.gimpSays = gimpSays -- For XGUI, too lazy to change all refs
  151. local ID_GIMP = 1
  152. local ID_MUTE = 2
  153.  
  154. function ulx.addGimpSay( say )
  155.         table.insert( gimpSays, say )
  156. end
  157.  
  158. function ulx.clearGimpSays()
  159.         table.Empty( gimpSays )
  160. end
  161.  
  162. function ulx.gimp( calling_ply, target_plys, should_ungimp )
  163.         for i=1, #target_plys do
  164.                 local v = target_plys[ i ]
  165.                 if should_ungimp then
  166.                         v.gimp = nil
  167.                 else
  168.                         v.gimp = ID_GIMP
  169.                 end
  170.                 v:SetNWBool("ulx_gimped", not should_ungimp)
  171.         end
  172.  
  173.         if not should_ungimp then
  174.                 ulx.fancyLogAdmin( calling_ply, "#A gimped #T", target_plys )
  175.         else
  176.                 ulx.fancyLogAdmin( calling_ply, "#A ungimped #T", target_plys )
  177.         end
  178. end
  179. local gimp = ulx.command( CATEGORY_NAME, "ulx gimp", ulx.gimp, "!gimp" )
  180. gimp:addParam{ type=ULib.cmds.PlayersArg }
  181. gimp:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  182. gimp:defaultAccess( ULib.ACCESS_ADMIN )
  183. gimp:help( "Gimps target(s) so they are unable to chat normally." )
  184. gimp:setOpposite( "ulx ungimp", {_, _, true}, "!ungimp" )
  185.  
  186. ------------------------------ Mute ------------------------------
  187. function ulx.mute( calling_ply, target_plys, should_unmute )
  188.         for i=1, #target_plys do
  189.                 local v = target_plys[ i ]
  190.                 if should_unmute then
  191.                         v.gimp = nil
  192.                 else
  193.                         v.gimp = ID_MUTE
  194.                 end
  195.                 v:SetNWBool("ulx_muted", not should_unmute)
  196.         end
  197.  
  198.         if not should_unmute then
  199.                 ulx.fancyLogAdmin( calling_ply, "#A muted #T", target_plys )
  200.         else
  201.                 ulx.fancyLogAdmin( calling_ply, "#A unmuted #T", target_plys )
  202.         end
  203. end
  204. local mute = ulx.command( CATEGORY_NAME, "ulx mute", ulx.mute, "!mute" )
  205. mute:addParam{ type=ULib.cmds.PlayersArg }
  206. mute:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  207. mute:defaultAccess( ULib.ACCESS_ADMIN )
  208. mute:help( "Mutes target(s) so they are unable to chat." )
  209. mute:setOpposite( "ulx unmute", {_, _, true}, "!unmute" )
  210.  
  211. if SERVER then
  212.         local function gimpCheck( ply, strText )
  213.                 if ply.gimp == ID_MUTE then return "" end
  214.                 if ply.gimp == ID_GIMP then
  215.                         if #gimpSays < 1 then return nil end
  216.                         return gimpSays[ math.random( #gimpSays ) ]
  217.                 end
  218.         end
  219.         hook.Add( "PlayerSay", "ULXGimpCheck", gimpCheck, HOOK_LOW )
  220. end
  221.  
  222. ------------------------------ Gag ------------------------------
  223. function ulx.gag( calling_ply, target_plys, should_ungag )
  224.         local players = player.GetAll()
  225.         for i=1, #target_plys do
  226.                 local v = target_plys[ i ]
  227.                 v.ulx_gagged = not should_ungag
  228.                 v:SetNWBool("ulx_gagged", v.ulx_gagged)
  229.         end
  230.  
  231.         if not should_ungag then
  232.                 ulx.fancyLogAdmin( calling_ply, "#A gagged #T", target_plys )
  233.         else
  234.                 ulx.fancyLogAdmin( calling_ply, "#A ungagged #T", target_plys )
  235.         end
  236. end
  237. local gag = ulx.command( CATEGORY_NAME, "ulx gag", ulx.gag, "!gag" )
  238. gag:addParam{ type=ULib.cmds.PlayersArg }
  239. gag:addParam{ type=ULib.cmds.BoolArg, invisible=true }
  240. gag:defaultAccess( ULib.ACCESS_ADMIN )
  241. gag:help( "Gag target(s), disables microphone." )
  242. gag:setOpposite( "ulx ungag", {_, _, true}, "!ungag" )
  243.  
  244. local function gagHook( listener, talker )
  245.         if talker.ulx_gagged then
  246.                 return false
  247.         end
  248. end
  249. hook.Add( "PlayerCanHearPlayersVoice", "ULXGag", gagHook )
  250.  
  251. -- Anti-spam stuff
  252. if SERVER then
  253.         local chattime_cvar = ulx.convar( "chattime", "1.5", "<time> - Players can only chat every x seconds (anti-spam). 0 to disable.", ULib.ACCESS_ADMIN )
  254.         local function playerSay( ply )
  255.                 if not ply.lastChatTime then ply.lastChatTime = 0 end
  256.        
  257.                 local chattime = chattime_cvar:GetFloat()
  258.                 if chattime <= 0 then return end
  259.        
  260.                 if ply.lastChatTime + chattime > CurTime() then
  261.                         return ""
  262.                 else
  263.                         ply.lastChatTime = CurTime()
  264.                         return
  265.                 end
  266.         end
  267.         hook.Add( "PlayerSay", "ulxPlayerSay", playerSay, HOOK_LOW )
  268.  
  269. local function showWelcome( ply )
  270.         local message = GetConVarString( "ulx_welcomemessage" )
  271.         if not message or message == "" then return end
  272.  
  273.         message = string.gsub( message, "%%curmap%%", game.GetMap() )
  274.         message = string.gsub( message, "%%host%%", GetConVarString( "hostname" ) )
  275.         message = string.gsub( message, "%%ulx_version%%", ulx.getVersion() )
  276.  
  277.         ply:ChatPrint( message ) -- We're not using tsay because ULib might not be loaded yet. (client side)
  278. end
  279. hook.Add( "PlayerInitialSpawn", "ULXWelcome", showWelcome )
  280. if SERVER then ulx.convar( "welcomemessage", "", "<msg> - This is shown to players on join.", ULib.ACCESS_ADMIN ) end
  281.  


I have went to the line and cant see a problem any help? :)

JamminR EDIT - Added Code tags (WHOA DUDE...ADD a FILE or CODE TAGS at the least]
« Last Edit: October 19, 2015, 07:53:57 pm by JamminR »

Offline roastchicken

  • Respected Community Member
  • Sr. Member
  • *****
  • Posts: 476
  • Karma: 84
  • I write code
Re: Unknow Error In Console and cant use ULX adverts
« Reply #1 on: October 19, 2015, 03:56:16 pm »
If you went to line 252 like the error said, you would see that it's an if statement that never gets closed. You need an end statement to close it. I assume you would want to put one on line 268.
Give a man some code and you help him for a day; teach a man to code and you help him for a lifetime.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: Unknow Error In Console and cant use ULX adverts
« Reply #2 on: October 19, 2015, 07:57:09 pm »
Indeed JJ Ellis, what roastchicken says.
Gmod errors are usually pretty clear to point out where a syntax error started.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline JJ_Ellis

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Unknow Error In Console and cant use ULX adverts
« Reply #3 on: October 20, 2015, 08:32:35 am »
so I would just type end on line 268?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 718
  • Karma: 116
  • :)
    • My Homepage
Re: Unknow Error In Console and cant use ULX adverts
« Reply #4 on: October 20, 2015, 11:09:25 am »
so I would just type end on line 268?
Looks like it--check your indentation, it gives you a hint.
bw81@ulysses-forums ~ % whoami
Homepage

Offline JJ_Ellis

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
Re: Unknow Error In Console and cant use ULX adverts
« Reply #5 on: October 20, 2015, 11:36:22 am »
Thank you very much! :)

  • Print