Graal Forums  

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

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-17-2012, 03:02 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
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.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
 


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


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