Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 02-17-2012, 03:13 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
Won't detect players touching NPC

I'm trying to script some sort of an event, and I'm having a little trouble. Basically, the point is not to get hit by the blocks randomly warping around the room. I've got that sorted. Now, I can't seem to get the NPC to detect if it's hit a player! Can somebody tell me what I'm doing wrong?

PHP Code:
function onCreated() {
  
setTimer(0.05);
  
setshape(1,32,32);
}

function 
onTimeout() {
  
  if (
this.on == 1) {
    
this.timer -= 1// Start the count down
    
this.random(3.5,57.5);
    
this.random(18,46);
   
    if (
player.x in this.xthis.this.width | && player.y in this.ythis.this.height|) {
      
player.chat "I've been hit!";
    }
  }
  
  if (
this.timer == 0) {
    
this.on 0// Stop warping
  
}
  
setTimer(0.05);

Edit
I think I've found my issue. It can't detect the players x and y co-ords server side? It worked when I created a new NPC and made it clientside. If I do this to my NPC, players won't be able to see the same X and Y of the block that other players see, and that's what I'm trying to do. Anybody got any ideas?

Just wondering if I could use a triggeraction to get around this. Would it be possible to send a triggeraction from the serverside to the clientside?

Edit
I've managed to put the movement and whatever clientside, and trigger the movement via the serverside using triggeraction. Now, I need help again trying to make the NPC detect if a player is in it's x and y.

PHP Code:
/*
Timer is the amount of time it takes
to warp around the room. The higher the
timer, the longer the warp session is.
*/
function onPlayerChats() {
  if (
player.guild != "Events Team") {
    return;
  }
  if (
player.chat == ":warp") {
    
triggeraction(31,33,"start",NULL);
  }
}

function 
onActionhit() {
  
player.chat "HAS BEEN HIT!";
}

//#CLIENTSIDE

const TIMER 25;

function 
onCreated() {
  
setTimer(0.05);
  
setshape(1,32,32);
  
this.height this.width 32;
}

function 
onTimeout() {
  
this.chat "Status:" SPC this.on;
  if (
this.on == 1) {
    
this.timer -= 1;
    
this.random(3.5,57.5);
    
this.random(18,46);
    if (
player.x in this.xthis.this.width | && player.y in this.ythis.this.height|) {
      
triggeraction(player.xplayer.y"hit"NULL);
    }
  }
  if (
this.timer == 0) {
    
this.on 0;
    
this.31;
    
this.33;
  }
  
setTimer(0.05);
}

function 
onActionstart() {
  
this.on 1;
  
this.timer TIMER;

__________________

Last edited by Emera; 02-17-2012 at 04:11 PM..
Reply With Quote
  #2  
Old 02-17-2012, 04:06 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
First off: you don't even have a player scope in that timeout. You will have to loop through all players and check them all. Also, this.width and this.height are set by setShape() already, I believe, and even if they aren't, they're way off. You want them in tiles, not pixels.
Reply With Quote
  #3  
Old 02-17-2012, 04:09 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 Crow View Post
First off: you don't even have a player scope in that timeout. You will have to loop through all players and check them all. Also, this.width and this.height are set by setShape() already, I believe, and even if they aren't, they're way off. You want them in tiles, not pixels.
I think I get what you mean by looping through the players, and I had a hunch that the setShape() set the width and height, but wasn't sure so I dumped the height and width check just for good measure. Also, how would I detect the tiles instead of pixels?
__________________
Reply With Quote
  #4  
Old 02-17-2012, 04:15 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
Also, how would I detect the tiles instead of pixels?
I was just saying that your width/height should be 2 instead of 32, since you already are checking for tile coordinates.
Reply With Quote
  #5  
Old 02-17-2012, 04:18 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 Crow View Post
I was just saying that your width/height should be 2 instead of 32, since you already are checking for tile coordinates.
So, are you saying I should use setShape(1,2,2);?
Don't think that's what you're saying since I tried that and it didn't work.
__________________
Reply With Quote
  #6  
Old 02-17-2012, 06:26 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Emera View Post
So, are you saying I should use setShape(1,2,2);?
Don't think that's what you're saying since I tried that and it didn't work.
No But this line:
PHP Code:
if (player.x in this.xthis.this.width | && player.y in this.ythis.this.height|) { 
Doesn't make sense if you have width/height as 32, which you did.
Reply With Quote
  #7  
Old 02-17-2012, 06:32 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 Crow View Post
No But this line:
PHP Code:
if (player.x in this.xthis.this.width | && player.y in this.ythis.this.height|) { 
Doesn't make sense if you have width/height as 32, which you did.
Finally fixed this :P Thanks for your help crow (+rep)
PHP Code:
/*
Timer is the amount of time it takes
to warp around the room. The higher the
timer, the longer the warp session is.
*/
function onPlayerChats() {
  if (
player.guild != "Events Team") {
    return;
  }

  if (
player.chat == ":warp") {
    
triggeraction(this.x,this.y,"start",NULL);
  }
}

//#CLIENTSIDE

const TIMER 50;

function 
onCreated() {
  
setTimer(0.05);
  
setshape(1,32,32);
  
dontblock();
  
this.ox this.x;
  
this.oy this.y;
}

function 
onTimeout() {
  if (
this.on == 1) {
    
this.timer -= 1;
    
this.random(3.5,57.5);
    
this.random(18,46);
    if (
player.x in this.1this.| && player.y in this.1this.|) {
      
player.30;
      
player.7;
    }
  }
  if (
this.timer == 0) {
    
this.on 0;
    
// Set back to original positions.
    
this.this.ox;
    
this.this.oy;
  }
  
setTimer(0.05);
}

function 
onActionstart() {
  
this.on 1;
  
this.timer TIMER;

__________________

Last edited by Emera; 02-17-2012 at 08:50 PM..
Reply With Quote
  #8  
Old 02-17-2012, 08:47 PM
ffcmike ffcmike is offline
Banned
Join Date: Jul 2004
Location: London
Posts: 2,029
ffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond reputeffcmike has a reputation beyond repute
Send a message via AIM to ffcmike Send a message via MSN to ffcmike
While setshape parameters are in pixels, npc.width and .height are actually in tiles. So Emera had this part right, maybe with the exception of checking player.x and player.y, those being the top left of the player rather than the center - player.x + 1.5 and player.y + 2.

I don't think having the NPC move clientside is a good solution, as everybody will see it differently on their own client, so you won't be able to see others get hit before they're eliminated. The event would probably be more fun if the NPC moved serverside via the move() function at high speeds, you could then check for an intersect in the clientside portion of the script in a timeout.
Reply With Quote
  #9  
Old 02-17-2012, 09:04 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by ffcmike View Post
While setshape parameters are in pixels, npc.width and .height are actually in tiles. So Emera had this part right, maybe with the exception of checking player.x and player.y, those being the top left of the player rather than the center - player.x + 1.5 and player.y + 2.
I know it usually does this, but he had set width and height to 32 manually in his first code snippet. Not even sure how the NPC reacts to that or if that's even possible though.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 08:23 PM.


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