Skip to content

SetActorRanged

Lets an actor with a bow or a crossbow shoot in its fights - or keeps it to its melee weapon.

An actor whose gear holds a bow (or a crossbow) and its arrows (or bolts) - its weapon preset, or the items you gave it (SetActorInventory) - fights with it by default: within range of its opponent and with a clear line it stands, draws, aims and shoots; out of range or out of sight it walks closer with the bow out; up close it changes to its melee weapon when it has one, and back to the bow when the opponent is far again. Every player sees the draw, the release and the arrow’s flight. The server decides each arrow: where it flies (the opponent’s movement led, off by a spread from accuracy - a miss is seen to miss) and what it costs - the bow’s power and the arrow’s attack against the armour on the part it struck, like a player’s arrow, through OnActorAttack (an actor struck: OnActorAttackActor). It never shoots from the saddle.

SetActorRanged(id [, enabled, range, accuracy])
Parameter Type
id number the actor
enabled boolean true (the default) = it shoots; false = its melee weapon only (a fight under way changes to it) (optional)
range number metres it shoots within (30; 5-80) (optional)
accuracy number 0-1, how close its arrows fly to where it aims (0.7: about half of them on a walking target at 20 m; 1: nearly all) (optional)

boolean - false for anything but a person actor

-- bandit archers on the road: keep their distance, shoot well
local archer = CreateActor(nil, x, y, -1, 90, "Bandit archer", nil, "animchar_battle_bow") -- a short sword, a bow, arrows
SetActorRanged(archer, true, 40, 0.85)
SetActorHostile(pid, archer, true)

SetActorHostile · SetActorInventory · OnActorAttack · CreateActor · the NPC actors group of the index