Vice City: Multiplayer

Server Development => Scripting and Server Management => Snippet Showroom => Topic started by: DizzasTeR on Nov 05, 2015, 02:27 PM

Title: Useful functions & Snippets
Post by: DizzasTeR on Nov 05, 2015, 02:27 PM
I noticed that @KAKAN's topic regarding this wasn't going as 'these type' of topics usually used to go. He was the only one who was posting them, plus he was editing the first topic making a complete mess. So I pm'ed him to delete his so that I may create a new one with clean rules and explanation on how such threads can go.

Original thread started: @KAKAN

* Rules listed in red have higher priority!

RULES:
Title: Re: Useful functions & Snippets
Post by: KAKAN on Nov 05, 2015, 02:53 PM
function GetWepName(reason)
{
if(!reason) return "Unknown";
else switch(reason)
{
  case 100: return "C-Wep 1";
  default: return GetWeaponName(reason.tointeger());
}
}

function GetWepID(id){
if(!id) return "Unknown";
else switch(id.tolower()){
    case "c-wep 1": return 100;
    default: return GetWeaponID(id);
  }
}

This one:- Credits goes to @Cutton
function direction(x1, y1, x2, y2)
{
  //all values must be floats.
  x1 = x1.tofloat();
  x2 = x2.tofloat();
  y1 = y1.tofloat();
  y2 = y2.tofloat();
  // Added those ^ just in case you forget :P
  local m = (y2-y1)/(x2-x1);
  if ((m >= 6) || (m <= -6))
  {
    if (y2 > y1) return "North";
    else return "South";
  }
  if ((m < 6) && (m >= 0.5))
  {
    if (y2 > y1) return "North East";
    else return "South West";
  }
  else if ((m < 0.5) && (m > -0.5))
  {
    if (x2 > x1) return "East";
    else return "West";
  }
  else if ((m <= -0.5) && (m > -6))
  {
    if (y2 > y1) return "North West";
    else return "South East";
  }
}

function IsPlayerInRangeOfPoint(v1, v2, range) // by Rusty_Bullet22
{
  v1.x -= v2.x, v1.y -= v2.y, v1.z -= v2.z;
  return ((v1.x * v1.x) + (v1.y * v1.y) + (v1.z * v1.z)) < (range * range);
  /*
Returns true if the player is within a range of 1500 from (0,0,0)
false if not
IsPlayerInRangeOfPoint( player.Pos, Vector( 0, 0, 0 ), 1500 );
  */
}
Title: Re: Useful functions & Snippets
Post by: rulk on Nov 05, 2015, 03:03 PM
@KAKAN, cutton isn't me, he's the leader of the VU clan, i'm not sure if he is still active. Rusty_Bullet22 is me though.