PHP Code:
/*
* Removes all colour formatting from a string
*
* @param string to remove colours from
*
* @return the monochromed string
*/
monochrome(str)
{
if(!isDefined(str))
return "";
temp = "";
for(i=0;i<str.size-1;i++)
{
if(str[i] == "^")
{
switch(str[i+1])
{
case "0":
case "1":
case "2":
case "3":
case "4":
case "5":
case "6":
case "7":
case "8":
case "9":
i++; break;
default:
temp += str[i];
}
}
else
temp += str[i];
}
return temp + str[str.size-1];
}
/*
* Removes spaces from the beginning and end of a string
*
* @param string to remove spaces from
*
* @return stipped string
*/
strip(str)
{
temp = "";
endSpaces = 0;
startAdding = false;
for(i=str.size-1;i>=0;i--)
{
if(str[i] == " ")
endSpaces++;
else
break;
}
if(endSpaces == str.size)
return "";
for(i=0;i<str.size-endSpaces;i++)
{
if(startAdding)
temp += str[i];
else if(str[i] != " " && !startAdding)
startAdding = true;
}
return temp;
}
isEven(n)
{
return (n % 2 == 0);
}
isInt(n)
{
return (n == int(n));
}
/*
* Checks if an array contains a value
*
* @param array to look through
*
* @param value to find in array
*
* @return boolean indicating if the value was found in the array
*/
arrayContains(arr, var)
{
if(!isDefined(arr) || !isDefined(var))
return false;
for(i=0;i<arr.size;i++)
{
if(arr[i] == var)
return true;
}
return false;
}
Player pickup
PHP Code:
playerPickup()
{
self endon("disconnect");
self endon("killed_player");
self endon("joined_spectators");
while(true)
{
while(!self secondaryoffhandButtonPressed())
wait 0.05;
start = self getPlayerEyePosition();
end = start + vector_scale(anglesToForward(self getPlayerAngles()), 999999);
trace = bulletTrace(start, end, true, self);
dist = distance(start, trace["position"]);
ent = trace["entity"];
if(isDefined(ent) && ent.classname == "player") // Remove " ent.classname == "player" " to pick up any entity, including moving models etc
{
if(isPlayer(ent))
ent iprintln("^1You've been picked up by ^2" + self.name + "^1!");
self iprintln("^1You've picked up ^2" + ent.name + "^1!");
linker = spawn("script_origin", trace["position"]);
ent linkto(linker);
while(self secondaryoffhandButtonPressed())
wait 0.05;
while(!self secondaryoffhandButtonPressed() && isDefined(ent))
{
start = self getPlayerEyePosition();
end = start + vector_scale(anglesToForward(self getPlayerAngles()), dist);
trace = bulletTrace(start, end, false, ent);
dist = distance(start, trace["position"]);
if(self fragButtonPressed() && !self adsButtonPressed())
dist -= 15;
else if(self fragButtonPressed() && self adsButtonPressed())
dist += 15;
end = start + vector_scale(anglesToForward(self getPlayerAngles()), dist);
trace = bulletTrace(start, end, false, ent);
linker.origin = trace["position"];
wait 0.05;
}
if(isDefined(ent))
{
ent unlink();
if(isPlayer(ent))
ent iprintln("^1You've been dropped by ^2" + self.name + "^1!");
self iprintln("^1You've dropped ^2" + ent.name + "^1!");
}
linker delete();
}
while(self secondaryoffhandButtonPressed())
wait 0.05;
}
}
getPlayerEyePosition()
{
eye = self.origin + (0, 0, 60);
if(self getStance() == "crouch")
eye -= (0, 0, 20);
else if(self getStance() == "prone")
eye -= (0, 0, 49);
return eye;
}
vector_scale(vec, scale)
{
return (vec[0] * scale, vec[1] * scale, vec[2] * scale);
}
Hope this helps