Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPCs triggering other NPCs (https://forums.graalonline.com/forums/showthread.php?t=134266630)

greggiles 06-12-2012 02:57 AM

NPCs triggering other NPCs
 
I'm trying to make a damage block instead of the player triggering the damage. But unfortunately I'm running into some issues.

How would I make this work to trigger other NPC's besides itself.

PHP Code:

function onActionServerside(temp.commandtemp.xtemp.y)
{
  switch(
temp.command){ 
    case 
"attack"
      
temp.tnpcs findareanpcs(temp.5temp.3106);   
      for(
temp.temp.tnpcs){   
        
temp.n.chat "Hit!";
  }
 }


Perhaps this question is badly worded and for that, I'm sorry forums.

cbk1994 06-12-2012 08:15 AM

I'm not quite sure what you're asking, but I think you mean that you're trying to trigger NPCs when they've been attacked.

Let's create a simple function for it..

PHP Code:

// put this in a class like func_damage so you can reuse it
function attackNPCs(temp.attackertemp.attackXtemp.attackYtemp.attackRadius) {
  for (
temp.npc findAreaNPCs(temp.attackX temp.attackRadiustemp.attackY temp.attackRadiustemp.attackRadius 2temp.attackRadius 2)) {
    
// you could do proper radius checking rather than a square with
    // length of 2*radius, but this is easier and generally sufficient for your needs
    
temp.npc.trigger("attack"temp.attacker); // tell the NPC it's been attacked
  
}


Now in any NPCs, you can do

PHP Code:

function onAttack(temp.attacker) {
  
this.chat "I was attacked by " temp.attacker.nick "!";


Then in your weapon, you can just do this:

PHP Code:

function onCreated() {
  
this.join("func_damage");
}

function 
onActionServerside(temp.commandtemp.xtemp.y

  switch(
temp.command){  
    case 
"attack":
      
this.attackNPCs(playertemp.xtemp.y1);
    break;
 } 



greggiles 06-12-2012 02:39 PM

So the first script is the Dmg block. Second is the baddie. third is the weapon. Got it~ THANK YOU


All times are GMT +2. The time now is 08:14 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.