Liberty Unleashed
Scripting => Script Snippets => Topic started by: Motley 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
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));
}
}
-
Isn't InPoly used to check whether someone is in a predefined polygon?
-
Yes, Why do you ask? Just curious.
-
What are you trying to do with your script?
-
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:
/* 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
-
Ah, nice job. I always used to check if they are within a predefined amount of distance of a vector.
-
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..
-
Version two:
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_+"); " );
}