Author Topic: Inpoly [Command]  (Read 2502 times)

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Inpoly [Command]
« on: November 14, 2016, 01:52:33 pm »
I never really seen any simple helpful commands for inpoly, So I created one to help me in the server.

This is not something that was intended to be really pretty, as well judged for its arrays, only really! useful.

I really hope this command helps others as it has with me, These commands have really saved me from a headache/ meltdown  ;D


Code: [Select]
x1 <- array(GetMaxPlayers(), 0);
y1 <- array(GetMaxPlayers(), 0);
x2 <- array(GetMaxPlayers(), 0);
y2 <- array(GetMaxPlayers(), 0);
x3 <- array(GetMaxPlayers(), 0);
y3 <- array(GetMaxPlayers(), 0);
x4 <- array(GetMaxPlayers(), 0);
y4 <- array(GetMaxPlayers(), 0);

function onPlayerCommand( player, cmd, text )
{
    if (cmd == "poly" )
    {
           if (text == "1")
           {
               x1[player.ID] = player.Pos.x;
               y1[player.ID] = player.Pos.y;
            }
       
            if (text == "2")
            {
                x2[player.ID] = player.Pos.x;
                y2[player.ID] = player.Pos.y;
            }

            if (text == "3")
            {
                 x3[player.ID] = player.Pos.x;
                 y3[player.ID] = player.Pos.y;
             }

             if (text == "4")
             {
                  x4[player.ID] = player.Pos.x;
                  y4[player.ID] = player.Pos.y;
             }
       
             if (text == "print")
             {
                 MessagePlayer("InPoly(player.Pos.x, player.Pos.y, "+x1[player.ID]+", "+y1[player.ID]+", "+x2[player.ID]+", "+y2[player.ID]+", "+x3[player.ID]+", "+y3[player.ID]+", "+x4[player.ID]+", "+y4[player.ID]+"); ", player, Colour(255, 255, 0));
                 print("InPoly(player.Pos.x, player.Pos.y, "+x1[player.ID]+", "+y1[player.ID]+", "+x2[player.ID]+", "+y2[player.ID]+", "+x3[player.ID]+", "+y3[player.ID]+", "+x4[player.ID]+", "+y4[player.ID]+"); " );
              }
       
              if ( text == "clear")
              {
                   x1[player.ID] = 0;
                   y1[player.ID] = 0;
                    x2[player.ID] = 0;
                    y2[player.ID] = 0;
                    x3[player.ID] = 0;
                    y3[player.ID] = 0;
                    x4[player.ID] = 0;
                    y4[player.ID] = 0;
        }
    }

    if (cmd == "help" )
    {
                MessagePlayer("/poly 1. pos.x1, pos.y1", player, Colour(255, 112, 0));
                MessagePlayer("/poly 2. pos.x2, pos.y2", player Colour(255, 112, 0));
                MessagePlayer("/poly 3. pos.x3, pos.y3", player Colour(255, 112, 0));
                MessagePlayer("/poly 4. pos.x4, pos.y4", player Colour(255, 112, 0));
MessagePlayer("/poly print. Message, print for stored poly", player Colour(255, 112, 0));       
                MessagePlayer("/poly clear.  Clears the arrays", player, Colour(255, 255, 0));
    }

}
« Last Edit: November 14, 2016, 01:57:25 pm by Mötley »

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: Inpoly [Command]
« Reply #1 on: November 14, 2016, 01:56:43 pm »
Isn't InPoly used to check whether someone is in a predefined polygon?

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Inpoly [Command]
« Reply #2 on: November 14, 2016, 01:58:11 pm »
Yes, Why do you ask? Just curious.

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: Inpoly [Command]
« Reply #3 on: November 14, 2016, 02:52:09 pm »
What are you trying to do with your script?

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Inpoly [Command]
« Reply #4 on: November 14, 2016, 04:06:55 pm »
It's funny that you ask  :)

Well, I have learned that when using CreateClientSphere  along with CreateSphere the sphere ids alter, affecting issues like showing a gui for for my gas script, This really alters the driving missions for the security car to much more. with adding this tiny validation the sphere IDs no longer get confused


Example:
Code: [Select]
/* anything that is not the fuel script */
if (!InPoly(player.Pos.x, player.Pos.y, 1136.8, -59.77, 1136.6, -98.87, 1184.9, -101.91, 1184.9, -59.7));

/* The fuel script */
if (InPoly(player.Pos.x, player.Pos.y, 1136.8, -59.77, 1136.6, -98.87, 1184.9, -101.91, 1184.9, -59.7));
Returns a great validation, I found that to be rather charming honestly.

This is really complicated to describe without showing you a entire mission script.
In general I find using InPoly a safe way of using spheres with client spheres while running the server.
Im also using it inside of the bank  :P

Maybe the garages as well


« Last Edit: November 14, 2016, 04:09:46 pm by Mötley »

JamesConway

  • Newbie
  • *
  • Posts: 39
  • Karma: +9/-3
    • View Profile
Re: Inpoly [Command]
« Reply #5 on: November 14, 2016, 04:51:41 pm »
Ah, nice job. I always used to check if they are within a predefined amount of distance of a vector. 

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Inpoly [Command]
« Reply #6 on: November 14, 2016, 04:56:56 pm »
Thats really interesting too, Something really told me to use inpoly.

I'm happy I did, Also happy due to that command,

Any other method for creating a poly like printing Pos.x, Pos.y multiple times is a nightmare

This way if used correctly you have something going on, I thought about adding a command to alter the players distance to forward, This way you could have stronger polys by having the exact distance and angle but,  ::) laziness  :D..

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Inpoly [Command]
« Reply #7 on: September 09, 2018, 08:05:33 pm »
Version two:

Code: [Select]
function onPlayerCommand( player, cmd, text )
{
    if (cmd == "cp" ) {
      if (text) {
        Create_Poly(player, text)
      }
    }
   
}
local x1_ = 0, y1_ = 0, x2_ = 0, y2_ = 0, x3_ = 0, y3_ = 0, x4_ = 0, y4_ = 0;

function Create_Poly(player, size) {

    x1_ = player.Pos.x, y1_ =  player.Pos.y, x2_ = player.Pos.x, y2_ = player.Pos.y, x3_ =  player.Pos.x, y3_ = player.Pos.y, x4_ =  player.Pos.x, y4_ =  player.Pos.y;
    size = size.tointeger()
    //North East
    x1_ += size;
    y1_ += size;

    // Display the positions on the radar
    CreateClientBlip(player, BLIP_NONE, Vector(x1_, y1_, -1));
   
    //South East
    x2_ += size;
    y2_ -= size;

    // Display the positions on the radar
    CreateClientBlip(player, BLIP_NONE, Vector(x2_, y2_, -1));

    // South West
    x3_ -= size;
    y3_ -= size;

    // Display the positions on the radar
    CreateClientBlip(player, BLIP_NONE, Vector(x3_, y3_, -1));

    // North West
    x4_ -= size;
    y4_ += size;

    // Display the positions on the radar
    CreateClientBlip(player, BLIP_NONE, Vector(x4_, y4_, -1));

    // Output the poly so it can be copied and pasted
    print("InPoly(player.Pos.x, player.Pos.y, "+x1_+", "+y1_+", "+x2_+", "+y2_+", "+x3_+", "+y3_+", "+x4_+", "+y4_+"); " );
}

 

© Liberty Unleashed Team.