Login to ZARP
|
-- Start of code insert
local entityList = {}
local plyList = {}
if SERVER then
concommand.Add("ttt_spec_prop_toggle_com",
function(ply, cmd, args, argStr)
--Code but in server-privileged form(?)
if ply == NULL then --NULL entity if command was entered with the dedicated server console.
local convar = GetConVar("ttt_spec_prop_toggle")
local var = convar:GetInt()
local function CheckEntitiesToSetCollisionOff()
if not table.IsEmpty(entityList) then
for k, v in pairs(entityList) do
Entity( v ):SetCollisionGroup(COLLISION_GROUP_WORLD)
Entity( v ):DrawShadow(true) -- do you want the prop to cast a shadow?
end
entityList = {}
plyList = {}
end
end
if argStr == "0" or argStr == "1" then -- (Apply as 'set convar as arg' mode)
if argStr != var then -- Sender DID NOT try to set the variable to IT'S same value.
if argStr == "1" then
CheckEntitiesToSetCollisionOff()
end
convar:SetInt(argStr)
end
else -- Apply as 'toggle' mode - Disregard all args that might have been passed.
if var == 0 then -- Set to 1, and,
CheckEntitiesToSetCollisionOff()
convar:SetInt(1)
elseif var == 1 then -- Set to 0
convar:SetInt(0)
end
end
end
end, nil, "Toggle prop possession command. \n Additionally, you can add '0' or '1' as an argument which will be passed along, and set 'ttt_spec_prop_toggle' as that value.", "0")
--print("ttt_spec_prop_toggle_com init")
else return end
-- End of code insert
-- Start of code insert
if SERVER then
if key == 4 then -- instead of also making an edit to propspec.lua. we can catch the player leaving the possessed prop here.
--print(ply:GetName(), "left the prop", CurTime())
for k, v in pairs(plyList) do
if ply:EntIndex() == v then
--print(v, k, Entity( v ), Entity( entityList[k] ))
Entity( entityList[k] ):SetNWInt( "spec_abandoned_time", CurTime() + 2 )
table.remove(plyList, k)
table.remove(entityList, k)
end
end
end
end
-- End of code insert
-- Start of code insert
if not SERVER then return end
local var = GetConVar("ttt_spec_prop_toggle"):GetInt()
if var == 0 then
tr.Entity:SetCollisionGroup(COLLISION_GROUP_NONE)
tr.Entity:DrawShadow(true)
local entID = tr.Entity:EntIndex()
if (not table.HasValue(entityList, entID)) then
table.insert(entityList, entID)
table.insert(plyList, ply:EntIndex())
end
elseif var == 1 then
tr.Entity:SetCollisionGroup(COLLISION_GROUP_WORLD)
tr.Entity:DrawShadow(true)
else
--print("The value of ttt_spec_prop_toggle was neither 1 or 0")
end
-- End of code insert
-- Start of code insert
elseif ent:GetClass() == "prop_physics" or ent:GetClass() == "prop_physics_multiplayer" and dmginfo:GetInflictor():GetClass() == "weapon_ttt_push" then
if ent:GetNWInt("push_time", 0) < CurTime() then -- apply custom newton lancher attribute
ent:SetNWInt("push_time", CurTime() + 4) -- 4 sec where it will count as a kill - from "if t > owner_time and t > CurTime() - 4 then"
if GetConVar("ttt_spec_prop_toggle"):GetInt() == 1 and ent:GetCollisionGroup() == COLLISION_GROUP_WORLD then --it should not matter if the prop is possessed, and the first 'elseif' condition has already ensured its a prop.
--make and start timer that counts down until the possessed prop returns to no collision
local shouldOccur = true
local function SetCollisionAndTimer()
if shouldOccur then
ent:SetCollisionGroup(COLLISION_GROUP_NONE)
shouldOccur = false
timer.Simple( 4,
function()
if GetConVar("ttt_spec_prop_toggle"):GetInt() == 1 then
ent:SetCollisionGroup(COLLISION_GROUP_WORLD)
end
shouldOccur = true
end
)
end
end
SetCollisionAndTimer()
end
end
-- End of code insert
-- Start of code insert
if tobool(Player(ent:UserID()):GetInfo( "ttt_spec_prop_user_toggle" )) and tobool(infl:GetNWInt("spec_owner", 0) or infl:GetNWInt("spec_abandoned_time", 0) > CurTime()) and tobool(not (infl:GetNWInt("push_time", 0) > CurTime())) then
dmginfo:ScaleDamage(0)
else
dmginfo:ScaleDamage(0.25)
end
-- End of code insert
-- Start of code override
--dmginfo:ScaleDamage(0.25)
-- End of code override
-- Start of code insert
CreateConVar("ttt_spec_prop_toggle", "0", FCVAR_LUA_SERVER + FCVAR_NOTIFY + FCVAR_REPLICATED, "Toggle ability for spectators to posses props with collision", 0, 1)
--print("ttt_spec_prop_toggle init")
-- End of code insert
-- Start of code insert
CreateClientConVar("ttt_spec_prop_user_toggle", "0", true, true, "Toggle user's stands on spectators dealing prop damage (DMG_CRUSH) to them. \n '0' = Will take damage; '1' = Will NOT take damage.", 0, 1)
--print("ttt_spec_prop_user_toggle_test init")
-- End of code insert
-- Start of code insert
elseif SERVER and IsValid(ply) then
dmginfo:SetInflictor( Entity(self:EntIndex()) )
-- End of code insert
if ply == NULL then
Entity( entityList[k] ):SetNWInt( "spec_abandoned_time", CurTime() + 2 )