Files

58 lines
1.8 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# npc.js — startLoop() (satır 374)
[← npc.js](index.md) · [← Master](../../wiki.md)
Parça 2/3 · [önceki](startLoop.md) · [sonraki](startLoop-3.md)
```javascript
};
wander[id] = st;
}
var wdx = st.x - p.x;
var wdz = st.z - p.z;
var wd = Math.sqrt(wdx * wdx + wdz * wdz);
if (wd > 0.1)
{
gw.addMotion((wdx / wd) * WANDER_SPEED, 0, (wdz / wd) * WANDER_SPEED);
gw.setRotations(0, Math.atan2(-wdx, wdz) * 180 / Math.PI, Math.atan2(-wdx, wdz) * 180 / Math.PI);
}
}
ctx.scheduleScript(LOOP_TICKS, loop);
return;
}
// --- TAKİP / SALDIRI: hedef oyuncuyu belirle ---
var destName = (mode === "attack") ? mappet.get("hector_attack_target") : TARGET_NAME;
var target = destName ? ctx.getServer().getPlayer(destName) : null;
// Hedef offline -> bekle, tekrar dene (sistem hâlâ açık).
if (!target)
{
ctx.scheduleScript(LOOP_TICKS, loop);
return;
}
var tpos = target.getPosition();
for (var i = 0; i < guards.size(); i++)
{
var e = guards.get(i);
if (!e) continue;
var pos = e.getPosition();
var dx = tpos.x - pos.x;
var dz = tpos.z - pos.z;
var dist = Math.sqrt(dx * dx + dz * dz);
var yaw = Math.atan2(-dx, dz) * 180 / Math.PI;
// SALDIRI: menzile girince hasar ver
if (mode === "attack" && dist < ATTACK_RANGE)
{
target.damage(ATTACK_DMG);
e.swingArm();
e.setRotations(0, yaw, yaw);
```