General > Developers Corner
Custom command not always working?
nathan736:
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
MrPresident:
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
Boxama:
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:
--- Code: ---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)." )
--- End code ---
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).
nathan736:
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
Boxama:
Thanks, I simplified them so both commands will be like this:
--- Code: -----------------------------------------------------
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." )
--- End code ---
I'll leave this for anyone who wants it. Hope it works well.
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version