Stopping players from spawning props on player spawn zones ??
16 replies, posted
Is there a way to stop players from spawning props on the spawn point ?
Yes, you would hook into the spawning hook, define the spawn area, and return false if the vector is inside the area. Let me whip up some code for you.
[Lua]
-- Copyright (c) 2012 , James Swift
-- This script is under this license : [url]https://sites.google.com/site/jamesaddons/home/terms-of-Service[/url]
local SpawnPoint = {
Min = Vector(-100 ,-100 ,-100 ),
Max = Vector( 100 , 100 , 100 )
}
hook.Add( "PlayerSpawnObject", "AntiSpawn", function( Player, Model , Entity )
local position = Entity:GetPos( )
local InAreaX = ( position.x > SpawnPoint.Min.x and position.x < SpawnPoint.Max.x )
local InAreaY = ( position.y > SpawnPoint.Min.y and position.y < SpawnPoint.Max.y)
local InAreaZ = ( position.z > SpawnPoint.Min.z and position.z < SpawnPoint.Max.z)
local Inarea = ( InAreaX and InAreaY and InAreaZ )
if ( Inarea and not ( Player:IsAdmin() ) )then
Entity:Remove( )
-- If the object is in the area, delete it if not admin
end
end)
[/Lua]
Or, You could use Ents.FindInBox and compare the results.
[code]
local SpawnPosMin = Vector(0,0,0)
local SpawnPosMax = Vector(100,100,100)
do
for k,v in pairs(ents.FindByClass("prop_physics")) do
if (((v:GetPos().x > SpawnPosMin.x) && (v:GetPos().y > SpawnPosMin.y) &&( v:GetPos().z < v:SpawnPosMin.z ) && ((v:GetPos().x < SpawnPosMax.x) && (v:GetPos().y < SpawnPosMax.y) &&( v:GetPos().z < SpawnPosMax.z )))then
v:Remove()
end
end
[/code]
Only way if you dont want people spawning props out side of the spawn and placing them inside.
[QUOTE=dingusnin;34474901][code]
local SpawnPosMin = Vector(0,0,0)
local SpawnPosMax = Vector(100,100,100)
do
for k,v in pairs(ents.FindByClass("prop_physics")) do
if (((v:GetPos().x > SpawnPosMin.x) && (v:GetPos().y > SpawnPosMin.y) &&( v:GetPos().z < v:SpawnPosMin.z ) && ((v:GetPos().x < SpawnPosMax.x) && (v:GetPos().y < SpawnPosMax.y) &&( v:GetPos().z < SpawnPosMax.z )))then
v:Remove()
end
end
[/code]
Only way if you dont want people spawning props out side of the spawn and placing them inside.[/QUOTE]
[Lua]
local SpawnPosMin = Vector(0,0,0)
local SpawnPosMax = Vector(100,100,100)
do -- Why do we need new chunk here?
for k,v in pairs(ents.FindByClass("prop_physics")) do
if (((v:GetPos().x > SpawnPosMin.x) && (v:GetPos().y > SpawnPosMin.y) &&( v:GetPos().z < v:SpawnPosMin.z ) && ((v:GetPos().x < SpawnPosMax.x) && (v:GetPos().y < SpawnPosMax.y) &&( v:GetPos().z < SpawnPosMax.z )))
-- Or you could save the position in a local variable and not call Entity:GetPos() 6 times per entity per frame?
then
v:Remove()
end
end
-- Missing an end here, for the new chunk you made ...
-- And you need to put it in the think hook, otherwise it's just plain useless...
[/Lua]
Also, Indented code is easier to read, and you would have noticed the missing end more easily.
What you did is exactly what I did, except without adding hooks, creating useless chunks, overusing functions ( 6 calls per entity per frame? ), and missing an end.
[QUOTE=James xX;34474843]Yes, you would hook into the spawning hook, define the spawn area, and return false if the vector is inside the area. Let me whip up some code for you.
[Lua]
-- Copyright (c) 2012 , James Swift
-- This script is under this license : [url]https://sites.google.com/site/jamesaddons/home/terms-of-Service[/url]
local SpawnPoint = {
Min = Vector(-100 ,-100 ,-100 ),
Max = Vector( 100 , 100 , 100 )
}
hook.Add( "PlayerSpawnObject", "AntiSpawn", function( Player, Model , Entity )
local position = Entity:GetPos( )
local InAreaX = ( position.x > SpawnPoint.Min.x and position.x < SpawnPoint.Max.x )
local InAreaY = ( position.y > SpawnPoint.Min.y and position.y < SpawnPoint.Max.y)
local InAreaZ = ( position.z > SpawnPoint.Min.z and position.z < SpawnPoint.Max.z)
local Inarea = ( InAreaX and InAreaY and InAreaZ )
if ( Inarea and not ( Player:IsAdmin() ) )then
Entity:Remove( )
-- If the object is in the area, delete it if not admin
end
end)
[/Lua]
Or, You could use Ents.FindInBox and compare the results.[/QUOTE]
Fixed your code, And you could of just done this:
[code]
local SpawnPoint = { min = Vector(-100,-100,-100), max = Vector(100,100,100)}
local entss = ents.FindInBox(SpawnPoint.min,SpawnPoint.max)
do
for k,v in pairs(entss) do
if v:GetClass() == "prop_physics" then v:Remove()
end
end
end
[/code]
[QUOTE=dingusnin;34474974]Fixed your code, And you could of just done this:
[code]
local SpawnPoint = { min = Vector(-100,-100,-100), max = Vector(100,100,100)}
local entss = ents.FindInBox(SpawnPoint.min,SpawnPoint.max)
[/code][/QUOTE]
In your ignorance you might have missed the part at the bottom of my post that said you could also use Ents.FindInBox ...
[QUOTE=James xX;34475131]In your ignorance you might have missed the part at the bottom of my post that said you could also use Ents.FindInBox ...[/QUOTE]
I did say that you gave me the idea :3
It is an effective bit of coding, only problem is, players with lesser understanding don't understand why their creations vanish when they get to close to the spawn. How would I go about using a similar script to teleport players & their props to a nominated spot or distance from the spawn ?
instead of v:Remove() , do v:SetPos(Vector(x,y,z)
Thanking you guys so very much for you assistance and wisdom.
[QUOTE=wizardsbane;34480934][url]http://en.wikipedia.org/wiki/Sarcasm[/url][/QUOTE]
[url]http://en.wikipedia.org/wiki/Pedant[/url]
Now let's stop shit posting, the guy got his answer, let's not turn this into a battle on whose got the biggest URL.
Where would someone call themselves a pedant? Only in this thread, ladies and gentlemen.
What are you on about still? I was saying that I was pedantic, not you.
Now now kittys... Let's not get into a scrap now...
Sorry, you need to Log In to post a reply to this thread.