In the Ranger Camp on Silan, about ten metres from the Fyros fight trainer Utehes Isy and the Fyros leader Guilan Guiter, two Fyros trainees named Pimus Pilion and Iodon Kritheus spar without end. One of them challenges the other, they fight until one of them is down to a fifth of his hit points, the loser gives up, and both sit down. Once the loser has healed, he asks for a rematch.
The service has no special code for this. The whole effect comes from two NPC groups that name each other as enemy factions, plus HP triggers, timers and user events in AI script. This page goes through the setup so it can be reused for other sparring or duelling NPCs.
Both NPCs are in the Silan urban primitive, primitives/newbieland/urban_newbieland.primitive:
npc_manager "fight trainee"
npc_zone "refugeefight01" ai_movement = stand_on_start_point, ai_activity = no_change
npc_group "fighter1" one bot: Pimus Pilion
npc_group "fighter2" one bot: Iodon Kritheus
| Group | Bot | Position (x, y) | Right hand | Left hand |
|---|---|---|---|---|
fighter1 |
Pimus Pilion | 10368.4, -11677.1 | icfm1ss.sitem (Blam Sword) |
icfss.sitem (Stok Shield) |
fighter2 |
Iodon Kritheus | 10374.5, -11677.1 | icfm1ss.sitem (Blam Sword) |
iccm1pd.sitem (Dagger) |
Both bots stand six metres apart and use sheet_client = fyha1, with USER_MODEL: trainee in their equipment list instead of a server sheet. Their spoken lines are the NPE_FIGHT_* phrases, written in translation/work/phrases/nbland_npcs_village.txt.
The Ryzom Core leveldesign repository has those phrases in its translation files, but its Silan primitives are a small subset and do not include the fighters.
The two bots get their stats from a user model named trainee, a user_model node in the same primitive file. Its script sets creature attributes such as Basics.life, Basics.LifeRegen, the attack and defence levels, basics.nbhittokillplayer and basics.playerhplevel on top of the fyha1 base sheet. The user model is looked up by its name property together with the bot's primitive file, so a model is only visible to bots in the same file. See Creature AI Action Sheets for how PlayerHpLevel and NbHitToKillPlayer set creature damage.
Basics.LifeRegen is in hit points per second. The time the loser needs to regenerate from 20% to full health is the pause between bouts.
Each group's setFighter() function turns it into a combatant:
()setFactionProp("faction", $me); // fighter1 is in faction "fighter1"
()setFactionProp("ennemyFaction", $enemy); // and treats faction "fighter2" as its enemy
()setBotAttackable(1);
()setAggro(20,12);
()setActivity("faction");
()addHpDownTrigger(0.2, 0);
user_event_0 on the group when its bot's HP falls below 20%. The trigger stays registered after it fires until delHpDownTrigger removes it.The other two functions turn the group back into a bystander:
giveUp()
{
()delHpDownTrigger(0.2, 0);
()setActivity("normal");
()setBotAttackable(0);
()setAggro(0,12);
()clearAggroList();
()addHpUpTrigger(1, 1); // when HP is back to 100%, raise user_event_1: the rematch
}
win()
{
()delHpDownTrigger(0.2, 0);
()setActivity("normal");
()setBotAttackable(0);
()setAggro(0,12);
()clearAggroList();
}
Every group defines these functions, its variables ($me, $enemy, starter, dead) and its respawn and despawn times (200 and 100 ticks) in its start_of_state code block. The group then calls the other one by name, as in ()fighter2.setEvent(3), which works for any static group in the same AI instance (see AI Script).
Times are in ticks (game cycles, 10 per second).
fighter1's start_of_state starts timer t2, at a random 100 to 200 ticks (10 to 20 s). When it fires, fighter1 raises its own user_event_1, so Pimus Pilion always opens the first bout after a restart.user_event_1 sets starter = 1, stands the bot up, starts t0 at 20 and t3 at 60, and sends user_event_2 to the other group. That group sets starter = 0, stands up and starts t0 at 30 and t3 at 60.NPE_FIGHT_START_* lines (via user_event_5) after 2 s, and the other answers with an NPE_FIGHT_ENGAGE_* line (via user_event_4) a second later.setFighter() and attack each other.user_event_0 fires. It says an NPE_FIGHT_I_LOSE_* line, calls giveUp(), sends user_event_3 to the other group and starts t1 at 50 to 100 ticks. The winner's user_event_3 calls win(), plays the roar emote, says an NPE_FIGHT_I_WIN_* line and starts its own t1.setMode("Normal") and sits down (sit_down action).giveUp() added fires when the loser's HP is back to 100%. That raises user_event_1 on the loser, which removes the trigger and makes the loser the next challenger. The cycle goes back to step 2.So the challenger of each bout is the loser of the one before, which is what the lines are written for: the challenger's "You've rested enough" and the reply "The last time wasn't enough for you?".
When a fighter dies. If a bout ends in a death anyway, the dead group's group_eliminated handler sets dead = 1 and sends user_event_6 to the other group. That group says NPE_FIGHT_DOH. If it is alive itself, it calls win(), sits down after t1 and starts t2 at 400 ticks (40 s), after which it challenges again. If both are dead, it starts t2 at 200 ticks instead. The dead bot respawns after its respawn time and walks back to its start point, and the destination_reached event that the stand_on_start_point movement then sends resets dead = 0.
| Event | Raised by | Handler |
|---|---|---|
start_of_state |
the state starting | Defines the functions and variables; fighter1 only: t2 = 100 to 200 |
timer_t2_triggered |
start_of_state, user_event_6 |
setEvent(1) |
user_event_1 (challenge) |
t2, or the HP-up trigger at 100% | delHpUpTrigger(1, 1), starter = 1, standUp(), t3 = 60, t0 = 20, other group setEvent(2) |
user_event_2 (accept) |
the other group's user_event_1 |
starter = 0, standUp(), t3 = 60, t0 = 30 |
timer_t0_triggered |
user_event_1, user_event_2 |
setEvent(5) if starter, else setEvent(4) |
user_event_5 |
t0 | Random NPE_FIGHT_START_01 to 04 |
user_event_4 |
t0 | Random NPE_FIGHT_ENGAGE_01 to 04 |
timer_t3_triggered |
user_event_1, user_event_2 |
delHpUpTrigger(1, 1), setFighter() |
user_event_0 (yield) |
the HP-down trigger at 20% | Random NPE_FIGHT_I_LOSE_01 to 04, giveUp(), other group setEvent(3), t1 = 50 to 100 |
user_event_3 (win) |
the other group's user_event_0 |
win(), t1 = 50 to 100, roar emote, random NPE_FIGHT_I_WIN_01 to 04 |
timer_t1_triggered |
user_event_0, user_event_3, user_event_6 |
setMode("Normal"), sit_down |
group_eliminated |
the group's bot dying | dead = 1, other group setEvent(6) |
user_event_6 |
the other group's group_eliminated |
NPE_FIGHT_DOH; alive: win(), t1 = 50 to 100, t2 = 400; dead: t2 = 200 |
destination_reached |
the bot reaching its start point | dead = 0 |
The random lines use a random_select action over four say actions. The handlers are otherwise code actions, plus multi_actions where a handler both speaks and runs code.
| Phrase | English text |
|---|---|
NPE_FIGHT_START_01 |
I'm in exceptional form today, I could kill Daï-Den alone I think! |
NPE_FIGHT_START_02 |
Get up! I've got to show you what Utehes Isy taught me. |
NPE_FIGHT_START_03 |
*stretches* I'm tired of sitting. A small battle to warm up? |
NPE_FIGHT_START_04 |
Hop to it! You've rested enough; we need to fight or I'll fall asleep! |
NPE_FIGHT_ENGAGE_01 |
Stop talking and fight. |
NPE_FIGHT_ENGAGE_02 |
If you really want... *sigh* |
NPE_FIGHT_ENGAGE_03 |
Aah... *yawn* I just fell asleep! |
NPE_FIGHT_ENGAGE_04 |
The last time wasn't enough for you? |
NPE_FIGHT_I_LOSE_01 |
*hurt* Argh... |
NPE_FIGHT_I_LOSE_02 |
*breathes* Okay, okay... stop, you've won. |
NPE_FIGHT_I_LOSE_03 |
Hey! You nearly killed me!? Stop, you're too dangerous. |
NPE_FIGHT_I_LOSE_04 |
Come on, that's enough, I'm fed up. |
NPE_FIGHT_I_WIN_01 |
Aha, you see? I'm the best, do you still have any doubt about it? |
NPE_FIGHT_I_WIN_02 |
I'm getting the impression that you get a little worse with every battle. |
NPE_FIGHT_I_WIN_03 |
Aha! Not bad, this time I thought that I actually might lose. |
NPE_FIGHT_I_WIN_04 |
*flexes his muscles* Next! |
NPE_FIGHT_DOH |
Ouch. I probably went a bit too far. Well, the Karavan or the Kami will resurrect you... I hope. |
$enemy and once in the <group>.setEvent(n) calls. Copying the pair means renaming both.start_of_state). If both did, two challenges could cross.user_model node in the same primitive file as the bots.group_eliminated and user_event_6 branch, or a death will stop the loop.