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 05-30-2014, 06:20 PM
i8bit i8bit is offline
Registered User
Join Date: Jul 2013
Posts: 146
i8bit is an unknown quantity at this point
Finding players in Z range

PHP Code:
  triggeraction(player.1.5 vecx(player.dir) * 1.5player.vecy(player.dir) * 1.5"Lighthurt"player.dmg); 
How do I also do a check to make sure the player in front is within a certain z-range?
Reply With Quote
  #2  
Old 05-30-2014, 07:35 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
You can use vectorDist()

PHP Code:
vectorDist(
  {
player.xplayer.yplayer.y},
  {
obj.xobj.yobj.z}
); 
Checks the distance from one object to another based on the x, y and z properties of both objects. Failing that, you can use a distance formula (search the forums).
Reply With Quote
  #3  
Old 05-30-2014, 07:50 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 Emera View Post
[...]
I'm sure he ment how to find players within a certain range, not how to get the range. You could do that the following way using findNearestPlayers():

PHP Code:
function attackPlayers(from_xfrom_ydistance_max) {
  for (
temp.plfindNearestPlayers(temp.from_xtemp.from_y) {
    
temp.dx temp.pl.temp.from_x;
    
temp.dy temp.pl.temp.from_y;
    
    
temp.distance = (dx^dy^2) ^ 0.5//calculate distance
    
echo("Distance to " temp.pl.account ": " temp.distance);

    if (
temp.distance temp.distance_max) continue; //ignore players that are further away than you want them to be
    //do stuff to the players within the given range
  
}

__________________
MEEP!
Reply With Quote
  #4  
Old 05-30-2014, 08:17 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 callimuc View Post
I'm sure he ment how to find players within a certain range, not how to get the range. You could do that the following way using findNearestPlayers():

PHP Code:
function attackPlayers(from_xfrom_ydistance_max) {
  for (
temp.plfindNearestPlayers(temp.from_xtemp.from_y) {
    
temp.dx temp.pl.temp.from_x;
    
temp.dy temp.pl.temp.from_y;
    
    
temp.distance = (dx^dy^2) ^ 0.5//calculate distance
    
echo("Distance to " temp.pl.account ": " temp.distance);

    if (
temp.distance temp.distance_max) continue; //ignore players that are further away than you want them to be
    //do stuff to the players within the given range
  
}


I may be doing it wrong.. but the way I did it seems so much simpler...

in the action-
PHP Code:
  triggeraction(player.1.5 vecx(player.dir) * 4player.vecy(player.dir) * 4"Lighthurt"player.dmgplayer.z+3player.z-3); 
in the hurt function-
PHP Code:
if (player.params[1]){
if (
player.params[2]){ 
Reply With Quote
  #5  
Old 05-30-2014, 10: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
Ah I now get it. You'd need to make a player class (like a health class) to check what the players z value is (inside the onActionLighthurt()) and control any further stuff from there on.

PHP Code:
function onActionLighthurt() {
  if (
player.z in |-33|) { //players Z value goes from -3 to 3
    //same as if (player.z >= -3 && player.z <= 3)
    //Do your stuff inside here
    
player.chat "'eyy";
  }

for the triggerAction() you'd only need to do triggeraction(player.x + 1.5 + vecx(player.dir) * 4, player.y + 2 + vecy(player.dir) * 4, "Lighthurt", player.dmg); now
__________________
MEEP!
Reply With Quote
  #6  
Old 05-31-2014, 12:35 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 callimuc View Post
Ah I now get it. You'd need to make a player class (like a health class) to check what the players z value is (inside the onActionLighthurt()) and control any further stuff from there on.

PHP Code:
function onActionLighthurt() {
  if (
player.z in |-33|) { //players Z value goes from -3 to 3
    //same as if (player.z >= -3 && player.z <= 3)
    //Do your stuff inside here
    
player.chat "'eyy";
  }

for the triggerAction() you'd only need to do triggeraction(player.x + 1.5 + vecx(player.dir) * 4, player.y + 2 + vecy(player.dir) * 4, "Lighthurt", player.dmg); now
Thanks for input!

I have a little side question though. How do I change the player's location on the screen?

For example, if I want the player a little further down the screen instead of centered?
Is this possible?
Reply With Quote
  #7  
Old 05-31-2014, 02:52 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
Quote:
Originally Posted by i8bit View Post
For example, if I want the player a little further down the screen instead of centered?
Is this possible?
Take a look at:
resetfocus();
and
setfocus(x, y);
__________________
http://i.imgur.com/OOJbW.jpg
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 11:01 AM.


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