Author Topic: Custom command not always working?  (Read 4846 times)

0 Members and 1 Guest are viewing this topic.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Custom command not always working?
« 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:
Code: [Select]
------------------------------ 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." )
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command not always working?
« Reply #1 on: February 21, 2013, 09:37:17 AM »
WHY DO U HAS TIMER ? IT IS NOT CLEVER xD/needed
« Last Edit: February 21, 2013, 09:47:30 AM by nathan736 »
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Custom command not always working?
« Reply #2 on: February 21, 2013, 09:49:43 AM »
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.
« Last Edit: February 21, 2013, 09:54:50 AM by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command not always working?
« Reply #3 on: February 25, 2013, 07:17:40 AM »
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.
« Last Edit: February 25, 2013, 08:26:23 AM by nathan736 »
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Custom command not always working?
« Reply #4 on: February 25, 2013, 08:32:25 AM »
removing the timer worked and yes thats what the goal of the command is, to move them to the spectator team for afk
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command not always working?
« Reply #5 on: February 26, 2013, 08:25:11 AM »
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
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: Custom command not always working?
« Reply #6 on: February 27, 2013, 10:55:31 PM »
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

Offline Boxama

  • Newbie
  • *
  • Posts: 12
  • Karma: 1
Re: Custom command not always working?
« Reply #7 on: April 10, 2013, 07:50:23 AM »
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: [Select]
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).
« Last Edit: April 10, 2013, 08:01:05 AM by Boxama »

Offline nathan736

  • Full Member
  • ***
  • Posts: 143
  • Karma: 4
Re: Custom command not always working?
« Reply #8 on: April 10, 2013, 08:31:36 AM »
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
a person asked me how to code lua and i said this " its like building a rocket up side down then  realizing you did it all wrong."

Offline Boxama

  • Newbie
  • *
  • Posts: 12
  • Karma: 1
Re: Custom command not always working?
« Reply #9 on: April 11, 2013, 04:29:19 AM »
Thanks, I simplified them so both commands will be like this:
Code: [Select]
--------------------------------------------------
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.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: Custom command not always working?
« Reply #10 on: April 11, 2013, 07:38:23 AM »
Would you mind if i included this in my addon? ill credit you of course :)
« Last Edit: April 11, 2013, 09:13:53 AM by bender180 »
Made community pool and community bowling and for the life of me couldn't tell you why they are popular.
Also made the ttt ulx commands.