Added door locking & owner functions

master
E. Almqvist 5 years ago
parent 76028c10a7
commit d285317364
  1. 12
      entities/weapons/quantum_hands/shared.lua
  2. 40
      gamemode/engine/lib/server/sv_property.lua
  3. 9
      gamemode/engine/lib/server/sv_zone.lua
  4. 5
      gamemode/engine/vars/sh_vars.lua

@ -63,7 +63,7 @@ SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0 SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "" SWEP.Secondary.Ammo = ""
SWEP.Secondary.Delay = 0.25 SWEP.Secondary.Delay = 0.75
function SWEP:Initialize() function SWEP:Initialize()
self:SetHoldType( "normal" ) self:SetHoldType( "normal" )
@ -106,6 +106,16 @@ function SWEP:PrimaryAttack()
end end
function SWEP:SecondaryAttack() function SWEP:SecondaryAttack()
if SERVER then
local hitposEnt = self:GetOwner():GetEyeTraceNoCursor().Entity
if( Quantum.Server.DoorClasses[hitposEnt:GetClass()] && IsValid(hitposEnt) ) then -- if it is a door
if( hitposEnt:GetPos():Distance(self:GetOwner():GetPos()) <= 90 ) then
Quantum.Server.Property.PlayerSwitchLock( self:GetOwner(), hitposEnt ) -- then try to unlock/lock it
end
end
end
if CLIENT then if CLIENT then
local devmode = GetConVar( "developer" ) local devmode = GetConVar( "developer" )
if( devmode:GetBool() == true ) then if( devmode:GetBool() == true ) then

@ -19,10 +19,12 @@ function Quantum.Server.Property.Register( propid, tbl )
vec2 = tbl.vec2, vec2 = tbl.vec2,
price = tbl.price || Quantum.Server.DefualtPropertyPrice price = tbl.price || Quantum.Server.DefualtPropertyPrice
} }
prop.zone = Quantum.Server.Zone.Register( propid .. "_zone", { -- register the zone for the property
prop.zone = Quantum.Server.Zone.Register( propid .. "_property", { -- register the zone for the property
name = prop.name, name = prop.name,
vec1 = prop.vec1, vec1 = prop.vec1,
vec2 = prop.vec2 vec2 = prop.vec2,
property = propid
} ) } )
Quantum.Server.Property.Properties[propid] = prop Quantum.Server.Property.Properties[propid] = prop
@ -54,7 +56,39 @@ end)
-- Door functions -- -- Door functions --
function Quantum.Server.Property.LockDoor( ent ) function Quantum.Server.Property.LockDoor( ent )
if( ent:GetClass() ) then -- doors/door_locked2.wav if( Quantum.Server.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then --
ent:Fire( "lock", "", 0 )
ent:EmitSound( Quantum.DoorSounds.Lock )
ent.islocked = true
end
end
function Quantum.Server.Property.UnlockDoor( ent )
if( Quantum.Server.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then --
ent:Fire( "unlock", "", 0 )
ent:EmitSound( Quantum.DoorSounds.Unlock )
ent.islocked = false
end
end
function Quantum.Server.Property.SwitchLockDoor( ent )
if( Quantum.Server.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then --
if( ent.islocked ) then
Quantum.Server.Property.UnlockDoor( ent )
else
Quantum.Server.Property.LockDoor( ent )
end
end
end
function Quantum.Server.Property.PlayerSwitchLock( pl, doorent )
local zone = Quantum.Server.Zone.GetCurrentZone( pl:GetPos() )
if( Quantum.Server.Zone.DoorIsInZone(doorent, zone.id) ) then
local prop = Quantum.Server.Property.Get( zone.property )
if( prop.owner == pl || pl:IsSuperAdmin() ) then
Quantum.Server.Property.SwitchLockDoor( doorent )
else
return
end
end end
end end

@ -15,7 +15,9 @@ function Quantum.Server.Zone.Register( zoneid, tbl )
name = tbl.name || "Unknown Zone", name = tbl.name || "Unknown Zone",
id = zoneid, id = zoneid,
vec1 = tbl.vec1, vec1 = tbl.vec1,
vec2 = tbl.vec2 vec2 = tbl.vec2,
property = tbl.property -- not used for normal zones
-- why cant lua just have classes :(
} }
Quantum.Server.Zone.Zones[zoneid] = zone Quantum.Server.Zone.Zones[zoneid] = zone
@ -53,3 +55,8 @@ function Quantum.Server.Zone.GetDoors( zoneid )
return entInZone return entInZone
end end
function Quantum.Server.Zone.DoorIsInZone( doorent, zoneid )
local doors = Quantum.Server.Zone.GetDoors( zoneid )
return table.HasValue( doors, doorent )
end

@ -57,3 +57,8 @@ end
function Quantum.PrintPlayer( pl ) function Quantum.PrintPlayer( pl )
return "[" .. pl:Nick() .. "|" .. pl:SteamID() .. "]" return "[" .. pl:Nick() .. "|" .. pl:SteamID() .. "]"
end end
Quantum.DoorSounds = {
Lock = "doors/default_locked.wav",
Unlock = "doors/default_locked.wav"
}
Loading…
Cancel
Save