Information: Hey leute bin grade an einer Berechnung um raus zu kriegen wer der nähste spieler an was ist.
Aber es geht so nicht.
Erros: Keine
Hilfe die ich brauche: Am besten eine andere idee oder meine die auch geht
Lua
-- Aufruf --
local nearstPlayer = g_Zombie:NearestPlayer( self.id, g_Zombie:PlayerInNear( zx, zy, zz ) );
--
function g_Zombie:NearestPlayer( zombie, playerList )
local i = 0;
local distance = {};
local nearestPlayer;
local zx, zy, zz = getElementPosition( zombie );
for key, index in pairs( playerList ) do
i = i + 1
x, y, z = getElementPosition( index );
distance[i] = getDistanceBetweenPoints3D( x, y, z, zx, zy, zz );
if not distance[1] then
if distance[i] <= distance[i-1] then
nearestPlayer = index;
end
else
nearestPlayer = index;
end
end
return nearestPlayer;
end
function g_Zombie:PlayerInNear( zx, zy, zz )
local playerList = {};
for key, index in pairs( getElementsByType("player") ) do
local x, y, z = getElementPosition( index );
local distance = getDistanceBetweenPoints3D( x, y, z, zx, zy, zz );
if ( distance < Zombiesettings.Attackradius ) then
table.insert( playerList, index );
end
end
return playerList;
end
Alles anzeigen