TTT Voice Battery - Drain amount for specific groups

Hello.

I’ve been trying to get this done and solved for a very long time now, I have not had any success.
Basically I am trying to have custom ULX groups have specific amount of battery or drain with the default TTT voice battery. I’ve gotten certain solutions from people that claim it “should” work but wasn’t actually tested by them. And they ended up never working.

I can reply here with codes to any default files if needed.

The easiest way would be to edit the GetDrainRate() function in cl_voice at line 619. Where is says


if ply:IsAdmin() or ply:IsDetective() then
      return GetGlobalFloat("ttt_voice_drain_admin", 0)
   else
      return GetGlobalFloat("ttt_voice_drain_normal", 0)
   end

change it to check if a player is in a specific group and then return the value you want.

A more complex but easier way to modify it would to have a table of ranks as a key and the drain rate as the value, check the table for the players rank and then return the appropriate value.
here is an example:


SpecialDrain = {
	["admin"] = 0.1
	["moderator"] = 0.2
	["member"] = 0.4
	["guest"] = 0.5
}
DrainValue = SpecialDrain[ply:GetUserGroup()] or 0.1
//return 0.1 if the players rank is not in the table

Alright, so say I wanted to use the “more complex but easier way”, how would the code around line 619 look?

I refuse to spoon feed people and normally wouldn’t go this far; however, here is what you need. Try to figure it out and if you get any errors let me know, I will help you finish this.

http://puu.sh/jyhev/62df3f2bd4.png

I understand you as far as the spoonfeeding goes but thank you very much. I will try this as soon as I can and sorry but I’m not as great at lua as i should be.

Alright, i tried it and my console was flooded by this error

[ERROR] gamemodes/terrortown/gamemode/cl_init.lua:326: attempt to call field ‘Tick’ (a nil value)

  1. unknown - gamemodes/terrortown/gamemode/cl_init.lua:326

Tracking it down and it points to the VOICE.Tick in this function


function GM:Tick()
   local client = LocalPlayer()
   if IsValid(client) then
      if client:Alive() and client:Team() != TEAM_SPEC then
         WSWITCH:Think()
         RADIO:StoreTarget()
      end

      VOICE.Tick()
   end
end

You did something wrong in GetDrainRate which breaks the tick function. Post code here?

This is my cl_voice when I try to add custom groups.


SpecialDrain = {
	["superadmin"] = 0,
	["admin vip+"] = 0.06,
	["admin vip"] = 0.07,
	["mod vip+"] = 0.05,
	["mod vip"] = 0.06,
	["VIP+"] = 0.05,
	["VIP"] = 0.06
}
DrainValue = SpecialDrain[ply:GetUserGroup()] or 0.1
--return 0.1 if the players rank is not in the table

local function GetDrainRate()
   if not GetGlobalBool("ttt_voice_drain", false) then return 0 end
   -- return a rate of 0 if voice drain is disabled

   if GetRoundState() ~= ROUND_ACTIVE then return 0 end
   -- return a rate of 0 if we are not in a round
   local ply = LocalPlayer()
   if (not IsValid(ply)) or ply:IsSpec() then return 0 end
   --return a rate of 0 if the player is not valid or the player is spectating

   --if ply:IsAdmin() or ply:IsDetective() then
   --   return GetGlobalFloat("ttt_voice_drain_admin", 0)
   --else
   --   return GetGlobalFloat("ttt_voice_drain_normal", 0)
   --end
   --let disable the old version of this code (this will remove admin voice drain disable via console command)
   return the_drain_value_we_want
end

This is the default cl_voice without errors


local function GetDrainRate()
   if not GetGlobalBool("ttt_voice_drain", false) then return 0 end

   if GetRoundState() != ROUND_ACTIVE then return 0 end
   local ply = LocalPlayer()
   if (not IsValid(ply)) or ply:IsSpec() then return 0 end

   if ply:IsAdmin() or ply:IsDetective() then
      return GetGlobalFloat("ttt_voice_drain_admin", 0)
   else
      return GetGlobalFloat("ttt_voice_drain_normal", 0)
   end
end


the_drain_value_we_want 

Ehm this var is not even defined as far as I can see. Or am I just blind atm?

You’re supposed to replace that (in the code) with the drain value that you want…

Yeah but I think that he does not change this var.
This could cause the error, right?

Yeah, he just needs to change


return the_drain_value_we_want

to


return DrainValue

Exactly this is what I wanted to say, thanks! :slight_smile:

I feel very ignorant for asking this but, would it literally be “DrainValue” or an amount?

An amount.
DrainValue is defined based on the player’s user group

That’s what i was thinking, but I don’t know where that specific DrainValue is pointing to. Therefore i’m not sure what to set it to.



SpecialDrain = {
	["superadmin"] = 0,
	["admin vip+"] = 0.06,
	["admin vip"] = 0.07,
	["mod vip+"] = 0.05,
	["mod vip"] = 0.06,
	["VIP+"] = 0.05,
	["VIP"] = 0.06
}
--return 0.1 if the players rank is not in the table

local function GetDrainRate()
   if not GetGlobalBool("ttt_voice_drain", false) then return 0 end
   -- return a rate of 0 if voice drain is disabled

   if GetRoundState() ~= ROUND_ACTIVE then return 0 end
   -- return a rate of 0 if we are not in a round
   local ply = LocalPlayer()
   if (not IsValid(ply)) or ply:IsSpec() then return 0 end
   --return a rate of 0 if the player is not valid or the player is spectating

   --if ply:IsAdmin() or ply:IsDetective() then
   --   return GetGlobalFloat("ttt_voice_drain_admin", 0)
   --else
   --   return GetGlobalFloat("ttt_voice_drain_normal", 0)
   --end
   --let disable the old version of this code (this will remove admin voice drain disable via console command)
   return SpecialDrain[ply:GetUserGroup()] or 0.1
end


as much as i hate spoon feeding, this is what you want. if you do it like you had it the person’s usergroup may not be defined when the lua file loads.

If your goal is to learn how to do things like this on your own, your best bet is to continue to ask questions. I can explain it in a more detailed way. If you just want code/add-ons your going to have a tough time in this forum.

I’m constantly trying to learn, thanks for the advice :slight_smile:

[editline]13th August 2015[/editline]

Thank you so much. I’ve spent so long trying to get a working code and you made it happen. I’m sorry you had to spoonfeed and as you can tell, I need to learn LUA. As I am not very good with it.

But once again thank you.