Liberty Unleashed
Scripting => Script Releases => Topic started by: Pipec on August 28, 2014, 09:46:44 am
-
This script has been created by me in 2013. Script contain defined new zones in Portland.
You are free and welcome to use this script in any possible way as you wish.
Download/Copy:
COLOUR_WHITE <- Colour(255, 255, 255);
COLOUR_BLACK <- Colour(0, 0, 0);
g_GUI_ZONE <- null;
g_GUI_ZONEName <- null;
g_ZoneID <- -1;
g_T_Owner <- ["Bandito","Triad", "Bandito",
"Diablos","Ballas", "Ballas",
"Yakuza","Yakuza", "Yakuza",
"Triada","Triada", "Triada",
"Leone","Leone", "Leone",
"Banditos","Diablos", "Bandito",
"Bandito","Bandito", "Bandito",
"Diablos","Ballas", "Ballas"];
function SetZoneOwner(i, myData){ g_T_Owner[i] = myData; }
function onScriptLoad()
{
pPlayer <- FindLocalPlayer();
NewTimer("ZoneCheck", 1000,0);
g_GUI_ZONE = GUIWindow(VectorScreen(ScreenWidth/2-265, ScreenHeight/2-160),ScreenSize(301,50),"Current Zone of:");
g_GUI_ZONE.Visible = false;
g_GUI_ZONE.Colour = COLOUR_BLACK;
AddGUILayer( g_GUI_ZONE );
g_GUI_ZONEName = GUILabel( VectorScreen(5,1), ScreenSize(300,20 ), "......" );
g_GUI_ZONEName.TextColour = COLOUR_WHITE
g_GUI_ZONEName.FontSize = 12
g_GUI_ZONEName.FontName = "Arial";
g_GUI_ZONE.AddChild( g_GUI_ZONEName );
print("Zone script has been loaded");
}
function ZoneCheck()
{
local i=-1;
if(CheckDistance4D(1136.4, 1388.1, -332.2, -194.03)){ i=0; }
if(CheckDistance4D(1206.6, 1388.1, -517.1, -335.6)){ i=1; }
if(CheckDistance4D(1116.1, 1205.5, -193.63, -38.84)){ i=2; }
if(CheckDistance4D(1035.9, 1115.9, -233.71, -114.05)){ i=3; }
if(CheckDistance4D(901.1, 1034.6, -328.4, -109.31)){ i=4; }
if(CheckDistance4D(901, 1007.9, -108.84, 27.49)){ i=5; }
if(CheckDistance4D(763.0, 900.4, -284.0, -59.45)){ i=6; }
if(CheckDistance4D(764.8, 900.4, -444.3, -283.87)){ i=7; }
if(CheckDistance4D(901.3, 1011.2, -471.7, -329.3)){ i=8; }
if(CheckDistance4D(764.7, 901.2, -477.8, -444.2)){ i=9; }
if(CheckDistance4D(1011.5, 1068.4, -467.7, -234.46)){ i=10; }
if(CheckDistance4D(1113.4, 1205.8, -483.6, -334.3)){ i=11; }
if(CheckDistance4D(996, 1205.3, -517.4, -483.8)){ i=12; }
if(CheckDistance4D(765.3, 995.1, -640, -475.3)){ i=13; }
if(CheckDistance4D(995.2, 1086.9, -639.8, -606.3)){ i=14; }
if(CheckDistance4D(765.6, 1073.8, -778.8, -639.5)){ i=15; }
if(CheckDistance4D(765.2, 1071.3, -865.1, -779.1)){ i=16; }
if(CheckDistance4D(1079, 1141.1, -1049.8, -940)){ i=17; }
if(CheckDistance4D(1085.2, 1222.7, -1171.4, -1039.9)){ i=18; }
if(CheckDistance4D(939.5, 1084.9, -1157.7, -1050.1)){ i=19; }
if(CheckDistance4D(1223.7, 1355.2, -1185.8, -1001.7)){ i=20; }
if(CheckDistance4D(1357.7, 1540.4, -871.3, -766)){ i=21; }
if(CheckDistance4D(1357, 1549.8, -1040.7, -872.9)){ i=22; }
if(CheckDistance4D(1290.5, 1340, -804.5, -716.1)){ i=23; }
if(g_ZoneID != i){
onPlayerZoneChanged(g_ZoneID, i); }
g_ZoneID = i;
//Message("Zona:" + g_ZoneID);
return 1;
}
function onPlayerZoneChanged(OldID, NewID) //Its a Call back
{
if(NewID == -1){
g_GUI_ZONEName.Text = " ";
g_GUI_ZONE.Visible = false; } else {
g_GUI_ZONEName.Text = g_T_Owner[NewID] + " gang";
g_GUI_ZONE.Visible = true; }
//DO something else here...
}
function CheckDistance4D(Xlow, Xhigh, Ylow, Yhigh )
{
local mP = pPlayer.Pos;
if ( ( mP.x >= Xlow ) && ( mP.x <= Xhigh ) && ( mP.y >= Ylow ) && ( mP.y <= Yhigh ))
{ return true; }
return false;
}
-
The fact you used a timer for this isn't pretty, but then you also used millions of if's without any else if's. Ouch.
-
And what's the difference then, between single
if
and else if
Also, I don't see any sense in checking Player Vector on every FPS. I think for older PC timer would be better
Thank you for the feedback.
-
Because if you keep doing if's it will continue doing CheckDistance4D. If you use else if it will only do it a few times until it has found a statement that's true and will break.
While in this case it wouldn't matter a whole lot, it's better practice to learn it the right way.