Is there a way to "touch" all props in the server?
7 replies, posted
Using prop protection (any), after you load a save file all props are owned by N/A until you interact with them in some way. Basically, after I load a save, I want to own everything in that save without going around and phys gunning everything.
[QUOTE=hovergroovie;48775193]Using prop protection (any), after you load a save file all props are owned by N/A until you interact with them in some way. Basically, after I load a save, I want to own everything in that save without going around and phys gunning everything.[/QUOTE]
You could make a script that checks if its single player and then on initial spawn set all currently spawned props to you. This is a rough example so things might not work:
[lua]
-- InitSpawn:
-- Description: Sets player to own all dem props in the map on spawn
function InitSpawn(ply)
--Check if not singleplayer
if !game.SinglePlayer() then return end
--Get all ents in map
local ents = ents.GetAll()
--Cycle through all of the ents
for k,v in pairs(ents) do
if v:IsValid() and /*throw extra check here if you need it*/ then
ent:SetOwner(ply)
end
end
end
hook.Add("PlayerInitialSpawn", "own_dem_props", InitSpawn ) --attach function to the PlayerInitialSpawn hook so it runs when player first joins
[/lua]
I need to do this in an online, local server. Can I just remove that if?
[QUOTE=hovergroovie;48776739]I need to do this in an online, local server. Can I just remove that if?[/QUOTE]
Yea you can, but in that case I need to change it around a tad bit, because I thought you were only doing this in single player. Are you trying to only set all props that do not have a owner ONLY to you or to anyone who first joins?
I am making an obstacle course which requires a very specific method of ownership. Basically, I need to start a server, load a save, and then own all the props it loads.
[QUOTE=hovergroovie;48776983]I am making an obstacle course which requires a very specific method of ownership. Basically, I need to start a server, load a save, and then own all the props it loads.[/QUOTE]
Here I did both ways:
[lua]
-- InitSpawn:
-- Description: Sets player to own all dem props in the map on spawn
function InitSpawn(ply)
--***CODE FOR ONLY YOU***--
--See if player joining is you if not then cancel out of code
if ply:SteamID() != "Put steamID here" then return end
--***CODE FOR FIRST PERSON***--
-- Uncomment the lines below to use this code--
--ONLY!!! do it for the first player joining; I think 2 is the first player instead of 1
--if ply:UserID() != 2 then return end
--Get all ents in map
local ents = ents.GetAll()
--Cycle through all of the ents
for k,v in pairs(ents) do
if v:IsValid() and v:GetOwner() == nil then
ent:SetOwner(ply)
end
end
end
hook.Add("PlayerInitialSpawn", "own_dem_props", InitSpawn ) --attach function to the PlayerInitialSpawn hook so it runs when player first joins
[/lua]
[QUOTE=bran92don;48776998]Here I did both ways:
[lua]
-- InitSpawn:
-- Description: Sets player to own all dem props in the map on spawn
function InitSpawn(ply)
--***CODE FOR ONLY YOU***--
--See if player joining is you if not then cancel out of code
if ply:SteamID() != "Put steamID here" then return end
--***CODE FOR FIRST PERSON***--
-- Uncomment the lines below to use this code--
--ONLY!!! do it for the first player joining; I think 2 is the first player instead of 1
--if ply:UserID() != 2 then return end
--Get all ents in map
local ents = ents.GetAll()
--Cycle through all of the ents
for k,v in pairs(ents) do
if v:IsValid() and v:GetOwner() == nil then
ent:SetOwner(ply)
end
end
end
hook.Add("PlayerInitialSpawn", "own_dem_props", InitSpawn ) --attach function to the PlayerInitialSpawn hook so it runs when player first joins
[/lua][/QUOTE]
ents.GetAll() will return all entities though, not just props
[QUOTE=tyguy;48782366]ents.GetAll() will return all entities though, not just props[/QUOTE]
Which is why I told him earlier in the other code to put another check in the if statement.
Sorry, you need to Log In to post a reply to this thread.