Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #31  
Old 01-12-2014, 05:44 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
I have everything working the way I want, but I am trying to do a check in the CLASS script to check if the baddie is a certain type.

PHP Code:
  for (temp.npc findAreaNPCs(this.xthis.y44)) {
   if (
temp.npc.baddietype == "normal"){
    
temp.npc.trigger("Hurt");
  }
 } 
What is line 2 suppose to look like to check if the baddietype == "normal"??
Reply With Quote
  #32  
Old 01-12-2014, 07:27 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by i8bit View Post
I have everything working the way I want, but I am trying to do a check in the CLASS script to check if the baddie is a certain type.

PHP Code:
  for (temp.npc findAreaNPCs(this.xthis.y44)) {
   if (
temp.npc.baddietype == "normal"){
    
temp.npc.trigger("Hurt");
  }
 } 
What is line 2 suppose to look like to check if the baddietype == "normal"??
It's fine if you're setting this.baddietype = "normal"; serverside in all the baddie NPCs you want to get hurt.
__________________
Reply With Quote
  #33  
Old 01-13-2014, 06:24 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
It's fine if you're setting this.baddietype = "normal"; serverside in all the baddie NPCs you want to get hurt.
I am, but it's not triggering the function for some reason...
Reply With Quote
  #34  
Old 01-13-2014, 07:21 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by i8bit View Post
I am, but it's not triggering the function for some reason...
Post the code that's handling the triggers.

Have you tried debugging to see where the problem is? Add echoes to the for loop to see what NPCs it's finding, and another inside the if-statement to see if the right NPCs are being considered baddies. If you haven't already, add echoes in the trigger receiving function to see if it's received at all. Add echoes before the for-loop to see if it's even being reached. When you do this it will become clear where the problem is (e.g. is the problem finding NPCs? is it identifying the right NPCs? is it triggering the NPCs?). You can't have too many echoes when debugging.
__________________
Reply With Quote
  #35  
Old 01-13-2014, 09:18 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Originally Posted by cbk1994 View Post
Post the code that's handling the triggers.

Have you tried debugging to see where the problem is? Add echoes to the for loop to see what NPCs it's finding, and another inside the if-statement to see if the right NPCs are being considered baddies. If you haven't already, add echoes in the trigger receiving function to see if it's received at all. Add echoes before the for-loop to see if it's even being reached. When you do this it will become clear where the problem is (e.g. is the problem finding NPCs? is it identifying the right NPCs? is it triggering the NPCs?). You can't have too many echoes when debugging.
It was a dumb problem I overlooked. In the baddie's CLASS, I had
PHP Code:
baddietype "normal"
where I needed:
PHP Code:
this.baddietype "normal"
Reply With Quote
  #36  
Old 01-14-2014, 02:57 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Switching to Clientside

So after a lot of testing and what not, I have come to realize that my damage block system works, but not at the fast pace I am looking for.

Furthermore, I am going to switch to run my damage system all via CLIENTSIDE.

How would I trigger a clientside function in a weapon of another player?

PHP Code:
//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  if (
player.x in |this.x-2this.1| && player.y in |this.y-1this.3|) { 
   
//Trigger Clientside function in other player's "System/Health" weapon
   
}
  }

Can anyone fill in that line for me please?
It's also something I'd like to learn for the future.

Also, I'm not sure if my check is right to find players in front. If incorrect, please assist me there too.
Reply With Quote
  #37  
Old 01-14-2014, 04:49 AM
100Zero100 100Zero100 is offline
Registered User
Join Date: Jul 2006
Posts: 31
100Zero100 is on a distinguished road
Quote:
Originally Posted by i8bit View Post
So after a lot of testing and what not, I have come to realize that my damage block system works, but not at the fast pace I am looking for.

Furthermore, I am going to switch to run my damage system all via CLIENTSIDE.

How would I trigger a clientside function in a weapon of another player?

PHP Code:
//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  if (
player.x in |this.x-2this.1| && player.y in |this.y-1this.3|) { 
   
//Trigger Clientside function in other player's "System/Health" weapon
   
}
  }

Can anyone fill in that line for me please?
It's also something I'd like to learn for the future.

Also, I'm not sure if my check is right to find players in front. If incorrect, please assist me there too.
If you want to find a player *in front* you would use the vecx() and vecy() functions. vecx(player.dir) returns -1 for left, +1 for right, and 0 for up/down. Thus, doing player.x + vecx(player.dir) will aim 1 in front of the player either left or right, while doing player.y + vecy(player.dir) will aim 1 in front of player either up or down.

I am pretty sure Graal also allows you to triggerAction straight onto another player, something like

NPC Code:
triggerAction(player.x + vecx(..), player.y + vecy(..), "hit", "etc");



Assuming that's deprecated (I think it might be, or might require you to set a server option to allow it), then the first is the way to go.

In either scenario, once you get to the serverside with the player already planned, just triggerClient onto that player.

Something like this:

(in weapon NPC):
NPC Code:
function onActionServerside(act, acc) {
if (act == "hit") {
temp.pl = findplayer(acc);
temp.dist = ((player.x - pl.x) ^ 2 + (player.y - pl.y) ^ 2) ^ 0.5;
if (dist < 4) { // This check is just for general security, to make sure a lagger isn't just conquering people, or a hacker isn't hitting people from 500 miles away
pl.triggerClient("weapon", this.name, "hit", player.account);
}
}
}
//#CLIENTSIDE
function onKeyPressed(keycode, key) {
if (key == "s") { (you should consider using "if (keydown(5)) {" or whatever instead, in case the player wishes to change their 'default' sword key
// Some algorithmic stuff here to detect the hitbox that I'm not going to include, assume they are "pl"
if (other player in hitbox -- this is the stuff we've spoken about elsewhere) {
triggerServer("weapon", this.name, "hit", pl.account);
}
}
}
function onActionServerside(temp.act, temp.info) {
if (act == "hit") {
// Hit the player here
// "info" in this case would be the account of the player who landed the hit.
}
}



As for your "damage block" system that you complained isn't "fast paced" enough -- if you want fast pace, you need clientside hit detection. Make the "hurt" attack a clientsided function. If you're using graal default, that's "hitplayer()" -- if you aren't using Graal default, code in your own custom knockback. You can do something like finding out the angle between your player and the block, and then hitting your player back away from them using cos/sin. Set a temporary flag to give them immunity to re-hit (like the 'blinks' in default graal), and have the heart-removal happen clientside (even a clientr. flag can be set on the clientside, it just won't truly save until it's set on the serverside), and then trigger the heart update to the serverside. The server gets the info late -- but the client gets it immediately, and that keeps it feeling crisp.

For making the NPCs hit baddies, there are two main ways to do this:

1. Have the block (or baddy) repeatedly loop through npcs[] (or better, a smaller level.list of the relevant NPCs) and compare their x/y to the others' x/y to see if they are making contact.

2. Have the block (or baddy) doing testnpc() onto itself. If you setshape(1,1,1); right before you testnpc (and then re-setshape immediately after), the testnpc will miss the npc itself and allow it to detect another NPC under it. Then you can access that NPC by doing like npcs[testnpc()].

I'd go with #1 in this case. Don't loop over the entire npcs[], though. Make it so baddies save a level variable of their presence. So, for example, at the top of the baddies class:

(clientside)
NPC Code:
function onCreated() {
level.baddies.add(this);
}



Now, when the block wants to test if a baddy is inside of its coordinates, rather than doing:

NPC Code:
for (temp.npc: npcs) {
if (npc.isBaddie) {
// compare npc.x and npc.y to this.x and this.y
}
}



you would instead do:

NPC Code:
for (temp.baddie: level.baddies) {
// compare baddie.x and baddie.y to this.x and this.y
}



That is easier to read, easier to access and manipulate, and more efficient because you are no longer iterating pointlessly over a bunch of unrelated NPCs that have nothing to do with baddies.
Reply With Quote
  #38  
Old 01-15-2014, 04:34 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
I took what was read above into consideration. Thank you. But I am running all pvp actions via Clientside.

With that said, I am having issues and can't find out why this won't work.

This is the script for the weapon "Combat"
PHP Code:
//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  
setAni("sword"NULL)'
  if (player.x in |this.x-2, this.x + 1| && player.y in |this.y-1, this.y + 3|) {      
     triggerAction(player.x, player.y, "SYSTEM/damage", "Hurt");
     }
    }
   } 
And this is the weapon for my damage system:
PHP Code:
//#CLIENTSIDE
function onHurt(){
 
setAni("hurt"NULL);
 
player.chat "HURT!";
 } 

It's not triggering the function.

I know the x1,x2 and y1,y2 and a little outa wack. I'm just testing with the player.dir == 3
Reply With Quote
  #39  
Old 01-15-2014, 04:59 PM
Torankusu Torankusu is offline
Elite Member
Torankusu's Avatar
Join Date: Jun 2001
Posts: 10,065
Torankusu is a jewel in the roughTorankusu is a jewel in the rough
Quote:
Originally Posted by i8bit View Post
I took what was read above into consideration. Thank you. But I am running all pvp actions via Clientside.

With that said, I am having issues and can't find out why this won't work.

This is the script for the weapon "Combat"
PHP Code:
//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "s"){
  
setAni("sword"NULL)'
  if (player.x in |this.x-2, this.x + 1| && player.y in |this.y-1, this.y + 3|) {      
     triggerAction(player.x, player.y, "SYSTEM/damage", "Hurt");
     }
    }
   } 
And this is the weapon for my damage system:
PHP Code:
//#CLIENTSIDE
function onHurt(){
 
setAni("hurt"NULL);
 
player.chat "HURT!";
 } 

It's not triggering the function.

I know the x1,x2 and y1,y2 and a little outa wack. I'm just testing with the player.dir == 3
The problem is largely going to be in your condition. Not to mention the snippet you gave us does not have a ; after setani().

Think about this.x and this.y also: this. Refers to the weapon as the object. Probably not something you are going to want to do in this instance..

And player.x and player.x refers specifically the top left of the player.

The way this is set up it almost seems as if you want to hurt yourself, which might be fine for testing, but you can put the same onHurt function in a class and join it to an npc that looks like a player character as well to test animations.

While you're still early in the script i'd read up on vecx and vecy because it will come in handy for determining a position in front of a player.

Here is a thread explaining it: http://forums.graalonline.com/forums...47#post1649547

Also, here is an old example using a mining system that might help you set up better testing procedures (the triggers and receiving of them can be applied to a combat system)
http://forums.graalonline.com/forums...ad.php?t=68273
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 03:22 PM.


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