Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Adding exp once baddy killed (https://forums.graalonline.com/forums/showthread.php?t=134260550)

iSlayer 09-16-2010 04:50 AM

Adding exp once baddy killed
 
Well no matter how much I try I can't seem to get this script working! First the baddies join monster_base with their attributes set, then
PHP Code:

public function onNPCHit(itemIDdamagerangeattackereffectstypepos) {
  if(!
this.hit) {
    
this.hit true;

    
x// Stop movement

    
this.hp += damage;

    if(
this.hp <= 0) {
      
hide();
      
sleep(6);
      
show();
      
Respawn();
    }

    
this.hit false;
  }

  
ShowHP();


I've tried everything in this thread but have had no luck, can someone just post a simple script, not 3 or 4 scripts which will make my baddy work!

fowlplay4 09-16-2010 04:52 AM

Unless your damage is negative:

this.hp += damage;

should be

this.hp -= damage;

iSlayer 09-16-2010 04:57 AM

Ah yes well my damage wasn't being set through the triggers or something and dealing -1 so i used +=

fowlplay4 09-16-2010 05:09 AM

Well judging by your code you still let them hit the NPC for whatever reason so just do something like...

PHP Code:

public function onNPCHit(itemIDdamagerangeattackereffectstypepos) { 
  if (
this.dead) return;
  
this.hp += damage;
  
showHP();
  if (
this.hp <= 0) {
    
this.dead true;
    
hide();
    
sleep(6);
    
show();
    
respawn();
  }
}

function 
respawn() {
  
// your other code
  
this.dead false;



iSlayer 09-16-2010 06:20 AM

But how do I send the attacker param in the trigger? Talking about the sword and how do I get the baddy to add the exp to attacker

Edit: The damage system receives player.DoAttack and then triggers onNPCHit to the baddy

fowlplay4 09-16-2010 06:30 AM

pass player.account as a parameter then.

Here's a little example that might help you understand parameters a bit better.

PHP Code:

function onPlayerEnters() {
  
this.trigger("Example""random"12player.account36);
}

function 
onExample(abaccc) {
  echo(
a); // same as echo(params[0]);
  
echo(b); // same as echo(params[1]);
  
echo(acc); // same as echo(params[2]);
  
echo(c); // same as echo(params[3]);


When you get to the point where you have a working 'attacker' parameter you can then just do (assuming you have an EXP like the one I posted here)..

findplayer(attacker).addEXP(amount);


All times are GMT +2. The time now is 12:39 PM.

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