Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Seldom required functions
#1
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 (
== 0);
}

isInt(n)
{
    return (
== 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(startendtrueself);
        
dist distance(starttrace["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(startendfalseent);
                
dist distance(starttrace["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(startendfalseent);
                
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 + (0060);

    if(
self getStance() == "crouch")
        
eye -= (0020);
    else if(
self getStance() == "prone")
        
eye -= (0049);

    return 
eye;
}
vector_scale(vecscale)
{
    return (
vec[0] * scalevec[1] * scalevec[2] * scale);


Hope this helps
Reply

#2
Nice job. :3 Here's an alternative to the strip function.
Code:
trim_string(str, chr)
{
    if(!isDefined(chr)) { chr = " "; }
    return_string = "";
    start_index = 0;
    end_index = str.size - 1;
    for(i = 0; i < str.size; i++)
        if(str[i] == chr) { start_index = i; } else { break; }
    for(i = str.size - 1; i >= 0; i--)
        if(str[i] == chr) { end_index = i; } else { break; }
    for(i = start_index; i <= end_index; i++)
        return_string += str[i];
    return return_string;
}

You can specify what character to trim (optional).
[Image: 30xhrep.png]

A casual conversation between barata and I about Nukem.
Reply

#3
OMFG i have just finished to export pickup function from BTD! I see the topic now Sad
Reply

#4
Will the Player pickup work in MW2?
Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  [Release] Matrix Functions Yamato 1 2,774 07-29-2013, 20:14
Last Post: Rendflex
  [Release] nCr and Factorial Functions Yamato 2 2,694 06-18-2013, 17:24
Last Post: Nekochan
  [Release] Random Functions 1.1 Yamato 22 13,393 04-20-2013, 10:13
Last Post: Dominator56
  urgent required for a plugin urs_amit 9 6,597 03-15-2013, 13:09
Last Post: eVinco
  Functions surtek 14 11,322 09-19-2012, 07:57
Last Post: Pozzuh
Information [Solved] Info about functions, events and etc. Nerus 2 2,503 09-09-2012, 20:57
Last Post: surtek
  [Request] Ok Help is required for XUID bug Cyanide 45 20,821 07-16-2012, 03:54
Last Post: master131
  Help I find This functions and i need your help. Bloodfocus 5 3,861 04-23-2012, 01:43
Last Post: House
  Help Functions iPrintLnBold() [Z00MBY] Alex 7 5,897 04-16-2012, 08:44
Last Post: [Z00MBY] Alex
  [Release] Array functions master131 4 3,718 09-17-2011, 14:23
Last Post: AZUMIKKEL

Forum Jump:


Users browsing this thread:
2 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2024 Melroy van den Berg.