• Print

Author Topic: "Rock the guards" command for Jailbreak?  (Read 6776 times)

0 Members and 1 Guest are viewing this topic.

Offline rocco1233

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
"Rock the guards" command for Jailbreak?
« on: October 18, 2014, 03:42:22 pm »
Ok, so basically what this command does, is it calls a vote, and if the results are greater than 60% for yes, it forces the guards to become prisoners next round. Here is what i have so far:

Code: Lua
  1. local CATEGORY_NAME = "Jailbreak"
  2. local target_plyss = team.GetPlayers(TEAM_GUARD)
  3.  
  4. local function force_prisoner( calling_ply, target_plys )
  5.         local affected_plys = {}
  6.        
  7.         for i=1, #target_plys do
  8.                 for n=#GAMEMODE.GuardQueue,1,-1 do
  9.                         if GAMEMODE.GuardQueue[n]==target_plys[i] then table.remove( GAMEMODE.GuardQueue, n ) end
  10.                        
  11. //                      target_plys[i]:KillSilent()
  12. //                      target_plys[i]:SetTeam( TEAM_PRISONER )
  13.                 end
  14.         end
  15.        
  16.         ulx.fancyLogAdmin( calling_ply, "#A removed #T from the Guard queue", affected_plys )
  17.        
  18.         GAMEMODE:UpdateGuardQueue()
  19. end
  20.  
  21. local fprisoner = ulx.command( CATEGORY_NAME, "ulx prisoner", force_prisoner, "!prisoner" )
  22. fprisoner:addParam{ type=ULib.cmds.PlayersArg }
  23. fprisoner:defaultAccess( ULib.ACCESS_ADMIN )
  24. fprisoner:help( "Forces the target(s) to join the Prisoner team." )
  25.  
Code: Lua
  1. local function votePrisonerDonee2( t, target_plyss, ply, reason )
  2.      local shouldPrison = false
  3.  
  4.      if t.results[ 1 ] and t.results[ 1 ] > 0 then
  5.           ulx.logUserAct( ply, target_plyss, "#A approved the Rocking of the Guards (" .. (reason or "") .. ")" )
  6.           shouldPrison = true
  7.      else
  8.           ulx.logUserAct( ply, target_plyss, "#A denied the Rocking of the Guards" )
  9.      end
  10.  
  11.      if shouldPrison then
  12.           ULib.tsay( _, "Vote to Rock the Guards was successful." )
  13.  
  14.           force_prisoner( ply, target_plyss )
  15.  
  16.      end
  17. end
  18.  
  19. local function votePrisonerDonee( t, target_plyss, ply, reason )
  20.      local results = t.results
  21.      local winner
  22.      local winnernum = 0
  23.      for id, numvotes in pairs( results ) do
  24.           if numvotes > winnernum then
  25.                winner = id
  26.                winnernum = numvotes
  27.          end
  28.      end
  29.  
  30.      local ratioNeeded = GetConVarNumber( "ulx_votenprisonerSuccessratio" )
  31.      local minVotes = GetConVarNumber( "ulx_voteprisonerMinvotes" )
  32.      local str
  33.      if winner ~= 1 or winnernum < minVotes or winnernum / t.voters < ratioNeeded then
  34.           str = "Vote results: Guard will not be rocked. (" .. (results[ 1 ] or "0") .. "/" .. t.voters .. ")"
  35.      else
  36.           str = "Vote results: Guard will now be rocked, Pending Approval. (" .. winnernum .. "/" .. t.voters .. ")"
  37.           ulx.doVote( "Accept result and Rock the Guards?", { "Yes", "No" }, votePrisonerDonee2, 30000, { ply }, true, target_plyss, ply, reason )
  38.      end
  39.  
  40.      ULib.tsay( _, str )
  41.      ulx.logString( str )
  42.      if game.IsDedicated() then Msg( str .. "\n" ) end
  43. end
  44.  
  45. function ulx.votertgall( calling_ply, target_plyss, reason )
  46.      if voteInProgress then
  47.           ULib.tsayError( calling_ply, "There is already a vote in progress. Please wait for the current one to end.", true )
  48.           return
  49.      end
  50.  
  51. local msg = "Rock the Guards?"
  52. if reason and reason ~= "" then
  53.      msg = msg .. " (" .. reason .. ")"
  54. end
  55.  
  56. ulx.doVote( msg, { "Yes", "No" }, votePrisonerDonee, _, _, _, target_ply, calling_ply, reason )
  57. ulx.fancyLogAdmin( calling_ply, "#A started a vote to Rock the Guards")
  58. end
  59. local votertgall = ulx.command( CATEGORY_NAME, "ulx rocktheguardall", ulx.votertgall, "!rtgall" )
  60. votertgall:addParam{ type=ULib.cmds.PlayerArg }
  61. votertgall:addParam{ type=ULib.cmds.StringArg, hint="reason", ULib.cmds.optional, ULib.cmds.takeRestOfLine}
  62. votertgall:defaultAccess( ULib.ACCESS_ADMIN )
  63. votertgall:help( "Starts a public RTG vote for all guards." )
  64. if SERVER then ulx.convar( "voteprisonerSuccessratio", "0.6", _, ULib.ACCESS_ADMIN ) end
  65. if SERVER then ulx.convar( "voteprisonerMinvotes", "2", _, ULib.ACCESS_ADMIN ) end
  66.  

so basically what i am trying to do is make the vote, if successful, call the force_prisoner command, but i want it to target all guards. I tried to do so by defining a local variable target_plyss as what i thought would store all the names of the guards in it. It still does not work however. I don't want to have to call !rtgall <target>, as it should know that it just applies to everyone. I want to only have to do !rtgall. Thats it. Please help? and feel free to ask any questions if needed
« Last Edit: October 18, 2014, 09:41:40 pm by rocco1233 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Rock the guards" command for Jailbreak?
« Reply #1 on: October 18, 2014, 05:27:50 pm »
Ok, I've not fully studied your code, but, just as a quick overview, you're setting up rtgall for a SINGLE player passed.
To use a table of players (including "*" if wanted), you'd have to use
Code: [Select]
votertg:addParam{ type=ULib.cmds.PlayersArg }at line 60 of your rtgall code. It tells ULib "hey, accept a table of players"

Whatever the design decisions you make, I'd recommend a for loop, then perhaps pass the players to whatever code you need them.
QUASI-CODE (don't just paste this into your code and expect it to work)
Code: [Select]
local my_guard_table = { }
for k, v in pairs ( player.Getall() ) do
   if v:GetTeam() == <whatever_team_name_Guards_are_in...TEAM_GUARD?> then
     my_guard_table = { v , my_guard_table }
  end
end
--then here, call whatever function you want, passing my_guard_table that contains all guards, along with any other variables you need (calling ply, etc)

There's more sanity checks you can throw in to make sure the player didn't leave during the check, but, that's the general idea of it.
You'd then have a table of guards to do with what you need.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline rocco1233

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: "Rock the guards" command for Jailbreak?
« Reply #2 on: October 18, 2014, 05:39:34 pm »
I'm sort of confused about what you are saying to do. Line 60 of my code is exactly what you posted, are you telling me to change it or just pointing out what it does? and 2, where would i put that for loop ? i understand passing that table as a parameter, but that is what i tried to do at the top of the first segment. And the problem is, in game i don't know what i would call, because i have to specify a person/persons, when i just want to type !rtgall, and have it automatically know to target all guards. Yes the variable for the guard team is TEAM_GUARD.
« Last Edit: October 18, 2014, 05:43:01 pm by rocco1233 »

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Rock the guards" command for Jailbreak?
« Reply #3 on: October 18, 2014, 09:41:19 pm »
I'm recommending you not use line 60 at all, it sets up a parameter for the function your calling from it. (and in most cases, is a target to activate the function on.)
Line 60 of your code is not the same as what I posted.
In YOUR line 60, your using type=ULib.cmds.PlayerArg , a single player target option.
In my example, I'm using type=ULib.cmds.PlayersArg , a multiple target option.

You're rtgall command doesn't need to pass a target (2nd parameter) to the function...only the "reason" or whatever (stringarg).

The for loop would be used if vote was successful, and passed to any function that needs a table of guards to convert.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline rocco1233

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: "Rock the guards" command for Jailbreak?
« Reply #4 on: October 18, 2014, 09:44:01 pm »
OH OK, so then would i still need the parameter "Target" in votePrisonerDonee2 and votePrisonerDonee? Or is that supposed to be the table of players? Forgive me for my absence of knowledge but i just sort of used a votegag method i found and i kinda filled in the spaces.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Rock the guards" command for Jailbreak?
« Reply #5 on: October 18, 2014, 10:00:37 pm »
Heck, I just realized you may not even need that loop... Gmod has a new team.GetPlayers command you're using that I've never seen before.
(It's been too long since I really looked into latest Gmod lua)
It seems to expect a number parameter though..not sure TEAM_GUARD returns a number. Likely does.
I also wouldn't call it outside the function. It would have old data (=nothing, when server starts, which is when it's run)

As for your question, I don't know.
I unfortunately don't have the time to refresh myself on what those two functions do in our code, nor the time to review your code.
There's no need to go adding variables to functions though. If those 2 commands only had 3 parameters in the original functions you copied, adding one more without knowing what you're doing won't magically make it do what you want.
Yes, in our original, we needed a target to perforum a vote function on. In yours, you don't need a target called from the ULX command, you only need it later if 'vote' = 'passed'.

I'd focus on what happens when the vote passes...that's where the magic takes place.
« Last Edit: October 18, 2014, 10:02:37 pm by JamminR »
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline rocco1233

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: "Rock the guards" command for Jailbreak?
« Reply #6 on: October 19, 2014, 02:13:26 am »
I actually just removed line 60 and did what you said, and it worked! Thanks for your help. Locking topic.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: "Rock the guards" command for Jailbreak?
« Reply #7 on: October 19, 2014, 06:34:19 am »
Glad you got it working.
Update your original post with the code you're using, if you haven't already.
Might be helpful for someone else in the future.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

  • Print