Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   NPC collision (https://forums.graalonline.com/forums/showthread.php?t=134264359)

blackbeltben 08-25-2011 02:43 PM

NPC collision
 
You can make an NPC that has a function for onPlayerTouchsMe() and so on will happen.

But can you make a NPC have the same thing happen for an onPlayerTouchsMe().

An NPC touching another NPC.
I'm using for a baddie.

Twinny 08-25-2011 02:54 PM

Currently no. You'll need to write your own collision detection. I don't think it would be very feasible getting an event added for NPC touching NPC

ffcmike 08-25-2011 04:59 PM

Quote:

Originally Posted by blackbeltben (Post 1665328)
You can make an NPC that has a function for onPlayerTouchsMe() and so on will happen.

But can you make a NPC have the same thing happen for an onPlayerTouchsMe().

An NPC touching another NPC.
I'm using for a baddie.

After moving the NPC, you can do something such as:

PHP Code:

function doTouchTrigger(){
  
temp.pixel 16;
  
temp.halfpixel 32;
  if(
this.dir == 1){
    
temp.this.0.75 temp.halfpixel + (vecx(this.dir) * (0.75 temp.halfpixel));
    
temp.this.1;
    
temp.temp.pixel;
    
temp.2;
  }
  else{
    
temp.this.0.5;
    
temp.this.1.25 temp.halfpixel + (vecy(this.dir) * (0.75 temp.halfpixel));
    
temp.2;
    
temp.temp.pixel;
  }
  
  
temp.tnpcs findareanpcs(temp.xtemp.ytemp.wtemp.h);
  
//I'm not sure if findareanpcs(); filters out npcs which call the function
  
temp.tnpcs.remove(this);
  for(
temp.temp.tnpcs){
    
temp.n.trigger("NPCTouchsMe"this);
  }
}

//Will result in
function onNPCTouchsMe(temp.n){
  
this.chat "I was touched by the NPC at " temp.n.", " temp.n.y;


These coordinates are based on showcharacter npcs.

Tricxta 08-25-2011 11:30 PM

Could always place a constant firing triggeraction in front of the npc:
PHP Code:

triggeractionplayerx.+1.5+(vecx(player.dir)), player.y+2+(vecy(player.dir)), "npctouchedme"NULL); 

Then in the receiving npc just find out when the triggeraction is called and your rolling. Im only suggesting this because Thors method is a bit daunting for some people. So unless you understand what his done theres always a second more easier to understand approach. Its just a bit less stable lol.

It might not be the most elegant solution but it sure is straight forward ;)

DustyPorViva 08-25-2011 11:43 PM

Quote:

Originally Posted by Tricxta (Post 1665473)
Could always place a constant firing triggeraction in front of the npc:
PHP Code:

triggeractionplayerx.+1.5+(vecx(player.dir)), player.y+2+(vecy(player.dir)), "npctouchedme"NULL); 

Then in the receiving npc just find out when the triggeraction is called and your rolling. Im only suggesting this because Thors method is a bit daunting for some people. So unless you understand what his done theres always a second more easier to understand approach. Its just a bit less stable lol.

It might not be the most elegant solution but it sure is straight forward ;)

Not only is it not elegant but running triggeraction loops is horribly inefficient and taxing on the server.

NPCs, if given a shape(via setshape() or showcharacter()) are considered walls via onwall(). Instead, he could check for walls and only when they collide with a wall, check for an NPC in front of them... if you want to do something simple. However, this requires NPCs to block which may not be desired, and will end up emulating almost exactly what Thor is doing anyways... he could fall back on triggeraction when it hits a wall but I don't like to recommend triggeraction.

Tricxta 08-26-2011 05:00 AM

Quote:

Originally Posted by DustyPorViva (Post 1665478)
Not only is it not elegant but running triggeraction loops is horribly inefficient and taxing on the server.

NPCs, if given a shape(via setshape() or showcharacter()) are considered walls via onwall(). Instead, he could check for walls and only when they collide with a wall, check for an NPC in front of them... if you want to do something simple. However, this requires NPCs to block which may not be desired, and will end up emulating almost exactly what Thor is doing anyways... he could fall back on triggeraction when it hits a wall but I don't like to recommend triggeraction.

Good point... I had in mind it only being used a cheats way to make things work with the average npc character though, but yes... I was wrong to suggest such a horrid solution :(


All times are GMT +2. The time now is 11:41 PM.

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