From 8b35e7336790705bbc01805526f0bce4f72fbb9f Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Sat, 22 Feb 2020 00:40:50 +0100 Subject: [PATCH] Ported zones & properties lib to shared realm --- gamemode/engine/lib/server/sv_property.lua | 95 ------------------- gamemode/engine/lib/sh_property.lua | 95 +++++++++++++++++++ .../lib/{server/sv_zone.lua => sh_zone.lua} | 34 +++---- gamemode/engine/vars/sh_vars.lua | 10 ++ gamemode/engine/vars/sv_vars.lua | 12 +-- 5 files changed, 123 insertions(+), 123 deletions(-) delete mode 100644 gamemode/engine/lib/server/sv_property.lua create mode 100644 gamemode/engine/lib/sh_property.lua rename gamemode/engine/lib/{server/sv_zone.lua => sh_zone.lua} (51%) diff --git a/gamemode/engine/lib/server/sv_property.lua b/gamemode/engine/lib/server/sv_property.lua deleted file mode 100644 index 177baf6..0000000 --- a/gamemode/engine/lib/server/sv_property.lua +++ /dev/null @@ -1,95 +0,0 @@ --- __ _ _______ _ __ --- / / /\ | | |__ __| | | \ \ --- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ --- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > --- \ \ / ____ \| | | | | | | | __/ (__| | | | / / --- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ - -Quantum.Server.Property = {} - -Quantum.Server.Property.Properties = {} - -function Quantum.Server.Property.Register( propid, tbl ) - if( Quantum.Server.Property.Properties[propid] == nil ) then - local prop = { - name = tbl.name || "Private Property", - id = propid, - owner = nil, - vec1 = tbl.vec1, - vec2 = tbl.vec2, - price = tbl.price || Quantum.Server.DefualtPropertyPrice - } - - prop.zone = Quantum.Server.Zone.Register( propid .. "_property", { -- register the zone for the property - name = prop.name, - vec1 = prop.vec1, - vec2 = prop.vec2, - property = propid - } ) - - Quantum.Server.Property.Properties[propid] = prop - return prop - else - Quantum.Error( "Property id '" .. propid .. "' already exists! Aborting..." ) - end -end - -function Quantum.Server.Property.Get( propid ) return Quantum.Server.Property.Properties[propid] end - --- Player functions -- - -function Quantum.Server.Property.SetOwner( propid, charid ) - Quantum.Server.Property.Properties[propid].owner = charid -end - -hook.Add( "Move", "Quantum_Move_Property_CheckInZone", function( ply, mv ) - if( ply.isloaded ) then - if( mv:GetVelocity() != Vector( 0, 0, 0 ) ) then - local zone = Quantum.Server.Zone.GetCurrentZone( ply:GetPos() ) - if( zone != nil ) then - ply:ChatPrint( zone.name ) - end - end - end -end) - --- Door functions -- - -function Quantum.Server.Property.LockDoor( ent ) - 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( zone == nil ) then return end - 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 \ No newline at end of file diff --git a/gamemode/engine/lib/sh_property.lua b/gamemode/engine/lib/sh_property.lua new file mode 100644 index 0000000..4839a80 --- /dev/null +++ b/gamemode/engine/lib/sh_property.lua @@ -0,0 +1,95 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Property = {} + +Quantum.Property.Properties = {} + +function Quantum.Property.Register( propid, tbl ) + if( Quantum.Property.Properties[propid] == nil ) then + local prop = { + name = tbl.name || "Private Property", + id = propid, + owner = nil, + vec1 = tbl.vec1, + vec2 = tbl.vec2, + price = tbl.price || Quantum.DefualtPropertyPrice + } + + prop.zone = Quantum.Zone.Register( propid .. "_property", { -- register the zone for the property + name = prop.name, + vec1 = prop.vec1, + vec2 = prop.vec2, + property = propid + } ) + + Quantum.Property.Properties[propid] = prop + return prop + else + Quantum.Error( "Property id '" .. propid .. "' already exists! Aborting..." ) + end +end + +function Quantum.Property.Get( propid ) return Quantum.Property.Properties[propid] end + +-- Player functions -- + +function Quantum.Property.SetOwner( propid, charid ) + Quantum.Property.Properties[propid].owner = charid +end + +hook.Add( "Move", "Quantum_Move_Property_CheckInZone", function( ply, mv ) -- DEBUG REMOVE LATER + if( ply.isloaded ) then + if( mv:GetVelocity() != Vector( 0, 0, 0 ) ) then + local zone = Quantum.Zone.GetCurrentZone( ply:GetPos() ) + if( zone != nil ) then + ply:ChatPrint( zone.name ) + end + end + end +end) + +-- Door functions -- + +function Quantum.Property.LockDoor( ent ) + if( Quantum.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then + ent:Fire( "lock", "", 0 ) + ent:EmitSound( Quantum.DoorSounds.Lock ) + ent.islocked = true + end +end + +function Quantum.Property.UnlockDoor( ent ) + if( Quantum.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then + ent:Fire( "unlock", "", 0 ) + ent:EmitSound( Quantum.DoorSounds.Unlock ) + ent.islocked = false + end +end + +function Quantum.Property.SwitchLockDoor( ent ) + if( Quantum.DoorClasses[ent:GetClass()] && IsValid( ent ) ) then + if( ent.islocked ) then + Quantum.Property.UnlockDoor( ent ) + else + Quantum.Property.LockDoor( ent ) + end + end +end + +function Quantum.Property.PlayerSwitchLock( pl, doorent ) + local zone = Quantum.Zone.GetCurrentZone( pl:GetPos() ) + if( zone == nil ) then return end + if( Quantum.Zone.DoorIsInZone(doorent, zone.id) ) then + local prop = Quantum.Property.Get( zone.property ) + if( prop.owner == pl || pl:IsSuperAdmin() ) then + Quantum.Property.SwitchLockDoor( doorent ) + else + return + end + end +end \ No newline at end of file diff --git a/gamemode/engine/lib/server/sv_zone.lua b/gamemode/engine/lib/sh_zone.lua similarity index 51% rename from gamemode/engine/lib/server/sv_zone.lua rename to gamemode/engine/lib/sh_zone.lua index 483a745..1ebf07d 100644 --- a/gamemode/engine/lib/server/sv_zone.lua +++ b/gamemode/engine/lib/sh_zone.lua @@ -5,12 +5,12 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -Quantum.Server.Zone = {} +Quantum.Zone = {} -Quantum.Server.Zone.Zones = {} -- all zones are rectangles where they go from vec1 to vec2 +Quantum.Zone.Zones = {} -- all zones are rectangles where they go from vec1 to vec2 -function Quantum.Server.Zone.Register( zoneid, tbl ) - if( Quantum.Server.Zone.Zones[zoneid] == nil ) then +function Quantum.Zone.Register( zoneid, tbl ) + if( Quantum.Zone.Zones[zoneid] == nil ) then local zone = { name = tbl.name || "Unknown Zone", id = zoneid, @@ -20,35 +20,35 @@ function Quantum.Server.Zone.Register( zoneid, tbl ) -- why cant lua just have classes :( } - Quantum.Server.Zone.Zones[zoneid] = zone + Quantum.Zone.Zones[zoneid] = zone return zone else Quantum.Error( "Zone id '" .. zoneid .. "' already exists! Aborting..." ) end end -function Quantum.Server.Zone.Get( zoneid ) - return Quantum.Server.Zone.Zones[zoneid] +function Quantum.Zone.Get( zoneid ) + return Quantum.Zone.Zones[zoneid] end -function Quantum.Server.Zone.IsInZone( vec, zoneid, zone ) - zone = zone || Quantum.Server.Zone.Get( zoneid ) +function Quantum.Zone.IsInZone( vec, zoneid, zone ) + zone = zone || Quantum.Zone.Get( zoneid ) return vec:WithinAABox( zone.vec1, zone.vec2 ) end -function Quantum.Server.Zone.GetCurrentZone( vec ) - for i, zone in pairs( Quantum.Server.Zone.Zones ) do - if( Quantum.Server.Zone.IsInZone( vec, nil, zone ) ) then +function Quantum.Zone.GetCurrentZone( vec ) + for i, zone in pairs( Quantum.Zone.Zones ) do + if( Quantum.Zone.IsInZone( vec, nil, zone ) ) then return zone end end end -function Quantum.Server.Zone.GetDoors( zoneid ) - local zone = Quantum.Server.Zone.Get( zoneid ) +function Quantum.Zone.GetDoors( zoneid ) + local zone = Quantum.Zone.Get( zoneid ) local entInZone = {} for i, ent in pairs( ents.FindInBox( zone.vec1, zone.vec2 ) ) do - if( Quantum.Server.DoorClasses[ ent:GetClass() ]) then + if( Quantum.DoorClasses[ ent:GetClass() ]) then entInZone[i] = ent end end @@ -56,7 +56,7 @@ function Quantum.Server.Zone.GetDoors( zoneid ) return entInZone end -function Quantum.Server.Zone.DoorIsInZone( doorent, zoneid ) - local doors = Quantum.Server.Zone.GetDoors( zoneid ) +function Quantum.Zone.DoorIsInZone( doorent, zoneid ) + local doors = Quantum.Zone.GetDoors( zoneid ) return table.HasValue( doors, doorent ) end \ No newline at end of file diff --git a/gamemode/engine/vars/sh_vars.lua b/gamemode/engine/vars/sh_vars.lua index 74e3943..56dacf1 100644 --- a/gamemode/engine/vars/sh_vars.lua +++ b/gamemode/engine/vars/sh_vars.lua @@ -61,4 +61,14 @@ end Quantum.DoorSounds = { Lock = "doors/default_locked.wav", Unlock = "doors/default_locked.wav" +} + +Quantum.DefualtPropertyPrice = 5000 + +Quantum.DoorClasses = { + ["func_door"] = true, + ["func_door_rotating"] = true, + ["prop_door_rotating"] = true, + ["func_movelinear"] = true, + ["prop_dynamic"] = true } \ No newline at end of file diff --git a/gamemode/engine/vars/sv_vars.lua b/gamemode/engine/vars/sv_vars.lua index e020f50..d5c920f 100644 --- a/gamemode/engine/vars/sv_vars.lua +++ b/gamemode/engine/vars/sv_vars.lua @@ -7,14 +7,4 @@ Quantum.Server.DefaultNodeHealth = 10 -Quantum.Server.DefaultNodeRespawnTimer = 30 - -Quantum.Server.DefualtPropertyPrice = 5000 - -Quantum.Server.DoorClasses = { - ["func_door"] = true, - ["func_door_rotating"] = true, - ["prop_door_rotating"] = true, - ["func_movelinear"] = true, - ["prop_dynamic"] = true -} \ No newline at end of file +Quantum.Server.DefaultNodeRespawnTimer = 30 \ No newline at end of file