ents.FindInSphere

  table ents.FindInSphere( Vector origin, number radius )

Açıklama

Belirtilen küre içindeki tüm varlıkları alır.

Bu fonksiyon, dahili olarak haritadaki her varlık için Yönlendirilmiş Sınırlayıcı Kutularına (Orientated Bounding Box) dayanarak util.IsBoxIntersectingSphere fonksiyonunu çağırır.

Argümanlar

1 Vector origin
Kürenin merkezi.
2 number radius
Kürenin yarıçapı.

Döndürülenler

1 sıralı table<Entity>
Bulunan tüm Entity'lerin bir tablosu.

Örnek

Kullanma (Use) tuşuna basılı tutulduğunda, oyuncuya bağlı varlıkları yok sayarak FindInSphere fonksiyonunu görselleştirir.

local entities = {} local entities_sv = {} local pos = Vector() local rad = 1000 if ( SERVER ) then util.AddNetworkString( "send_sv_ents" ) end hook.Add( "Think", "VisualizeFindInSphere", function() local ply = Entity( 1 ) if ( IsValid( ply ) and ply:KeyDown( IN_USE ) ) then pos = ply:GetPos() entities = ents.FindInSphere( pos, rad ) local newTab = {} for id, ent in pairs( entities ) do if ( ent:GetParent() == ply || ent == ply || ent:GetClass() == "gmod_hands" || ent:GetClass() == "viewmodel" ) then -- Bu varlığı yoksay else local entTable = { ent = ent, pos = ent:GetPos(), ang = ent:GetAngles(), mins = ent:OBBMins(), maxs = ent:OBBMaxs(), class = ent:GetClass() } -- doğma noktalarının boyutu olmadığı için taklit ediyoruz if ( ent:GetClass() == "info_player_start" ) then entTable.mins = ply:OBBMins() entTable.maxs = ply:OBBMaxs() end table.insert( newTab, entTable ) end end entities = newTab if ( SERVER ) then net.Start( "send_sv_ents" ) net.WriteTable( entities ) net.Broadcast() end end end ) net.Receive( "send_sv_ents",function( len, ply ) entities_sv = net.ReadTable() end ) local function RenderEnts( enti, clr, isCl ) for id, tabl in pairs( enti ) do local ent = tabl.ent local test = "NULL" if ( IsValid( ent ) ) then test = ent:EntIndex() end debugoverlay.EntityTextAtPosition( tabl.pos, isCl and 1 or 0, (isCl and "CL " or "SV ") .. "Entity " .. test .. " " .. tabl.class, FrameTime() ) render.DrawWireframeBox( tabl.pos, tabl.ang, tabl.mins, tabl.maxs, clr, true ) end end local mat = Material( "models/wireframe" ) hook.Add( "PostDrawTranslucentRenderables", "VisualizeFindInSphere", function() render.SetMaterial( mat ) render.DrawSphere( pos, rad, 8, 8 ) render.DrawSphere( pos, -rad, 8, 8 ) local clr = Color( 255, 128, 0 ) RenderEnts( entities, clr, true ) clr = Color( 0, 128, 255 ) RenderEnts( entities_sv, clr ) end )
Çıktı:
image.png

Tüm sunucular · GmodTR Launcher · Rehber · GMod Wiki · GmodTR nedir? · Sunucu ekle · Discord