60 lines
1.2 KiB
Markdown
60 lines
1.2 KiB
Markdown
# FarawayOrbAgg.js — main() (satır 1)
|
||
|
||
[← FarawayOrbAgg.js](index.md) · [← Master](../../wiki.md)
|
||
|
||
```javascript
|
||
function main(c)
|
||
{
|
||
var npc = c.getSubject();
|
||
|
||
if (npc == null || !npc.isNPC())
|
||
{
|
||
return;
|
||
}
|
||
|
||
if (String(npc.getNpcId()).toLowerCase() != "farawayorb")
|
||
{
|
||
return;
|
||
}
|
||
|
||
npc.setAIEnabled(true);
|
||
npc.setPathDistance(50);
|
||
npc.setAttackRange(4);
|
||
|
||
var pos = npc.getPosition();
|
||
var entities = c.getWorld().getEntities(pos.x, pos.y, pos.z, 50);
|
||
|
||
var nearest = null;
|
||
var nearestDistance = 50 * 50;
|
||
|
||
for (var i in entities)
|
||
{
|
||
var entity = entities[i];
|
||
|
||
if (!entity.isPlayer())
|
||
{
|
||
continue;
|
||
}
|
||
|
||
if (!isFarawayDusman(entity))
|
||
{
|
||
continue;
|
||
}
|
||
|
||
var p = entity.getPosition();
|
||
var dx = p.x - pos.x;
|
||
var dy = p.y - pos.y;
|
||
var dz = p.z - pos.z;
|
||
var distance = dx * dx + dy * dy + dz * dz;
|
||
|
||
if (distance < nearestDistance)
|
||
{
|
||
nearestDistance = distance;
|
||
nearest = entity;
|
||
}
|
||
}
|
||
|
||
npc.setTarget(nearest);
|
||
}
|
||
```
|