Raid NPC


  • Forum Admin

    This explains a little bit how to make a simple script quest NPC which runs around at a scripted path, shoots, can be shot, and respawns.

    First record a story:

    Bildschirmfoto 2019-03-30 um 18.49.37.png

    In the following popup click on the waypoints button (only shown to admins):

    Bildschirmfoto 2019-03-30 um 18.49.58.png

    It will show a text window containing the waypoints for this story, you don't need to publish the story to use the waypoints, just copy the text:

    Bildschirmfoto 2019-03-30 um 18.51.01.png

    Now add an NPC with /scriptnpc and edit the script:

    function onCreated() {
        this.onRespawn();
    }
    function onUpdated() {
        this.onRespawn();
    }
    function onRespawn() {
        this.ani = "player_idle";
        this.waypoints = [
          {"x":42.5,"y":63,"ani":"gun_idle-ak47","dir":2,"speed":7.5,"zoom":1,"name":"Stefan","chat":"Stop intruder!","armor":"corleone_body03","head":"corleone_head04.png","hat":"bbuilder_bandana2.png","weapon":"ak47","pause":0.4},
          {"ani":"gun_fire-ak47","action":"shoot","sound":"ak47_fire","pause":0.3},
          {"ani":"gun_idle-ak47","pause":0.2},
          {"ani":"gun_fire-ak47","action":"shoot","sound":"ak47_fire","pause":0.3},
          {"ani":"gun_idle-ak47","pause":0.1},
          {"y":64.12,"ani":"gun_walk-ak47"},
          {"x":42.12,"y":64.5},
          {"x":39.87,"dir":3},
          {"x":38.75,"y":65.62,"dir":2},
          {"y":66},
          {"ani":"gun_idle-ak47"},
          {"ani":"gun_fire-ak47","action":"shoot","sound":"ak47_fire","pause":0.25},
          {"ani":"gun_idle-ak47","pause":0.1},
          {"ani":"gun_fire-ak47","action":"shoot","sound":"ak47_fire","pause":0.3},
          {"ani":"gun_idle-ak47","pause":0.15},
          {"ani":"gun_fire-ak47","action":"shoot","sound":"ak47_fire","pause":0.3},
          {"ani":"gun_idle-ak47","pause":0.25}
        ];
        this.hp = this.maxhp = 50;
    }
    function onDeath() {
        this.waypoints = null;
        this.chat = "Argh!";
    
        this.ani = "player_death3";
        this.hp = this.maxhp = 0;
    
        this.scheduleevent(1, "hide");
        this.cancelevents("respawn");
        this.scheduleevent(10, "respawn");
    }
    function onHide() {
        this.name = "";
        this.chat = "";
        this.ani = "";
    }
    

    This script sets the waypoints and hitpoints so that the NPCs follows the waypoints and can be shot. Once the NPC has been killed it hides and respawns after10 seconds.

    Instead of copy-pasting the waypoints you can also use stories, and set this.storyid = STORYID. Use waypoints if you want it to work on several servers or maps.


Log in to reply