Graal Forums

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

Gunderak 12-17-2012 03:02 PM

Selecting Players
 
Hey, I've made a script to select players with your mouse, by clicking down and dragging, but when it comes time to check what players have been selected it's probably not the most efficient way to do it.
Also yes I know the multiple with(findimg(blah)){ is probably bad, but I don't want just one filled in square, I want four lines and the center to be clear.
Anyway here's my script.
PHP Code:

//#CLIENTSIDE
function onCreated(){
  const 
xoffset = -0.4;
  const 
yoffset = -0.4;
}
function 
onMouseDown(){
  if(
client.oeOpen){
    return;
  }
  
this.drawing true;
  
this.startx mousex xoffset;
  
this.starty mousey yoffset;
  
onTimeout();
  
}
function 
onMouseUp(){
  if(
client.oeOpen){
    return;
  }
  
this.drawing false;
  
GetPlayers();
}
function 
onTimeout(){
  if(
this.drawing){
    
this.endx mousex xoffset;
    
this.endy mousey yoffset;
    
temp.sx this.startx;
    
temp.sy this.starty;
    
temp.ex this.endx;
    
temp.ey this.endy;
    
with(findimg(250)){
      
polygon = {
        
sxsy,
        
exsy,
      };
      
red green blue 1;
      
alpha 0.5;
    }
    
with(findimg(251)){
      
polygon = {
        
exsy,
        
exey,
      };
      
red green blue 1;
      
alpha 0.5;
    }
    
with(findimg(252)){
      
polygon = {
        
exey,
        
sxey,
      };
      
red green blue 1;
      
alpha 0.5;
    }
    
with(findimg(253)){
      
polygon = {
        
sxey,
        
sxsy
      
};
      
red green blue 1;
      
alpha 0.5;
    }
    
settimer(0.05);
  }else{
    
hideimgs(250253);
  }
}
function 
GetPlayers(){
  
this.plyrs null;
  
this.plyrsnames null;
  for(
temp.players){
    
//The part where it could probably be simplified a lot.
    
if(p.x in this.startxthis.endx |){
      if(
p.y in this.startythis.endy |){
        
this.plyrs.add(p);
      }
    }
    if(
p.x in this.endxthis.startx |){
      if(
p.y in this.endythis.starty |){
        
this.plyrs.add(p);
      }
    }
    if(
p.x in this.startxthis.endx |){
      if(
p.y in this.endythis.starty |){
        
this.plyrs.add(p);
      }
    }
    if(
p.x in this.endxthis.startx |){
      if(
p.y in this.startythis.endy |){
        
this.plyrs.add(p);
      }
    }
  }
  if(
this.plyrs != null){
    for(
temp.pn this.plyrs){
      
this.plyrsnames.add(pn.nick);
    }
    
player.chat "Players selected: "@this.plyrsnames;
  }else{
    
player.chat "No players selected.";
  }


Iv'e tried just doing one check for the player from startx, starty, endx, endy. But that only works if you click and drag from top left to bottom right, any other corners you start from won't. I guess that's the issue.

0PiX0 12-17-2012 04:50 PM

To be able to drag from any direction, you can assign the start values to be the lower values, and the end values to be the higher values. Once you do that you can simplify your checks inside your loop.


All times are GMT +2. The time now is 10:06 PM.

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