User Tools

Site Tools


scriptlib:minerminig

This is an old revision of the document!


A Miner Mining

  • Create 3 mounds of dirt in your grove
  • Create a spawn point and attach a friendly NPC to it. I recommend using 122, who is a mining NPC already equippred with a shovel.
  • Use /iscript to add the following script, making you sure alter walk_locations and ACTOR_CDEFID to match the locations of your mounds and the Creature Def ID of your actor.
/*
 * This script demonstrates adding some 'life' to an NPC. The
 * NPC is instructed to walk to one of several spots (randomly
 * chosen). They will then say a phrase in local chat (again
 * chosen randomly), and finally performing an emote, and
 * then going through the whole cycle again.
 *
 */

// Change this for to the create definition ID you want to animate
const ACTOR_CDEFID = 122;

// Change this to use different animation
const ANIMATION = "Dig_Shovel";

// This determines the chance the actor will speak when they arrive (%age chance)
const SPEAK_CHANCE = 33;

/* The speed you want your actor to walk at. There are 3 pre-defined
 * speed constants you can use :-
 *
 * CREATURE_WALK_SPEED
 * CREATURE_JOG_SPEED
 * CREATURE_RUN_SPEED
 *
 * Or you can use any integer number between 1 and 500.
 *
 * NOTE!!!! Speed doesn't currently work properly
 *
 */
speed <- CREATURE_JOG_SPEED;

/*
 * An 'array' of different things the actor might say.
 */
phrases <- [
	"I just know it's buried here somewhere ..",
	"One day I'll be able to pay others to do this for me",
	"I really dig ... digging",
	"Rock .. that's all I seem to find these days",
	"I mine the mine, and what's mine is mine",
	"I'm really digging a hole for myself here"
];

/*
 * An array of locations the actor may move to. Each location
 * is a 'Point' object, that contains the X and Z co-ordinates
 */
walk_locations <- [
	Point(3028, 4110),
	Point(3139, 4048),
	Point(3026, 4006)
];

/*
 * Move the actor to one of the pre-defined spots
 */
function moveSomewhere() {
	/*
	 * Pick a random location from the list. 'randmodrnd' is used as it
	 * returns a number between 0 (inclusive) and 1 less than the number of possible
	 * locations
	 */
	local location = walk_locations[randmodrng(0, walk_locations.len())];

	// As with most things, we need the CID of the creature to act on
	local cid = inst.cids(ACTOR_CDEFID)[0];

	/* Instruct the  actor to walk to the chosen location. The
	 * last argument to 'orderWalk' is the function to call when
	 * the actor arrives
	 */
	inst.walkThen(cid, location, speed, 0, arrived);
}

/*
 * Called when the actor arrives at his location
 */
function arrived() {

	local cid = inst.cids(ACTOR_CDEFID)[0];

	/* Determine if we want the actor to speak at all */

	if(randmodrng(0, 100) <= SPEAK_CHANCE) {
		/*
		 * Pick a random phrase to 'say'. As with the location, randmodrng is used. We also
		 * delay the speech by a second
		 */
		core.queue(function() {
			inst.creatureChat(cid, "s/", phrases[randmodrng(0, phrases.len())]);
		}, 1000);
	}

	/* Make the character perform an emote. We will perform the emote 4 times, once
	 * every 2000ms (2 seconds).
	 */
	
	inst.emote(cid, ANIMATION);
	core.queue(function() { inst.emote(cid, ANIMATION); }, 2000);
	core.queue(function() { inst.emote(cid, ANIMATION); }, 4000);
	core.queue(function() { inst.emote(cid, ANIMATION); }, 6000);
	core.queue(function() { inst.emote(cid, ANIMATION); }, 8000);
	 
	/*
	 * At 10 seconds, we move the actor on
	 */
	core.queue(moveSomewhere, 10000);
}

core.queue(moveSomewhere, 1000);
scriptlib/minerminig.1431198799.txt.gz · Last modified: 2015/05/09 20:13 by emerald