NPC:GetEnemy
Açıklama
Bu NPC'nin savaşmaya çalıştığı varlığı (entity) döndürür.
Döndürülen Değer
Örnek
İlk oyuncuyu düşmanı olarak belirleyen herhangi bir NPC'yi öldürür.
local function Think()
for i, ent in ipairs( ents.GetAll() ) do
if ent:IsNPC() and ent:GetEnemy() == Entity( 1 ) then
ent:TakeDamage( 999 )
end
end
end
hook.Add( "Think", "Kill My Enemies", Think )
Çıktı: Düşmanını Entity( 1 ) olarak belirleyen herhangi bir NPC ölür.
Örnek
Düşmanı olmayan (ve tercihen Oyunculara karşı bir D_HT ilişkisine sahip olan) her NPC'nin rastgele bir Oyuncuya saldırmaya başlamasını sağlar. Bu kod, My Base Defence oyun modundan kopyalanmıştır:
-- ...
local function _SetRandomPlayerTargetForNPC(npc)
if (npc:IsNPC()) then
if (!IsValid(npc:GetEnemy())) then
local _allPlayers = player.GetAll()
local _winnerPlNr = math.random(1, #_allPlayers)
timer.Simple(0.15, function()
local __Player = _allPlayers[_winnerPlNr]
--
--- Set the enemy for the NPC, so it does not just stand there doing nothing
-- lika young lazy teen or something
if (!npc:IsValid() or !__Player:IsValid()) then return end
npc:SetEnemy(__Player)
npc:UpdateEnemyMemory(__Player, __Player:GetPos())
npc:SetSchedule(SCHED_SHOOT_ENEMY_COVER)
end)
end
end
end
-- - - ---
-- --
-- Make every NPC that might not have a target, recive one random Player..:>>
-- (..you can place this loop inside an interval timer or something...)
for i, ent in ipairs( ents.GetAll('npc_*') ) do
if ent:IsValid() then _SetRandomPlayerTargetForNPC( ent ) end
end
Çıktı: SUNUCUDAKİ tüm NPC'lerin, eğer zaten bir düşmanları yoksa, hafızaları güncellenir ve düşmanın bilinen son konumuna doğru hareket edip saldırmaya çalışırlar. Bu düşman, rastgele bir Oyuncu olacaktır. Ayrıca düşman siperlerine ateş etmeye de çalışacaklardır.
Tüm sunucular · GmodTR Launcher · Rehber · GMod Wiki · GmodTR nedir? · Sunucu ekle · Discord