• ULX Check AFK command help
    3 replies, posted
I'm trying to make a script for a TTT server that, on execution on a target, will ask them to press wasd to not be put in spectator. The code I have so far is: [CODE]local CATEGORY_NAME = "Utility" local function forceSpec( calling_ply, target_ply ) for k,v in pairs(target_ply) do v:ConCommand("ttt_spectator_mode 1") v:ConCommand("ttt_cl_idlepopup") ulx.fancyLogAdmin("#T failed to respond to the AFK Check.", target_ply ) end end function ulx.cafk( calling_ply, target_ply) ULib.tsay(target_ply, "If you are not AFK, please press W, A, S, or D to cancel automatic spectating.") local passedResponse for k,v in pairs(target_ply) do if v:input.IsKeyDown(KEY_W) then passedResponse = true elseif v:input.IsKeyDown(KEY_A) then passedResponse = true elseif v:input.IsKeyDown(KEY_D) then passedResponse = true elseif v:input.IsKeyDown(KEY_S) then passedResponse = true else passedResponse = false end if passedResponse = false then ulx.fancyLogAdmin( "#T failed to respond to the AFK check." ) forceSpec() else ulx.fancyLogAdmin( "#T has passed the AFK check." ) end end end local cafk = ulx.command( CATEGORY_NAME, "ulx cafk", ulx.cafk, "!cafk" ) cafk:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional } cafk:defaultAccess( ULib.ACCESS_OPERATOR ) cafk:help( "Checks if a player is AFK." ) [/CODE] I put all of those elseif's in there because I thought that might have been the reason (I had them in or's before) but it turns out it wasn't. The error I'm getting is: [CODE][ERROR] addons/customcommands/lua/ulx/modules/sh/sh_cc_cafk.lua:18: function arguments expected near '.' 1. unknown - addons/customcommands/lua/ulx/modules/sh/sh_cc_cafk.lua:0[/CODE] I've tried adding "...(KEY_W) = true" but that doesn't work either. What am I doing wrong here? I'm fairly new to LUA but I have a decent understanding. If you're confused at all, just let me know and I'll try to clarify.
if input.IsKeyDown(KEY_W) then not if v:input.IsKeyDown(KEY_W) then if passedResponse = false then ... = to set a value == to check a value, so, if passedResponse == false then do ur thing end you can even do: if not passedResponse then do ur thing end
[QUOTE=Invule;50295985]if input.IsKeyDown(KEY_W) then not if v:input.IsKeyDown(KEY_W) then if passedResponse = false then ... = to set a value == to check a value, so, if passedResponse == false then do ur thing end you can even do: if not passedResponse then do ur thing end[/QUOTE] Thanks, I'll go try that out. And I remember learning the difference of = and == but it seems I forgot. I'll let you know if it works :) EDIT: This seemed to have fixed my error that I was having before, but now I'm having a different error. Firstly, just after loading in, I get the error: [CODE][ERROR] lua/includes/extensions/table.lua:76: attempt to index local 'dest' (a nil value) 1. Merge - lua/includes/extensions/table.lua:76 2. getData - addons/ulx/lua/ulx/xgui/server/sv_groups.lua:13 3. sendDataTable - addons/ulx/lua/ulx/modules/xgui_server.lua:178 4. unknown - addons/ulx/lua/ulx/modules/xgui_server.lua:98 5. unknown - addons/ulx/lua/ulx/modules/xgui_server.lua:65 6. unknown - lua/includes/modules/concommand.lua:54 [/CODE] and secondly, when I try the cafk command on myself, I get the error: [CODE]addons/ulib/lua/ulib/shared/commands.lua:943: bad argument #1 to ULib.tsay (nil,Player,Entity expected, got table)[/CODE] These are both files I did nothing to alter, does anyone know how I can fix this? The code on my program (after the changes Invule helped me with) is: [CODE]local CATEGORY_NAME = "Utility" local function forceSpec( calling_ply, target_ply ) for k,v in pairs(target_ply) do v:ConCommand("ttt_spectator_mode 1") v:ConCommand("ttt_cl_idlepopup") ulx.fancyLogAdmin("#T failed to respond to the AFK Check.", target_ply ) end end function ulx.cafk( calling_ply, target_ply) ULib.tsay(target_ply, "If you are not AFK, please press W, A, S, or D to cancel automatic spectating.") local passedResponse for k,v in pairs(target_ply) do if input.IsKeyDown(KEY_W) then passedResponse = true elseif input.IsKeyDown(KEY_A) then passedResponse = true elseif input.IsKeyDown(KEY_D) then passedResponse = true elseif input.IsKeyDown(KEY_S) then passedResponse = true else passedResponse = false end if passedResponse == false then ulx.fancyLogAdmin( "#T failed to respond to the AFK check." ) forceSpec() else ulx.fancyLogAdmin( "#T has passed the AFK check." ) end end end local cafk = ulx.command( CATEGORY_NAME, "ulx cafk", ulx.cafk, "!cafk" ) cafk:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional } cafk:defaultAccess( ULib.ACCESS_OPERATOR ) cafk:help( "Checks if a player is AFK." ) [/CODE]
You need to pass your target_ply's in the forceSpec function like so, forceSpec( calling_ply, v )
Sorry, you need to Log In to post a reply to this thread.