Ulysses
General => Developers Corner => Topic started by: bender180 on February 21, 2013, 09:27:18 AM
-
I made a command that allows and admin to move a player that is afk to the spectator team in trouble in terrorist town but its not always working, i will use the command on one player and the player will switch to spectator but then ill use it on a different player and it does nothing but echo in chat. Does anyone know why the command is acting this way?
Heres the code:
------------------------------ Spectator ------------------------------
function ulx.afk( calling_ply, target_plys )
for _,v in pairs(target_plys) do
timer.Simple(0.3, function()
v:ConCommand("ttt_spectator_mode 1")
v:ConCommand("ttt_cl_idlepopup")
end)
end
ulx.fancyLogAdmin( calling_ply, "#A has forced #T into spectator mode", target_plys )
end
local fspec = ulx.command( "TTT", "ulx afk", ulx.afk, "!afk" )
fspec:addParam{ type=ULib.cmds.PlayersArg }
fspec:defaultAccess( ULib.ACCESS_SUPERADMIN )
fspec:help( "Forces the target(s) to spectator mode." )
-
WHY DO U HAS TIMER ? IT IS NOT CLEVER xD/needed
-
i honestly took the code for moving someone to afk out of the ttt gamemode code and it had the timer so i kept it all I did was switch it from a client side to a server side style, ill try it with out the timer.
-
i think the logic flow for that command is what's broken remove the timer just do it... because re seting v after the timer is started could be causeing silent errors also spectator commands are not really needed for ttt just lower the afk spec setting (heh im guilty of this)
Ps: that is if your actualy trying to send them to spec for afk.
-
removing the timer worked and yes thats what the goal of the command is, to move them to the spectator team for afk
-
the reason why this happend (for future reference) v is a object that when used in a timer simple >>> if the value v is changed before the timer goes off and does the function the function will do un expected things like send a person to spec 2 times ( this wil fail silently by not specing the first person if not more) thats why when you spec'ed people it looked broken because the timer gave the code time to change the value of v while it was still counting down thus causing people not to be targeted
TLDR timer + for _,v in pairs = things go wrong if v is used in the timer
that reminds me is there a wait function in gmod ? or do you have to use timers
-
You could always fully automate it. Take this script and do a little lua surgery on it using your code you have above.
http://forums.ulyssesmod.net/index.php/topic,5963.0.html
-
Hi, I've been trying to make an opposite to this command that allows users to easily take off "ttt_spectator_mode 1", this is what I've got so far:
function ulx.unafk( calling_ply, target_plys )
if target_plys !={} and not ULib.ucl.query( calling_ply, "ulx afk" ) then -- If there are targets but the player has no permission, the command will not be run
ULib.tsayError( calling_ply, "You can only use this command on yourself!", true ) -- Player is warned
return
elseif target_plys == {} and not ULib.ucl.query( calling_ply, "ulx afk" ) then -- Otherwise, the command is run locally
calling_ply:ConCommand("ttt_spectator_mode 0")
else
for _,v in pairs(target_plys) do v:ConCommand("ttt_spectator_mode 0") end
end
ulx.fancyLogAdmin( calling_ply, "#A forced #T into player mode", target_plys )
end
local unafk = ulx.command( "TTT", "ulx unafk", ulx.unafk, "!unafk" )
unafk:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
unafk:defaultAccess( ULib.ACCESS_ALL )
unafk:help( "Disables spectate-only mode (for the n00bs)." )
I'm not sure exactly how to check if no target players have been given, but I want all users to be able to use it, but only admins with the permissions to use bender's "ulx afk" command to be able to have targets.
Will this work as I intend it to? I need to know before I give to be used on my community's server.
Any suggestions?
EDIT:
Forgot to mention that I made a permission for "ulx afk", so a permission lookup should work (in theory).
-
looks water tight but you should not ulx log the players useing the command on them self or they could and CAN flood the logs to cause lag
-
Thanks, I simplified them so both commands will be like this:
--------------------------------------------------
function ulx.unafk( calling_ply, target_plys )
if target_plys !={} and not ULib.ucl.query( calling_ply, "ulx afk" ) then -- If there are targets but the player has no permission, the command will not be run
ULib.tsayError( calling_ply, "You can only use this command on yourself!", true ) -- Player is warned
return
else
for _,v in pairs(target_plys) do v:ConCommand("ttt_spectator_mode 0") end
ulx.fancyLogAdmin( calling_ply, "#A forced #T into player mode", target_plys )
end
end
local unafk = ulx.command( "TTT", "ulx unafk", ulx.unafk, "!unafk" )
unafk:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
unafk:defaultAccess( ULib.ACCESS_ALL )
unafk:help( "Disables spectate-only mode (for the n00bs)." )
----------------------------------------------------------------
function ulx.afk( calling_ply, target_plys )
if SERVER then ULib.ucl.registerAccess( "ulx afk" , ULib.ACCESS_OPERATOR, "Allows group to force spectator", "TTT" ) end
for _,v in pairs(target_plys) do v:ConCommand("ttt_spectator_mode 1") v:ConCommand("ttt_cl_idlepopup") end
ulx.fancyLogAdmin( calling_ply, "#A forced #T into spectator mode", target_plys )
end
local fspec = ulx.command( "TTT", "ulx afk", ulx.afk, "!afk" )
fspec:addParam{ type=ULib.cmds.PlayersArg, ULib.cmds.optional }
fspec:defaultAccess( ULib.ACCESS_SUPERADMIN )
fspec:help( "Forces the target(s) to spectator mode." )
I'll leave this for anyone who wants it. Hope it works well.
-
Would you mind if i included this in my addon (http://forums.ulyssesmod.net/index.php/topic,6194.0.html)? ill credit you of course :)