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 = {
sx, sy,
ex, sy,
};
red = green = blue = 1;
alpha = 0.5;
}
with(findimg(251)){
polygon = {
ex, sy,
ex, ey,
};
red = green = blue = 1;
alpha = 0.5;
}
with(findimg(252)){
polygon = {
ex, ey,
sx, ey,
};
red = green = blue = 1;
alpha = 0.5;
}
with(findimg(253)){
polygon = {
sx, ey,
sx, sy
};
red = green = blue = 1;
alpha = 0.5;
}
settimer(0.05);
}else{
hideimgs(250, 253);
}
}
function GetPlayers(){
this.plyrs = null;
this.plyrsnames = null;
for(temp.p : players){
//The part where it could probably be simplified a lot.
if(p.x in | this.startx, this.endx |){
if(p.y in | this.starty, this.endy |){
this.plyrs.add(p);
}
}
if(p.x in | this.endx, this.startx |){
if(p.y in | this.endy, this.starty |){
this.plyrs.add(p);
}
}
if(p.x in | this.startx, this.endx |){
if(p.y in | this.endy, this.starty |){
this.plyrs.add(p);
}
}
if(p.x in | this.endx, this.startx |){
if(p.y in | this.starty, this.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.