diff options
| author | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-04-16 02:02:00 -0400 |
|---|---|---|
| committer | Alexander Pickering <Alexander.Pickering@anondomain.site90.net> | 2016-04-16 02:02:00 -0400 |
| commit | 7e5db609550cca0d8b8a76c4bf78ba4658962167 (patch) | |
| tree | 4df54e0c4eccff0b022e0732c258b7b193fd6cfe /gamemode/spp | |
| download | gmstranded-7e5db609550cca0d8b8a76c4bf78ba4658962167.tar.gz gmstranded-7e5db609550cca0d8b8a76c4bf78ba4658962167.tar.bz2 gmstranded-7e5db609550cca0d8b8a76c4bf78ba4658962167.zip | |
Initial commit
Diffstat (limited to 'gamemode/spp')
| -rw-r--r-- | gamemode/spp/cl_init.lua | 101 | ||||
| -rw-r--r-- | gamemode/spp/sh_cppi.lua | 87 | ||||
| -rw-r--r-- | gamemode/spp/sh_spp.lua | 96 | ||||
| -rw-r--r-- | gamemode/spp/sv_init.lua | 369 |
4 files changed, 653 insertions, 0 deletions
diff --git a/gamemode/spp/cl_init.lua b/gamemode/spp/cl_init.lua new file mode 100644 index 0000000..ca14f49 --- /dev/null +++ b/gamemode/spp/cl_init.lua @@ -0,0 +1,101 @@ + +function SPropProtection.PlayerIsPropOwner( ply, ent ) + if ( !IsValid( ent ) or ent:IsPlayer() ) then return false end + + if ( ent:GetNWString( "Owner" ) == ply:Nick() && ent:GetNWInt( "OwnerID" ) == ply:EntIndex() ) then + return true + end + + local HisTribe = GAMEMODE.FindTribeByID( ent:GetNWString( "TribeID" ) ) + + if ( !HisTribe ) then return false end + + if ( ent:GetNWString( "TribeID" ) == ply:Team() && HisTribe.pass == true ) then return true end + if ( ent:GetNWString( "TribeID" ) == ply:Team() && HisTribe.pass == true ) then return true end + + return false +end + +function SPropProtection.PlayerCanTouch( ply, ent ) + if ( GetConVarNumber( "spp_enabled" ) == 0 or ent:GetClass() == "worldspawn" ) then return true end + if ( ent:IsPlayer() or ent:IsNPC() ) then return false end + + /* Stranded Plants & Respacks*/ + local isResource = ent:GetClass() == "gms_resourcepack" or ent:GetClass() == "gms_resourcedrop" or ent:GetClass() == "gms_fridge" + local isPlant = ent:IsBerryBushModel() or ent:IsGrainModel() or ent:IsFoodModel() + if ( ( ent:GetNWString( "Owner" ) == "World" or GetConVarNumber( "spp_use" ) <= 0 ) && ( isResource or isPlant ) ) then + return true + end + + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin" ) == 1 && ent:GetNWString( "Owner" ) != "World" ) then return true end + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin_wp" ) == 1 && ent:GetNWString( "Owner" ) == "World" ) then return true end + + if ( SPropProtection.PlayerIsPropOwner( ply, ent ) ) then return true end + + -- Find the player + if ( !SPropProtection[ ply:SteamID() ] ) then return false end + for id, p in pairs( player.GetAll() ) do + if ( p:EntIndex() == ent:GetNWString( "OwnerID" ) ) then + if ( table.HasValue( SPropProtection[ ply:SteamID() ], p:SteamID() ) ) then return true end + end + end + + return false +end + +local UndoneStuff = {} +hook.Add( "HUDPaint", "spp.hudpaint", function() + if ( !IsValid( LocalPlayer() ) ) then return end + if ( #UndoneStuff > 0 ) then for id, s in pairs( UndoneStuff ) do table.insert( SPropProtection[ LocalPlayer():SteamID() ], s ) end end + local tr = LocalPlayer():GetEyeTrace() + + if ( !tr.HitNonWorld ) then return end + local ent = tr.Entity + + if ( !IsValid( ent ) || ent:IsPlayer() || ent:IsNPC() || LocalPlayer():InVehicle() ) then return end + + local OwnerName = ent:GetNWString( "Owner", "None" ) + local OwnerObj = ent:GetNWEntity( "OwnerObj" ) + if ( IsValid( OwnerObj ) ) then OwnerName = OwnerObj:Name() end + + local TribeOwner = false + local PropOwner = "Owner: " .. OwnerName + local PropOwnerTribe = "Owner tribe: " + + local HisTribe = GAMEMODE.FindTribeByID( ent:GetNWInt( "TribeID", 1 ) ) + if ( HisTribe && HisTribe.pass == true ) then TribeOwner = true PropOwnerTribe = PropOwnerTribe .. HisTribe.name end + + surface.SetFont( "DefaultBold" ) + local tw = surface.GetTextSize( PropOwner ) + local tw2 = surface.GetTextSize( PropOwnerTribe ) + + local w = math.max( ScrW() / 5, tw + 20, tw2 + 20 ) + local h = ScrH() / 24 + local x = ScrW() / 2 - w / 2 + local y = ScrH() - ScrH() / 16 + + if ( TribeOwner ) then h = ScrH() / 18 end + + surface.SetDrawColor( StrandedBackgroundColor ) + surface.DrawRect( x, y, w, h ) + + surface.SetDrawColor( StrandedBorderColor ) + surface.DrawOutlinedRect( x, y, w, h ) + + if ( TribeOwner ) then + draw.SimpleTextOutlined( PropOwner, "DefaultBold", x + w / 2, y + h / 4, StrandedTextColor, 1, 1, 0.5, StrandedTextShadowColor ) + draw.SimpleTextOutlined( PropOwnerTribe, "DefaultBold", x + w / 2, y + h / 1.5, StrandedTextColor, 1, 1, 0.5, StrandedTextShadowColor ) + else + draw.SimpleTextOutlined( PropOwner, "DefaultBold", x + w / 2, y + h / 2, StrandedTextColor, 1, 1, 0.5, StrandedTextShadowColor ) + end +end ) + +usermessage.Hook( "spp_addbuddy", function( um ) + if ( !IsValid( LocalPlayer() ) || !LocalPlayer().SteamID ) then table.insert( UndoneStuff, um:ReadString() ) return end + table.insert( SPropProtection[ LocalPlayer():SteamID() ], um:ReadString() ) +end ) + +usermessage.Hook( "spp_clearbuddy", function( um ) + if ( !IsValid( LocalPlayer() ) || !LocalPlayer().SteamID ) then UndoneStuff = {} return end + SPropProtection[ LocalPlayer():SteamID() ] = {} +end ) diff --git a/gamemode/spp/sh_cppi.lua b/gamemode/spp/sh_cppi.lua new file mode 100644 index 0000000..c5bc3aa --- /dev/null +++ b/gamemode/spp/sh_cppi.lua @@ -0,0 +1,87 @@ + +function CPPI:GetName() + return "Simple Prop Protection" +end + +function CPPI:GetVersion() + return SPropProtection.Version +end + +function CPPI:GetInterfaceVersion() + return 1.1 +end + +function CPPI:GetNameFromUID( uid ) + return CPPI_NOTIMPLEMENTED +end + +local Player = FindMetaTable( "Player" ) +if ( !Player ) then print( "EXTREME ERROR 1" ) return end + +function Player:CPPIGetFriends() + if ( SERVER ) then + local Table = {} + for k, v in pairs( player.GetAll() ) do + if ( table.HasValue( SPropProtection[ self:SteamID() ], v:SteamID() ) ) then table.insert( Table, v ) end + end + return Table + else + return CPPI_NOTIMPLEMENTED + end +end + +local Entity = FindMetaTable( "Entity" ) +if ( !Entity ) then print( "EXTREME ERROR 2" ) return end + +function Entity:CPPIGetOwner() + local Player = self:GetNetworkedEntity( "OwnerObj", false ) + if ( SERVER ) then Player = SPropProtection[ "Props" ][ self:EntIndex() ][ 3 ] end + if ( !IsValid( Player ) ) then return nil, CPPI_NOTIMPLEMENTED end + local UID = CPPI_NOTIMPLEMENTED + if ( SERVER ) then UID = Player:UniqueID() end + return Player, UID +end + +if ( SERVER ) then + function Entity:CPPISetOwner( ply ) + if ( !IsValid( ply ) or !ply:IsPlayer() ) then return false end + return SPropProtection.PlayerMakePropOwner( ply, self ) + end + + function Entity:CPPISetOwnerUID( uid ) + if ( !uid ) then return false end + local ply = player.GetByUniqueID( tostring( uid ) ) + if ( !ply ) then return false end + return SPropProtection.PlayerMakePropOwner( ply, self ) + end + + function Entity:CPPICanTool( ply, toolmode ) + if ( !IsValid( ply ) or !ply:IsPlayer() or !toolmode ) then return false end + return SPropProtection.PlayerCanTouch( ply, self ) + end + + function Entity:CPPICanPhysgun( ply ) + if ( !IsValid( ply ) or !ply:IsPlayer() ) then return false end + if ( SPropProtection.PhysGravGunPickup( ply, self ) == false ) then return false end + return true + end + + function Entity:CPPICanPickup( ply ) + if ( !IsValid( ply ) or !ply:IsPlayer() ) then return false end + if ( SPropProtection.PhysGravGunPickup( ply, self ) == false ) then return false end + return true + end + + function Entity:CPPICanPunt(ply) + if ( !IsValid( ply ) or !ply:IsPlayer() ) then return false end + if ( SPropProtection.PhysGravGunPickup( ply, self ) == false ) then return false end + return true + end +end + +hook.Add( "Initialize", "CPPIInitGM", function() + function GAMEMODE:CPPIAssignOwnership( ply, ent ) + end + function GAMEMODE:CPPIFriendsChanged( ply, ent ) + end +end ) diff --git a/gamemode/spp/sh_spp.lua b/gamemode/spp/sh_spp.lua new file mode 100644 index 0000000..1c22943 --- /dev/null +++ b/gamemode/spp/sh_spp.lua @@ -0,0 +1,96 @@ + +AddCSLuaFile( "sh_cppi.lua" ) +AddCSLuaFile( "sh_spp.lua" ) +AddCSLuaFile( "cl_init.lua" ) + +SPropProtection = SPropProtection or {} +SPropProtection.Version = 2 + +CPPI = CPPI or {} +CPPI_NOTIMPLEMENTED = 26 +CPPI_DEFER = 16 + +include( "sh_cppi.lua" ) + +if ( SERVER ) then + include( "sv_init.lua" ) +else + include( "cl_init.lua" ) +end + +/* ---------------------------------------------- + Keep these shared, so client can predict +------------------------------------------------ */ + +function SPropProtection.PhysGravGunPickup( ply, ent ) + if ( !IsValid( ent ) && ent:GetClass() != "worldspawn") then return end + if ( ent:GetNWString( "Owner" ) == "World" && ply:IsAdmin() && GetConVarNumber( "spp_admin_wp" ) == 1 ) then return true end + if ( SPropProtection.PlayerCanTouch( ply, ent ) ) then return true end +end +/*hook.Add( "GravGunPunt", "SPropProtection.GravGunPunt", PhysGravGunPickup ) +hook.Add( "GravGunPickupAllowed", "SPropProtection.GravGunPickupAllowed", PhysGravGunPickup ) +hook.Add( "PhysgunPickup", "SPropProtection.PhysgunPickup", PhysGravGunPickup ) +hook.Add( "CanTool", "SPropProtection.CanTool", PhysGravGunPickup )*/ + +/* ---------------------------------------------- + SPP Console Variables +------------------------------------------------ */ + +if ( SPPCVars ) then return end -- Auto-Refresh protection + +SPPCVars = {} + +function CreateSPPCVar( name, def ) + if ( SERVER ) then + + table.insert( SPPCVars, "spp_" .. name ) + CreateConVar( "spp_" .. name, def, FCVAR_ARCHIVE ) + + cvars.AddChangeCallback( "spp_" .. name, function( cvar, old, new ) + + if ( math.floor( old ) == math.floor( new ) ) then return end + for id, pl in pairs( player.GetAll() ) do pl:ConCommand( "spp_" .. name .. " " .. math.floor( new ) ) end + + end ) + + else + + CreateConVar( "spp_" .. name, def ) + cvars.AddChangeCallback( "spp_" .. name, function( cvar, old, new ) + + if ( math.floor( old ) == math.floor( new ) ) then return end + timer.Destroy( "spp_update" .. name ) + timer.Create("spp_update" .. name, 2, 1, function() RunConsoleCommand( "spp_update", name, math.floor( new ) ) end ) + + end ) + + end +end + +CreateSPPCVar( "enabled", "1" ) +CreateSPPCVar( "admin", "0" ) +CreateSPPCVar( "admin_wp", "0" ) +CreateSPPCVar( "use", "1" ) +CreateSPPCVar( "entdmg", "1" ) +CreateSPPCVar( "del_disconnected", "1" ) +CreateSPPCVar( "del_adminprops", "1" ) +CreateSPPCVar( "del_delay", "120" ) + +if ( CLIENT ) then return end + +concommand.Add( "spp_update", function( ply, cmd, args ) + + if ( !ply:IsAdmin() ) then return end + + local cmd = args[ 1 ] + local val = args[ 2 ] + + if ( math.floor( GetConVarNumber( "spp_" .. cmd ) ) == math.floor( val ) ) then return end + + RunConsoleCommand( "spp_" .. cmd, math.floor( val ) ) + +end ) + +hook.Add( "PlayerInitialSpawn", "spp.sync_cvars", function( ply ) + for id, cvar in pairs( SPPCVars ) do ply:ConCommand( cvar .. " " .. math.floor( GetConVarNumber( cvar ) ) ) end +end ) diff --git a/gamemode/spp/sv_init.lua b/gamemode/spp/sv_init.lua new file mode 100644 index 0000000..a4df311 --- /dev/null +++ b/gamemode/spp/sv_init.lua @@ -0,0 +1,369 @@ + +SPropProtection[ "Props" ] = SPropProtection[ "Props" ] or {} + +if ( cleanup ) then + local Clean = cleanup.Add + function cleanup.Add( ply, Type, ent ) + if ( IsValid( ent ) && ply:IsPlayer() ) then SPropProtection.PlayerMakePropOwner( ply, ent ) end + Clean( ply, Type, ent ) + end +end + +local Meta = FindMetaTable("Player") +if ( Meta.AddCount ) then + local Backup = Meta.AddCount + function Meta:AddCount( Type, ent ) + SPropProtection.PlayerMakePropOwner( self, ent ) + Backup( self, Type, ent ) + end +end + +function SPropProtection.NofityAll( Text ) + for k, ply in pairs( player.GetAll() ) do + SPropProtection.Nofity( ply, Text ) + end +end + +function SPropProtection.Nofity( ply, Text ) + ply:SendLua("GAMEMODE:AddNotify(\"" .. Text .. "\", NOTIFY_GENERIC, 5); surface.PlaySound(\"ambient/water/drip" .. math.random(1, 4) .. ".wav\")") + ply:PrintMessage( HUD_PRINTCONSOLE, Text ) +end + +function SPropProtection.PlayerMakePropOwner( ply, ent ) + if ( !IsValid( ent ) or ent:IsPlayer() ) then return end + + if ( ply && type( ply ) == "table" ) then + SPropProtection[ "Props" ][ ent:EntIndex() ] = { ply.SteamID, ent } + ent:SetNWString( "Owner", ply.Nick ) + ent:SetNWInt( "OwnerID", ply.EntIndex ) + ent:SetNWInt( "TribeID", ply.Team ) + return true + end + + if ( !IsValid( ply ) or !ply:IsPlayer() ) then return end + + SPropProtection[ "Props" ][ ent:EntIndex() ] = { ply:SteamID(), ent } + ent:SetNWString( "Owner", ply:Nick() ) + ent:SetNWInt( "OwnerID", ply:EntIndex() ) + ent:SetNWInt( "TribeID", ply:Team() ) + gamemode.Call( "CPPIAssignOwnership", ply, ent ) + return true +end + +function SPropProtection.PlayerIsPropOwner( ply, ent ) + if ( !IsValid( ent ) or ent:IsPlayer() ) then return false end + if ( !SPropProtection[ "Props" ][ ent:EntIndex() ] ) then return false end + + if ( SPropProtection[ "Props" ][ ent:EntIndex() ][ 1 ] == ply:SteamID() && ent:GetNWString( "Owner" ) == ply:Nick() && ent:GetNWInt( "OwnerID" ) == ply:EntIndex() ) then + return true + else + return false + end +end + +function SPropProtection.IsBuddy( ply, ent ) + if ( SPropProtection.PlayerIsPropOwner( ply, ent ) ) then return true end + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin" ) == 1 && ent:GetNWString( "Owner" ) != "World" ) then return true end + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin_wp" ) == 1 && ent:GetNWString( "Owner" ) == "World" ) then return true end + if ( ply:Team() == ent:GetNWInt( "TribeID", 1 ) && GAMEMODE.FindTribeByID( ply:Team() ).password != false ) then return true end + if ( ent:IsPlayer() or ent:IsNPC() ) then return false end + if ( ent:GetNWString( "Owner" ) == "World" ) then return false end + + for k, v in pairs( player.GetAll() ) do + if ( IsValid( v ) && v != ply ) then + if ( !SPropProtection[ "Props" ][ ent:EntIndex() ] ) then continue end + if ( SPropProtection[ "Props" ][ ent:EntIndex() ][ 1 ] == v:SteamID() ) then + if ( !SPropProtection[ v:SteamID() ] ) then return false end + + if ( table.HasValue( SPropProtection[ v:SteamID() ], ply:SteamID() ) ) then + return true + else + return false + end + end + end + end +end + +function SPropProtection.PlayerCanTouch( ply, ent ) + if ( GetConVarNumber( "spp_enabled" ) == 0 or ent:GetClass() == "worldspawn" ) then return true end + if ( ent:IsPlayer() or ent:IsNPC() ) then return false end + + if ( ent:GetNWString( "Owner" ) == "Everyone" && !ent:IsPlayer() ) then + return true + end + + /* Stranded Plants & Respacks*/ + local isResource = ent:GetClass() == "gms_resourcepack" or ent:GetClass() == "gms_resourcedrop" or ent:GetClass() == "gms_fridge" + local isPlant = ent:IsBerryBushModel() or ent:IsGrainModel() or ent:IsFoodModel() + if ( ( ent:GetNWString( "Owner" ) == "World" or GetConVarNumber( "spp_use" ) <= 0 ) && ( isResource or isPlant ) ) then + return true + end + + if ( ( !ent:GetNWString( "Owner" ) or ent:GetNWString( "Owner" ) == "" ) && !ent:IsPlayer() ) then + SPropProtection.PlayerMakePropOwner( ply, ent ) + SPropProtection.Nofity( ply, "You now own this prop" ) + return true + end + + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin" ) == 1 && ent:GetNWString( "Owner" ) != "World" ) then return true end + if ( ply:IsAdmin() && GetConVarNumber( "spp_admin_wp" ) == 1 && ent:GetNWString( "Owner" ) == "World" ) then return true end + if ( SPropProtection.IsBuddy( ply, ent ) ) then return true end + if ( SPropProtection[ "Props" ][ ent:EntIndex() ] != nil && SPropProtection[ "Props" ][ ent:EntIndex() ][ 1 ] == ply:SteamID() ) then + return true + end + + return false +end + +function SPropProtection.DRemove( SteamID, PlayerName ) + for k, v in pairs( SPropProtection[ "Props" ] ) do + if ( v[ 1 ] == SteamID and IsValid( v[ 2 ] ) ) then + v[ 2 ]:Remove() + SPropProtection[ "Props" ][ k ] = nil + end + end + SPropProtection.NofityAll( tostring( PlayerName ) .. "'s props have been cleaned up" ) +end + +/* Tribe PP */ + +SPropProtection.EmptifiedTribes = SPropProtection.EmptifiedTribes or {} +function SPropProtection.RemoveTribeProps( TribeID ) + for k, v in pairs( SPropProtection[ "Props" ] ) do + if ( IsValid(v[2]) and tonumber(v[2]:GetNWInt( "TribeID" ) ) == TribeID ) then + v[2]:Remove() + SPropProtection["Props"][k] = nil + end + end + SPropProtection.NofityAll( "Props of " .. GAMEMODE.FindTribeByID( TribeID ).name .. " have been cleaned up" ) + SPropProtection.EmptifiedTribes[ TribeID ] = true +end + +function SPropProtection.CheckForEmptyTribes() + for id, t in pairs( GAMEMODE.Tribes ) do + if ( team.NumPlayers( id ) == 0 && t.password != false && !timer.Exists( "SPropProtection.RemoveTribeProps: " .. id ) && !SPropProtection.EmptifiedTribes[ id ] ) then + timer.Create( "SPropProtection.RemoveTribeProps: " .. id, GetConVarNumber( "spp_del_delay" ), 1, function() SPropProtection.RemoveTribeProps( id ) end ) + elseif ( team.NumPlayers( id ) > 0 ) then + SPropProtection.EmptifiedTribes[ id ] = false + timer.Remove( "SPropProtection.RemoveTribeProps: " .. id ) + end + end +end + +function SPropProtection.TribePP( ply ) + for k, v in pairs( SPropProtection[ "Props" ] ) do + if ( v[ 1 ] == ply:SteamID() && IsValid( v[ 2 ] ) ) then + v[ 2 ]:SetNWInt( "TribeID", ply:Team() ) + + timer.Remove( "SPropProtection.RemoveTribeProps: " .. ply:Team() ) + SPropProtection.CheckForEmptyTribes() + end + end +end + +/* Hooks */ + +hook.Add( "PlayerInitialSpawn", "SPropProtection.PlayerInitialSpawn", function( ply ) + ply:SetNWString( "SPPSteamID", string.gsub( ply:SteamID(), ":", "_" ) ) + SPropProtection[ ply:SteamID() ] = {} + SPropProtection.LoadBuddies( ply ) + SPropProtection.TribePP( ply ) + + timer.Remove( "SPropProtection.DRemove: " .. ply:SteamID() ) +end ) + +hook.Add( "PlayerDisconnected", "SPropProtection.Disconnect", function( ply ) + if ( GetConVarNumber( "spp_del_disconnected" ) == 0 ) then return end + if ( ply:IsAdmin() && GetConVarNumber( "spp_del_adminprops" ) <= 0 ) then return end + if ( GAMEMODE.FindTribeByID( ply:Team() ).password == false ) then + local nick = ply:Nick() + local id = ply:SteamID() + timer.Create( "SPropProtection.DRemove: " .. ply:SteamID(), GetConVarNumber( "spp_del_delay" ), 1, function() SPropProtection.DRemove( id, nick ) end ) + end + SPropProtection.CheckForEmptyTribes() +end ) + +hook.Add( "EntityTakeDamage", "SPropProtection.EntityTakeDamage", function( ent, inflictor, attacker, amount, dmginfo ) + if ( !IsValid( ent ) || !IsValid( attacker ) ) then return end + if ( string.find( ent:GetClass(), "npc_" ) ) then return end + if ( GetConVarNumber( "spp_entdmg" ) == 0 ) then return end + if ( ent:IsPlayer() or !attacker:IsPlayer() ) then return end + if ( !SPropProtection.PlayerCanTouch( attacker, ent ) ) then + local total = ent:Health() + amount + if ( ent:GetMaxHealth() > total ) then ent:SetMaxHealth( total ) else ent:SetHealth( total ) end + end +end ) + +hook.Add( "PlayerUse", "SPropProtection.PlayerUse", function(ply, ent) + if ( ent:IsValid() && GetConVarNumber( "spp_use" ) >= 1 ) then + return SPropProtection.PlayerCanTouch( ply, ent ) + end +end ) + +hook.Add( "OnPhysgunReload", "SPropProtection.OnPhysgunReload", function( weapon, ply ) + local tr = ply:GetEyeTrace() + if ( !tr.HitNonWorld or !IsValid( tr.Entity ) or tr.Entity:IsPlayer() ) then return end + if ( !SPropProtection.PlayerCanTouch( ply, tr.Entity ) ) then return false end +end ) + +hook.Add( "EntityRemoved", "SPropProtection.EntityRemoved", function( ent ) + SPropProtection[ "Props" ][ ent:EntIndex() ] = nil +end ) + +hook.Add( "PlayerSpawnedSENT", "SPropProtection.PlayerSpawnedSENT", function( ply, ent ) + SPropProtection.PlayerMakePropOwner( ply, ent ) +end ) + +hook.Add( "PlayerSpawnedVehicle", "SPropProtection.PlayerSpawnedVehicle", function( ply, ent ) + SPropProtection.PlayerMakePropOwner( ply, ent ) +end ) + +hook.Add( "InitPostEntity", "spp_map_ents", function() + local WorldEnts = 0 + for k, v in pairs( ents.GetAll() ) do + if ( !v:IsPlayer() and !v:GetNWString( "Owner", false ) ) then + v:SetNetworkedString( "Owner", "World" ) + WorldEnts = WorldEnts + 1 + end + end + MsgC( Color( 64, 176, 255 ), "\n[ Simple Prop Protection ] " .. tostring( WorldEnts ) .. " props belong to world\n\n" ) +end ) + +/* Commands */ + +concommand.Add( "spp_cleanup_props_left", function( ply, cmd, args ) + if ( !ply:IsAdmin() ) then return end + for k1, v1 in pairs( SPropProtection[ "Props" ] ) do + local FoundUID = false + for k2, v2 in pairs( player.GetAll() ) do + if( v1[ 1 ] == v2:SteamID() ) then + FoundUID = true + end + end + if ( FoundUID == false and IsValid( v1[ 2 ] ) ) then + v1[ 2 ]:Remove() + SPropProtection[ "Props" ][ k1 ] = nil + end + end + SPropProtection.NofityAll("Disconnected players props have been cleaned up") +end ) + +concommand.Add( "spp_cleanup_props", function( ply, cmd, args ) + if ( !args[1] or args[1] == "" ) then + for k, v in pairs( SPropProtection["Props"] ) do + if (v[1] == ply:SteamID()) then + if (v[2]:IsValid()) then + v[2]:Remove() + SPropProtection["Props"][k] = nil + end + end + end + SPropProtection.Nofity(ply, "Your props have been cleaned up") + elseif ( ply:IsAdmin() ) then + for k, v in pairs(player.GetAll()) do + local NWSteamID = v:GetNWString( "SPPSteamID" ) + if ( args[1] == NWSteamID or args[2] == NWSteamID or string.find( string.Implode( " ", args ), NWSteamID ) != nil) then + for a, b in pairs( SPropProtection[ "Props" ] ) do + if ( b[1] == v:SteamID() && IsValid( b[ 2 ] ) ) then + b[2]:Remove() + SPropProtection[ "Props" ][ a ] = nil + end + end + SPropProtection.NofityAll( v:Nick() .. "'s props have been cleaned up" ) + end + end + end + ply:SetNWInt( "plants", 0 ) +end ) + +/* Buddies */ + +function SPropProtection.SyncBuddies( ply ) + for id, pl in pairs( player.GetAll() ) do + umsg.Start( "spp_clearbuddy", pl ) umsg.End() + if ( table.HasValue( SPropProtection[ ply:SteamID() ], pl:SteamID() ) ) then + umsg.Start( "spp_addbuddy", pl ) + umsg.String( ply:SteamID() ) + umsg.End() + end + end +end + +function SPropProtection.LoadBuddies( ply ) + local PData = ply:GetPData( "SPPBuddies", "" ) + if ( PData == "" ) then return end + for k, v in pairs( string.Explode( ";", PData ) ) do + local v = string.Trim( v ) + if ( v != "" ) then table.insert( SPropProtection[ ply:SteamID() ], v ) end + end + + SPropProtection.SyncBuddies( ply ) +end + +concommand.Add( "spp_apply_buddies", function( ply, cmd, args ) + if ( table.Count( player.GetAll() ) > 1 ) then + local ChangedFriends = false + for k, v in pairs( player.GetAll() ) do + local PlayersSteamID = v:SteamID() + local PData = ply:GetPData( "SPPBuddies", "" ) + if ( tonumber( ply:GetInfo( "spp_buddy_" .. v:GetNWString("SPPSteamID") ) ) == 1 ) then + if ( !table.HasValue( SPropProtection[ ply:SteamID() ], PlayersSteamID ) ) then + ChangedFriends = true + table.insert( SPropProtection[ ply:SteamID() ], PlayersSteamID ) + if ( PData == "" ) then + ply:SetPData( "SPPBuddies", PlayersSteamID .. ";") + else + ply:SetPData( "SPPBuddies", PData .. PlayersSteamID .. ";") + end + end + else + if ( table.HasValue( SPropProtection[ ply:SteamID() ], PlayersSteamID ) ) then + for k2, v2 in pairs( SPropProtection[ply:SteamID() ] ) do + if ( v2 == PlayersSteamID ) then + ChangedFriends = true + table.remove( SPropProtection[ ply:SteamID() ], k2 ) + ply:SetPData( "SPPBuddies", string.gsub( PData, PlayersSteamID .. ";", "" ) ) + end + end + end + end + end + + if ( ChangedFriends ) then + local Table = {} + for k, v in pairs( SPropProtection[ ply:SteamID() ] ) do + for k2, v2 in pairs( player.GetAll() ) do + if ( v == v2:SteamID() ) then + table.insert( Table, v2 ) + end + end + end + gamemode.Call( "CPPIFriendsChanged", ply, Table ) + end + end + + SPropProtection.SyncBuddies( ply ) + SPropProtection.Nofity( ply, "Your buddies have been updated" ) +end ) + +concommand.Add( "spp_clear_buddies", function( ply, cmd, args ) + local PData = ply:GetPData( "SPPBuddies", "" ) + if ( PData != "" ) then + for k, v in pairs( string.Explode( ";", PData ) ) do + local v = string.Trim( v ) + if ( v != "" ) then + ply:ConCommand( "spp_buddy_" .. string.gsub( v, ":", "_" ) .. " 0\n" ) + end + end + ply:SetPData( "SPPBuddies", "" ) + end + + for k, v in pairs( SPropProtection[ ply:SteamID() ] ) do + ply:ConCommand( "spp_buddy_" .. string.gsub( v, ":", "_" ) .. " 0\n" ) + end + SPropProtection[ ply:SteamID() ] = {} + + SPropProtection.SyncBuddies( ply ) + SPropProtection.Nofity( ply, "Your buddies have been cleared" ) +end ) |
