PDA

View Full Version : npc spawning?


one_must_fall
08-06-2006, 05:19 PM
Hi i need help with a spawn npc script. I have the script already, but how do i make it so the npc spawns when i kill a certain person? the tutorial covers spawning an npc when you enter an area but it doesn't cover spawning when a certain person dies.

stoffe
08-06-2006, 05:34 PM
Hi i need help with a spawn npc script. I have the script already, but how do i make it so the npc spawns when i kill a certain person? the tutorial covers spawning an npc when you enter an area but it doesn't cover spawning when a certain person dies.

You could make the OnDeath event AI script of the killed NPC spawn the other NPC. As an example, this modified OnDeath AI script would spawn a new NPC (at coordinates 1.0, 1.0, 1.0) that attacks the killer whenever the NPC it is assigned to is killed:


void main() {
vector loc;
loc.x = 1.0; // x coordinate in world
loc.y = 1.0; // y coordinate in world
loc.z = 1.0; // z coordinate (elevation) in world

object oSpawned = CreateObject(OBJECT_TYPE_CREATURE, "NPCResRef", Location(loc, 0.0));
AssignCommand(oSpawned, ActionAttack(GetLastKiller()));

ExecuteScript("k_ai_master", OBJECT_SELF, 1007);
}

one_must_fall
08-06-2006, 06:18 PM
wait, that script would make the person i spawn attack me if i kill someone? well, i'm doing a recrutment mod, and i need to make it so if i kill the new member instead of letting him join me, atton spawns outside of the room, runs in and starts a conversation with me. I don't want atton to be a hostile, still a friendly.

stoffe
08-06-2006, 06:50 PM
wait, that script would make the person i spawn attack me if i kill someone? well, i'm doing a recrutment mod, and i need to make it so if i kill the new member instead of letting him join me, atton spawns outside of the room, runs in and starts a conversation with me. I don't want atton to be a hostile, still a friendly.

It was merely an example of how it could be used, since I didn't know anything about your particular case. :)

You can replace everything in that script except the last line with what you have in your own script. As long as you keep the last line in the script (the ExecuteScript() line) it should work properly. Then you assign the script to the OnDeath script field in the UTC file for the NPC who should get killed.