Useful functions & Snippets

Started by DizzasTeR, Nov 05, 2015, 02:27 PM

Previous topic - Next topic

DizzasTeR

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:
  • Do not post functions or snippets which are not tested
  • Do not post any snippet / function which may not function on a blank script
  • Do not post common functions, post something useful as the topic name suggests
  • You can post a function though but only if its after a long period to let others have a notification of it
  • Do not post functions which are already posted
  • Do not go off-topic
  • If you have copied the function or snippet from somewhere, you must give the original author his credits

KAKAN

#1
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 );
  */
}
oh no

rulk

@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.
We are all god's children.