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
  #1  
Old 01-04-2014, 02:08 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
NPC checking for player

As you all know, the onPlayerTouchsMe() only works if the player runs into the NPC.

How would I script the NPC to check if the player is in the x, y of the object.
In this case, block.png

PHP Code:
function onCreated(){
 
setImg("block.png");
 
setTimer(1);
}

function 
onTimeOut(){
 
destroy();
}

function 
onPlayerTouchsMe(){
 
player.chat "HIT";

Reply With Quote
  #2  
Old 01-04-2014, 04:34 PM
Starfire2001 Starfire2001 is offline
Unholy Nation
Starfire2001's Avatar
Join Date: Dec 2010
Location: The streets.
Posts: 156
Starfire2001 will become famous soon enough
You need continuously to check the players position in a loop to see if they are within the bounds of the block. If you are looking to do it clientside...

PHP Code:
//#CLIENTSIDE
function onCreated() {
  
setImg("block.png");
  
onTimeout();  // probably better than setting a timer here as you might not want to wait a second before checking
}

function 
onTimeout() {
  
// assuming that your block's dimensions are 2x2
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) {
    
//destroy or hide the block or whatever you want to do
  
} else {
    
setTimer(.05); // or higher if it doesn't need to be so accurate
  
}

If you want to do it serverside you'll have to loop through the players array in your timeout and check if any of them are within the bounds of the block.
__________________
-Ph8
Reply With Quote
  #3  
Old 01-04-2014, 10: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 Starfire2001 View Post
PHP Code:
  // assuming that your block's dimensions are 2x2
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
Just a note that you can use this.width and this.height to get the width/height of an NPC with a defined shape (like an image).
__________________
Reply With Quote
  #4  
Old 01-05-2014, 01:51 AM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by cbk1994 View Post
Just a note that you can use this.width and this.height to get the width/height of an NPC with a defined shape (like an image).
changing the image though (like a 1x1 pixel one) will also alter this.width/height clientside though, that way players would be able to cheat through blocks
__________________
MEEP!
Reply With Quote
  #5  
Old 01-05-2014, 02:13 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 callimuc View Post
changing the image though (like a 1x1 pixel one) will also alter this.width/height clientside though, that way players would be able to cheat through blocks
If you're worried about cheating players, then you can't trust anything that happens clientside. You're right that that would be one of the easier ways to cheat, though.
__________________
Reply With Quote
  #6  
Old 01-05-2014, 03:12 AM
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
don't want to seem like i'm giving advice, because I am not, and I also don't know what the OP. wants to do with this, since it's so vague and there might be a better approach, but here's something i came up with on a serverside approach to at least give an array of players in that object's coordinates.

Quote:
Originally Posted by Using...
TServerLevel.findareaplayers(float, float, float, float) - returns object - returns an array of all players in the specified rectangle (x,y,width,height), uses the blocking rectangle of players (0.5,1,2,2) instead of (0,0)
PHP Code:
// Created by Torankusu

function onCreated()
{
  
setshape(1,32,32);
  
this.image "block.png";
  
drawunderplayer();
  
dontblock();
  
setTimer(0.1);
}

function 
onTimeout()
{
  
temp.pls this.level.findareaplayers(this.x,this.y,2,2);
  
this.chat temp.pls;
  
setTimer(0.1);

the object's chat in this example will display the array of players that are in the x,y of that object.
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #7  
Old 01-05-2014, 03:15 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
don't want to seem like i'm giving advice, because I am not, and I also don't know what the OP. wants to do with this, since it's so vague and there might be a better approach, but here's something i came up with on a serverside approach to at least give an array of players in that object's coordinates.
I am trying to make "damage blocks" so when the player collides with them, player.clientr.hp is deducted. That's why I want to go serverside. I can see where I was unclear by making the player chat in the end result. I should have been more specific.
Reply With Quote
  #8  
Old 01-05-2014, 04:26 PM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Quote:
Originally Posted by i8bit View Post
I am trying to make "damage blocks" so when the player collides with them, player.clientr.hp is deducted. That's why I want to go serverside. I can see where I was unclear by making the player chat in the end result. I should have been more specific.
Just to make sure, you're not using onPlayerTouchsMe() because I'm guessing that both the damage block and the players will be moving?
__________________
Reply With Quote
  #9  
Old 01-05-2014, 06:44 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 Emera View Post
Just to make sure, you're not using onPlayerTouchsMe() because I'm guessing that both the damage block and the players will be moving?

Well if the player was at constant motion, the onPlayerTouchsMe() would not be a problem. But it's the players that are on idle that it won't work.
Reply With Quote
  #10  
Old 01-05-2014, 07:08 PM
Jakov_the_Jakovasaur Jakov_the_Jakovasaur is offline
Deleted by Darlene159
Jakov_the_Jakovasaur's Avatar
Join Date: Sep 2013
Location: Deleted by Darlene159
Posts: 360
Jakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud ofJakov_the_Jakovasaur has much to be proud of
you could always make a clientside system which triggers to serverside upon damage to reduce hp or handle deaths, youd just need to make sure that it works securely (such as preventing people who modify packets invoking negative damage aka increased health) and that theres a clientside health variable to give the illusion of real time damage

if you do this then it would be easy to have a single weapon system for checking all box intersects for every enemy, rather than scripting the box intersect checks in a timeout inside all of their scripts
__________________
This signature has been deleted by Darlene159.
Reply With Quote
  #11  
Old 01-05-2014, 11:21 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
you could always make a clientside system which triggers to serverside upon damage to reduce hp or handle deaths, youd just need to make sure that it works securely (such as preventing people who modify packets invoking negative damage aka increased health) and that theres a clientside health variable to give the illusion of real time damage
Think you could give me an example/scenario?
Reply With Quote
  #12  
Old 01-05-2014, 11:32 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
Think you could give me an example/scenario?
The simple solution is just take Starfire's code and modify it to send a trigger...

PHP Code:
//#CLIENTSIDE
function onCreated() { 
  
setImg("block.png"); 
  
onTimeout();  // probably better than setting a timer here as you might not want to wait a second before checking 


function 
onTimeout() { 
  
// assuming that your block's dimensions are 2x2 
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
    
triggerServer("npc""HealthSystem""hitByBlock");
    return 
setTimer(1); // to avoid sending 20 triggers per second
  
}
  
  
setTimer(.05); // or higher if it doesn't need to be so accurate 

and then in a DB NPC HealthSystem...

PHP Code:
function onActionServerSide(temp.cmd) {
  if (
temp.cmd == "hitByBlock") {
    echo(
player.niceName() @ " was hit by a block.");
    
player.hit(1); // or whatever
  
}

You could also send a point trigger (but those can be unreliable) or do this a bunch of other ways. There are some neat tricks you can use to do this more efficiently but I'd need to know more about what you're trying to do to know if they'd work here.

Note that the above makes it possible for cheating players to not be hit by the block, so if you care about that, you should do everything serverside.
__________________
Reply With Quote
  #13  
Old 01-06-2014, 12:47 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
So I took what you said, but modified it a bit

PHP Code:
//#CLIENTSIDE
function onCreated() { 
  
setImg("block.png"); 
  
onTimeout();  
 
scheduleEvent("onDestroy"1);


function 
onTimeout() { 
  if (
player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
    
triggerServer("weapon""HealthSystem""hitByBlock");
  }
  
  
setTimer(.05); 
}  

function 
onDestroy(){
 
destroy()

Then in the weapon- "HealthSystem"
PHP Code:
function onActionServerSide(){
 if (
params[0] == "hitByBlock"){
  [
PHP]player.clientr.hp -= //whatever amount
  
}
 } 
[/PHP]

I haven't had a chance to test this but I don't see why it wouldn't work

SO my next question is...
How would I check local NPCs (Baddies) to trigger their "Hurt" function with that block too?

I want my "damage block" to not only effect players but NPCs also.
Reply With Quote
  #14  
Old 01-06-2014, 05:30 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
Looks fine to me except you probably don't want to send 20 triggers per second.

Hurting NPCs should probably be done serverside:

PHP Code:
function hurtNPCs() {
  for (
temp.npc findAreaNPCs(this.xthis.y22)) {
    
temp.npc.trigger("hurt");
  }

then you can add an onHurt function in any NPCs which can be hurt.
__________________
Reply With Quote
  #15  
Old 01-06-2014, 07:25 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Quote:
Looks fine to me except you probably don't want to send 20 triggers per second.
Oh yeah, good observation. What if I don't make it loop and it just checks for players/NPCs in that 0.05 time range, triggers the actions, then destroys?
Reply With Quote
  #16  
Old 01-06-2014, 09:38 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
Oh yeah, good observation. What if I don't make it loop and it just checks for players/NPCs in that 0.05 time range, triggers the actions, then destroys?
Should work if you only want it to send the trigger once. Just call this.destroy(); after sending the trigger.
__________________
Reply With Quote
  #17  
Old 01-06-2014, 11:25 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
Should work if you only want it to send the trigger once. Just call this.destroy(); after sending the trigger.
So I ran into a little bit of issues. I discovered I need to destroy the block serverside. How would I trigger a serverside function in clientside?

I tried this in the clientside

PHP Code:
triggerserver("npc"this.name"destroy"
and this in the serverside..

PHP Code:
function onActionServerSide(){
 if (
params[0] == "destroy"){
  
destroy();
  }
 } 
it doesn't work so can you tell me what I'm doing wrong please?
Reply With Quote
  #18  
Old 01-07-2014, 11:31 AM
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
Is this in a class or level npc?

Also, are you going to be using this in a situation where the blocks appearance and location needs to be:
A.) The same for all players in the level
Or
B.) Can be different for all players in the level.

Some good suggestions previously listed here, but there are potentially a lot of ways to cheat this on the clientside as well.
__________________
Quote:
Originally posted by Spark910
Think befreo you type.
Reply With Quote
  #19  
Old 01-07-2014, 12:00 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 Torankusu View Post
Is this in a class or level npc?

Also, are you going to be using this in a situation where the blocks appearance and location needs to be:
A.) The same for all players in the level
Or
B.) Can be different for all players in the level.

Some good suggestions previously listed here, but there are potentially a lot of ways to cheat this on the clientside as well.
It is a class.
Reply With Quote
  #20  
Old 01-07-2014, 06:47 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
triggerserver() does not work inside level NPCs, you would need to use triggerAction() for this case
__________________
MEEP!
Reply With Quote
  #21  
Old 01-08-2014, 01:25 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
I still don't really know what you're doing so it's hard to give advice, but if your NPCs are created via putnpc2, they do have a name, and you can trigger them via triggerServer (but you have to get the name clientside; normally it isn't available). That might be the best approach.
__________________
Reply With Quote
  #22  
Old 01-08-2014, 03:36 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by callimuc View Post
triggerserver() does not work inside level NPCs, you would need to use triggerAction() for this case
Have to fix this statement, you can use triggerServer() inside level NPCs to trigger DB NPCs or weapons (and classes being joined to those). I figured this would be the best solution if you also want to receive the onActionServerSide() inside level NPCs (or NPCs created via putNPC2()) and classes being joined to those


Quote:
Originally Posted by cbk1994 View Post
You can also do

PHP Code:
function onCreated() {
  
this.level.tapThis this;
}

function 
onPow() {
  
this.chat "ouch!";
}

//#CLIENTSIDE
function onPlayerChats() {
  
triggerServer("npc""TriggerControl""Trigger"this.level.name"tapThis""Pow");

and then in an NPC TriggerControl

PHP Code:
function onActionTrigger(levelNamenpcNamecommand) {
  
findLevel(levelName).(@ npcName).trigger(command);

Though you'd want to add some security features. Usually something like this is preferable since you never know if a trigger will be received when using x/y.
__________________
MEEP!
Reply With Quote
  #23  
Old 01-08-2014, 04:13 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Allow me to clarify exactly what I'm doing.

When the player presses 'a', the player creates an NPC that I'm using as a damage block. The NPC is functional through joining a class.

Perhaps it'd be easier to explain if I did step by step what I'm doing, so I can get some better, more specific advice.

1. Player presses 'A' and creates the "damage block" NPC.
This is the code from the Weapon
PHP Code:
function onActionServerSide(){
if (
params[0] == "dmgblock"){
 
temp.npc this.level.putNPC2(player.xplayer.y"");
 
temp.npc.join("damageblock");
 }
}

//#CLIENTSIDE
function onKeyPressed(codekey){
 if (
key == "c"){
  
player.chat "Placed!";
   
triggerserver("weapon"this.name"dmgblock");
   }
  } 
I realize the placement with the x and y is off and the player will collide instantly within placing. Ignore that.

2. The NPC preforms it's function, then deletes
This is where I'm Having issues. I need the block to destroy serverside.
This is the script from the CLASS it joined

PHP Code:
function onActionServerside(){
 if (
params[0] == "destroy"){
  
destroy();
  }
  }

//#CLIENTSIDE
function onCreated(){
 
dontblock();
 
setImg("block.png");
 
onTimeOut();
 
scheduleEvent(1"onDestroy");
}


function 
onTimeOut(){
 if (
player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
 
player.chat "HIT";}
 
//Trigger Actions in the player to make him lose HP and Whatever else
 
setTimer(0.05);
}

function 
onDestroy(){
 
triggerAction("npc"this.name"destroy");

Reply With Quote
  #24  
Old 01-08-2014, 04:58 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Consider this example:
PHP Code:
function onCreated() {
  
setshape(1,32,32);
}
function 
onActionTest() {
  
this.chat random(0,100);
}

//#CLIENTSIDE

function onCreated() {
  
setTimer(0.05);
}
function 
onTimeout() {
  
triggeraction(this.x,this.y,"test");
  
setTimer(1);

__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #25  
Old 01-08-2014, 05:04 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Weapon script:
changed your this.level.putNPC2(...) to player.level.putNPC2(...), this. would refer to the weapon while player. refers to the player)

PHP Code:
function onActionServerSide(){
  if (
params[0] == "dmgblock"){
    
temp.npc player.level.putNPC2(player.xplayer.y""); //should be player.level instead of this.level
    
temp.npc.join("damageblock");
  }
}

//#CLIENTSIDE
function onKeyPressed(codekey){
  if (
key == "c"){
    
player.chat "Placed!";
    
triggerserver("weapon"this.name"dmgblock");
  }


Class script:
removed your dontBlock() as it needs to be a blocking NPC I believe
fixed your triggerAction()
and other stuff
PHP Code:
function onCreated() {
    
//1=blocking, 32=width in pixel, 32=height in pixel
  
setshape(13232);
}

function 
onActionDestroyBlock() {
  
this.destroy();
}

//#CLIENTSIDE
function onCreated() {
  
setshape(13232);
  
this.setImg("block.png");
  
onTimeOut();
}


function 
onTimeOut(){
    
//if player is within the square, trigger the actions
  
if (player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
    
player.chat "HIT";
      
//stop the script and call the 'onDestroyObject()' function
    
return onDestroyObject();
  }
    
//keep running the script as the player hasnt been inside the block range yet
  
setTimer(0.05);
}

function 
onDestroyObject() {
    
//x, y, onAction...., parameters
  
triggerAction(this.xthis.y"DestroyBlock"NULL);

__________________
MEEP!
Reply With Quote
  #26  
Old 01-08-2014, 05:21 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
[QUOTE=BlueMelon;1724944]Consider this example:


Thanks for the tip. Here's what I got

PHP Code:
function onCreated() {
  
setshape(1,32,32);
  
setImg("block.png");
}

function 
onActionTest(){
  
destroy();
  }

//#CLIENTSIDE
function onCreated(){
 
dontblock();
 
setTimer(1);
  if (
player.x in |this.xthis.2| && player.y in |this.ythis.2|) { 
  
player.chat "HIT";} 
}


function 
onTimeOut(){
 
triggeraction(this.x,this.y,"Test");


PROBLEM:
It sometimes works, and sometimes doesn't. It seems to only destroy half the time... Anything I can modify to make it more reliable?
Reply With Quote
  #27  
Old 01-08-2014, 06:30 PM
BlueMelon BlueMelon is offline
asdfg
BlueMelon's Avatar
Join Date: Sep 2008
Posts: 1,481
BlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to beholdBlueMelon is a splendid one to behold
Take a look at what you posted, and what callimuc and I have posted.

You are checking the collision when the npc is created. Meaning it is comparing the coordinates once... this is not what you want.
__________________
http://i.imgur.com/OOJbW.jpg
Reply With Quote
  #28  
Old 01-08-2014, 06:33 PM
callimuc callimuc is offline
callimuc's Avatar
Join Date: Nov 2010
Location: Germany
Posts: 1,015
callimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to beholdcallimuc is a splendid one to behold
Quote:
Originally Posted by i8bit View Post
PROBLEM:
It sometimes works, and sometimes doesn't. It seems to only destroy half the time... Anything I can modify to make it more reliable?
you need to put the players location check into the loop, check my example. else it will only work when the block is being placed but it never checks back again.
__________________
MEEP!
Reply With Quote
  #29  
Old 01-08-2014, 09:07 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
What they said
Plus, its also probably noteworthy to make sure you use setTimer (0.05 or however long...) in the onTimeout function to continue the loop -- you don't have it this way in your example.

Also, not necessary, but if you wanted to start the loop as immediately as it was created just call onTimeout (); in the on created function.

edit: sorry, missed it on my phone.
callimuc's example is spot on -- disregard my post if you follow his examples -- or just take them as an explanation for what he did. :]
__________________
Quote:
Originally posted by Spark910
Think befreo you type.

Last edited by Torankusu; 01-09-2014 at 02:02 AM..
Reply With Quote
  #30  
Old 01-09-2014, 04:36 AM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
I wanna thank everyone for all the advice! I have been really learning a lot!
So far I have it running correct with the tests I have put it through. But if I run in to any trouble I will be sure to add on to this thread with my questions.
Reply With Quote
  #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 01:47 AM.


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