Author Topic: TTT lua help *Urgent*  (Read 1857 times)

0 Members and 1 Guest are viewing this topic.

Offline Rain

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
TTT lua help *Urgent*
« on: June 20, 2014, 08:19:25 PM »
Ok on my TTT server I'm trying to use slaynr.. I can use it but when I slay the person it says their alive, but they can fly around and talk and chat. this is a problem because they can tell the alive players who the traitor is. any idea how to fix it? the code for all of the ttt_admin.lua is below. This is an addon from bender and skillz

Code: [Select]
local CATEGORY_NAME  = "TTT Admin"
local gamemode_error = "The current gamemode is not trouble in terrorest town"
 
 
 
--[Ulx Completes]------------------------------------------------------------------------------
ulx.target_role = {}
function updateRoles()
        table.Empty( ulx.target_role )
           
    table.insert(ulx.target_role,"traitor")
    table.insert(ulx.target_role,"detective")
    table.insert(ulx.target_role,"innocent")
end
hook.Add( ULib.HOOK_UCLCHANGED, "ULXRoleNamesUpdate", updateRoles )
updateRoles()
--[End]----------------------------------------------------------------------------------------
 
 
 
--[Global Helper Functions][Used by more than one command.]------------------------------------
--[[send_messages][Sends messages to player(s)]
@param  {[PlayerObject]} v       [The player(s) to send the message to.]
@param  {[String]}       message [The message that will be sent.]
--]]
function send_messages(v, message)
        if type(v) == "Players" then
                v:ChatPrint(message)
        elseif type(v) == "table" then
                for i=1, #v do
                        v[i]:ChatPrint(message)
                end
        end
end
 
--[[corpse_find][Finds the corpse of a given player.]
@param  {[PlayerObject]} v       [The player that to find the corpse for.]
--]]
function corpse_find(v)
        for _, ent in pairs( ents.FindByClass( "prop_ragdoll" )) do
                if ent.uqid == v:UniqueID() and IsValid(ent) then
                        return ent or false
                end
        end
end
 
--[[corpse_remove][removes the corpse given.]
@param  {[Ragdoll]} corpse [The corpse to be removed.]
--]]
function corpse_remove(corpse)
        CORPSE.SetFound(corpse, false)
        if string.find(corpse:GetModel(), "zm_", 6, true) then
                corpse:Remove()
        elseif corpse.player_ragdoll then
                corpse:Remove()
        end
end
 
--[[corpse_identify][identifies the given corpse.]
@param  {[Ragdoll]} corpse [The corpse to be identified.]
--]]
function corpse_identify(corpse)
        if corpse then
                local ply = player.GetByUniqueID(corpse.uqid)
                ply:SetNWBool("body_found", true)
                CORPSE.SetFound(corpse, true)
        end
end
--[End]----------------------------------------------------------------------------------------
 
 
 
 
--[Force role]---------------------------------------------------------------------------------
--[[ulx.force][Forces <target(s)> to become a specified role.]
@param  {[PlayerObject]} calling_ply   [The player who used the command.]
@param  {[PlayerObject]} target_plys   [The player(s) who will have the effects of the command applied to them.]
@param  {[Number]}       target_role   [The role that target player(s) will have there role set to.]
@param  {[Boolean]}      should_silent [Hidden, determines weather the output will be silent or not.]
--]]
function ulx.slaynr( calling_ply, target_ply, num_slay, should_slaynr )
        if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
                local affected_plys = {}
                local slays_left = tonumber(target_ply:GetPData("slaynr_slays")) or 0
                local current_slay
                local new_slay
           
       
                if ulx.getExclusive( target_ply, calling_ply ) then
                        ULib.tsayError( calling_ply, ulx.getExclusive( target_ply, calling_ply ), true )
                elseif num_slay < 0 then
                        ULib.tsayError( calling_ply, "Invalid integer:\"" .. num_slay .. "\" specified.", true )
                else
                        current_slay = tonumber(target_ply:GetPData("slaynr_slays")) or 0
                        if not should_slaynr then     
                new_slay = current_slay + num_slay 
            else
                new_slay = current_slay - num_slay     
            end
 
            --local slay_reason = reason
            --if slay_reason == "reason" then
            --  slay_reason = false
            --end
 
                        if new_slay > 0 then           
                target_ply:SetPData("slaynr_slays", new_slay)
                --target_ply:SetPData("slaynr_reason", slay_reason)
            else
                                target_ply:RemovePData("slaynr_slays")
                --target_ply:RemovePData("slaynr_reason") 
            end
 
                local slays_left        = tonumber(target_ply:GetPData("slaynr_slays"))  or 0
                        local slays_removed = ( current_slay - slays_left )             or 0
 
                        if slays_removed==0 then
                                chat_message = ("#T will not be slain next round.")
                        elseif slays_removed > 0 then
                                chat_message = ("#A removed ".. slays_removed .." round(s) of slaying from #T.")
                        elseif slays_left == 1 then
                                chat_message = ("#A will slay #T next round.")
                        elseif slays_left > 1 then
                                chat_message = ("#A will slay #T for the next ".. tostring(slays_left) .." rounds.")
                        end
                        ulx.fancyLogAdmin( calling_ply, chat_message, target_ply, reason )
                end
        end
end
local slaynr = ulx.command( CATEGORY_NAME, "ulx slaynr", ulx.slaynr, "!slaynr" )
slaynr:addParam{ type=ULib.cmds.PlayerArg }
slaynr:addParam{ type=ULib.cmds.NumArg, max=100, default=1, hint="rounds", ULib.cmds.optional, ULib.cmds.round }
--slaynr:addParam{ type=ULib.cmds.StringArg, hint="reason",  ULib.cmds.optional}
slaynr:addParam{ type=ULib.cmds.BoolArg, invisible=true }
slaynr:defaultAccess( ULib.ACCESS_ADMIN )
slaynr:help( "Slays target(s) for a number of rounds" )
slaynr:setOpposite( "ulx rslaynr", {_, _, _, true}, "!rslaynr" )
--[Helper Functions]---------------------------------------------------------------------------
hook.Add("TTTBeginRound", "SlayPlayersNextRound", function()
        local affected_plys = {}
 
        for _,v in pairs(player.GetAll()) do
                local slays_left = tonumber(v:GetPData("slaynr_slays")) or 0
       
                if v:Alive() and slays_left > 0 then
                        local slays_left=slays_left -1
 
                        if slays_left == 0 then
                v:RemovePData("slaynr_slays")
                v:RemovePData("slaynr_reason")
                        else                                   
                v:SetPData("slaynr_slays", slays_left)
            end
 
                        v:Kill()
                        table.insert( affected_plys, v )
                        local corpse = corpse_find(v)
                        if corpse then
                                corpse_identify(corpse)
                                corpse_remove(corpse)
                        end
                end
        end
 
        local slay_message
        for i=1, #affected_plys do
                local v = affected_plys[ i ]
                local string_inbetween
 
                if i > 1 and #affected_plys == i then
                        string_inbetween=" and "
                elseif i > 1 then
                        string_inbetween=", "
                end
 
                string_inbetween = string_inbetween or ""
                slay_message = ( ( slay_message or "") .. string_inbetween )
                slay_message = ( ( slay_message or "") .. v:Nick() )
        end
 
        local slay_message_context
        if #affected_plys == 1 then slay_message_context ="was" else slay_message_context ="were" end
        if #affected_plys ~= 0 then
                ULib.tsay(_, slay_message .. " ".. slay_message_context .." slain.")
        end
end)
 
hook.Add("PlayerSpawn", "Inform" , function(ply)
        local slays_left = tonumber(ply:GetPData("slaynr_slays")) or 0
        local slay_reason = false
       
        if ply:Alive() and slays_left > 0 then
                local chat_message = ""
 
                if slays_left > 0 then
                        chat_message = (chat_message .. "You will be slain this round")
                end
                if slays_left > 1 then
                        chat_message = (chat_message .. " and ".. (slays_left - 1) .." round(s) after the current round")
                end
                if slay_reason then
                        chat_message = (chat_message .. " for \"".. slays_reason .."\".")
                else
                        chat_message = (chat_message .. ".")
                end
                ply:ChatPrint(chat_message)
        end
end)
--[End]----------------------------------------------------------------------------------------
 
 
--[Force role]---------------------------------------------------------------------------------
--[[ulx.force][Forces <target(s)> to become a specified role.]
@param  {[PlayerObject]} calling_ply   [The player who used the command.]
@param  {[PlayerObject]} target_plys   [The player(s) who will have the effects of the command applied to them.]
@param  {[Number]}       target_role   [The role that target player(s) will have there role set to.]
@param  {[Boolean]}      should_silent [Hidden, determines weather the output will be silent or not.]
--]]
function ulx.force( calling_ply, target_plys, target_role, should_silent )
        if not GetConVarString("gamemode") == "terrortown" then ULib.tsayError( calling_ply, gamemode_error, true ) else
 
                local affected_plys = {}
                local starting_credits=GetConVarNumber("ttt_credits_starting")
 
                local role
                local role_grammar
                local role_string
                local role_credits
 
            if target_role ==  "traitor"   or target_role == "t" then role, role_grammar, role_string, role_credits = ROLE_TRAITOR,   "a ",  "traitor",   starting_credits end
            if target_role ==  "detective" or target_role == "d" then role, role_grammar, role_string, role_credits = ROLE_DETECTIVE, "a ",  "detective", starting_credits end
            if target_role ==  "innocent"  or target_role == "i" then role, role_grammar, role_string, role_credits = ROLE_INNOCENT,  "an ", "innocent",  0                end
           
            for i=1, #target_plys do
                        local v = target_plys[ i ]
                        local current_role = v:GetRole()
       
                        if ulx.getExclusive( v, calling_ply ) then
                                ULib.tsayError( calling_ply, ulx.getExclusive( v, calling_ply ), true )
                        elseif GetRoundState() == 1 or GetRoundState() == 2 then
                        ULib.tsayError( calling_ply, "The round has not begun!", true )
                        elseif role == nil then
                        ULib.tsayError( calling_ply, "Invalid role :\"" .. target_role .. "\" specified", true )
                        elseif not v:Alive() then
                                ULib.tsayError( calling_ply, v:Nick() .. " is dead!", true )
                        elseif current_role == role then
                        ULib.tsayError( calling_ply, v:Nick() .. " is already " .. role_string, true )
                        else
                                v:ResetEquipment()
                                RemoveLoadoutWeapons(v)
                                RemoveBoughtWeapons(v)
 
                    v:SetRole(role)
                    v:SetCredits(role_credits)
                    SendFullStateUpdate()
 
                    GiveLoadoutItems(v)
                    GiveLoadoutWeapons(v)
 
                    table.insert( affected_plys, v )
                end
            end
            ulx.fancyLogAdmin( calling_ply, should_silent, "#A forced #T to become the role of " .. role_grammar .."#s.", affected_plys, role_string )
            send_messages(affected_plys, "Your role has been set to " .. role_string .. "." )
        end
end
local force = ulx.command( CATEGORY_NAME, "ulx force", ulx.force, "!force" )
force:addParam{ type=ULib.cmds.PlayersArg }
force:addParam{ type=ULib.cmds.StringArg, completes=ulx.target_role, hint="Role" }
force:addParam{ type=ULib.cmds.BoolArg, invisible=true }
force:defaultAccess( ULib.ACCESS_SUPERADMIN )
force:setOpposite( "ulx sforce", {_, _, _, true}, "!sforce", true )
force:help( "Force <target(s)> to become a specified role." )

Offline Decicus

  • Hero Member
  • *****
  • Posts: 552
  • Karma: 81
    • Alex Thomassen
Re: TTT lua help *Urgent*
« Reply #1 on: June 21, 2014, 09:53:00 AM »
Do you get any errors in your server log/console?

I have had issues before, where the "slaynr" command conflicts with addons, but currently it works fine for me. Are you using the most updated version?
Contact information:
E-mail: alex@thomassen.xyz.
You can also send a PM.

Offline bender180

  • Full Member
  • ***
  • Posts: 217
  • Karma: 42
    • Benders Villa
Re: TTT lua help *Urgent*
« Reply #2 on: June 21, 2014, 02:23:51 PM »
I can confirm it is working as intended in the current svn and workshop version, like Decicus said check your console for errors there may be a conflicting addon.
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 Delta7x

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: TTT lua help *Urgent*
« Reply #3 on: June 25, 2014, 05:55:43 PM »
This is a known bug with the Damagelog Menu you have installed.

They're only able to talk and fly around with live players if they're marked to be slain the round before a map change and then slain on the first round of the map change. My recommendation is to just manually use !slay [Insert generic name here], or simply respawn and kill them (Pretty sure that worked for us when we had those logs installed), otherwise just gag/mute them temporarily for that round.