Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Question involving custom damage scripts. (https://forums.graalonline.com/forums/showthread.php?t=134258619)

Jiroxys7 04-02-2010 07:22 AM

Question involving custom damage scripts.
 
Okay, so I have a weapon that uses triggeraction and whatnot clientside, but in my class, where it calculates the damage to be taken, its only using the variables of the person hit. What kind of function or w/e would I use to find the variable of another player? findplayer? and how would i go about telling it what player to find?

Switch 04-02-2010 07:38 AM

findplayer(str) - returns object
findplayerbycommunityname(str) - returns object
findplayerbyid(int) - returns object
You'd need to use testplayer(x, y) or something similar to see which player you want to get. testplayer() returns an integer so you'd need to use findplayerbyid() if you want to use it.

DrakilorP2P 04-02-2010 03:46 PM

Send the attacker as a parameter with the triggeraction?

fowlplay4 04-02-2010 04:22 PM

Quote:

Originally Posted by DrakilorP2P (Post 1566679)
Send the attacker as a parameter with the triggeraction?

Ideal way to do it, testplayer is a jerk and doesn't play nice around NPC decorations.

In your melee weapon system:

triggeraction(x, y, "damage", damageAmount, player.account);

Then in your damage system that catches the damage triggers:

PHP Code:

//#CLIENTSIDE

function onActionDamage(damage, attacker) {
  
// Find attacker
  
temp.obj = findplayer(attacker);
  
// Check if in same guild (Example)
  
if (temp.obj.guild == player.guild && player.guild.length() > 0) return;
  
// Other damage system code
} 

It's important to note that you won't be able to access other player's client/clientr variables on the clientside, so you'll have to process those checks on the serverside.

cbk1994 04-02-2010 08:40 PM

Usually it's best to just send the account of the attacker and the weapon they're using if you're using a clientside melee system since they can change the damage to whatever they want. For example,

PHP Code:

function onActionServerSide(cmd, account, weapon) {
  if (
cmd == "attack") {
    
temp.pl = findPlayer(account);
    if (
pl == null) {
      return; 
// attacker is offline
    
}
    if (! 
pl.hasWeapon(weapon)) { // replace this to match your server's item/weapon structure
      
return; // they don't have the weapon
    
}
    
    
temp.damage = DB_Damage.getDamage(weapon);
    
player.hit(damage);
  }
}

//#CLIENTSIDE
function onActionPlayerHit(account, weapon) {
  
triggerServer("gui", this.name, "attack", account, weapon);
} 


Jiroxys7 06-03-2010 01:11 AM

urg. i tried this today. i cant even get it to to hit the player that has it. !pissed!
What am i doing wrong in this?

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
setTimer(0.05);
}

function 
onTimeout(){
  
triggeraction(player.x, player.y, "Test");
  
setTimer(0.05);
}

function 
onActionTest(){
  
player.chat = "It works!";
} 


ffcmike 06-03-2010 01:18 AM

Quote:

Originally Posted by Jiroxys7 (Post 1579954)
urg. i tried this today. i cant even get it to to hit the player that has it. !pissed!
What am i doing wrong in this?

PHP Code:

//#CLIENTSIDE
function onCreated(){
  
setTimer(0.05);
}

function 
onTimeout(){
  
triggeraction(player.x, player.y, "Test");
  
setTimer(0.05);
}

function 
onActionTest(){
  
player.chat = "It works!";
} 


The Triggeraction function requires an extra Parameter even if you do not intend one to be sent (so just use "" or NULL), this is also intended to be something received by other players on the given coordinate, not sure if it can be picked up by yourself.

Also probably not the best idea to be doing this on a constant timeout beyond testing.

Jiroxys7 06-03-2010 01:25 AM

Yeah the timeout is purely for testing. I'll try your suggestion.

adam 06-03-2010 02:51 AM

Also, I don't think it'll work at the players x,y because that location doesn't actually touch a player. Try x+1.5, y+1.5

Cubical 06-03-2010 03:24 AM

I don't know what exactly you're trying to do but I think this might be it
PHP Code:

function onActionServerside(hitx,hity){
  for (
temp.pl: findNearestPlayers(hitx,hity)){
    
temp.playercenter = {temp.pl.x + 1.5, temp.pl.y + 2};
      if (
hitx in |temp.playercenter[0]-1.5, temp.playercenter[0]+1.5|){
       if (
hity in |temp.playercenter[1]-1.5, temp.playercenter[1]+1.5){
        
//do damage
      
}
    }
  }
} 

Also, I'm assuming if he is doing something that would cause damage that the player would be either in the 8 surrounding levels so findNearestPlayers would be best in my opinion rather than findplayer as everyone else was saying. If I'm wrong then correct me but that's what I have always just assumed.


All times are GMT +2. The time now is 01:15 AM.

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