Post: Good Mod Utility Functions & Cryptography
07-23-2012, 12:37 AM #1
(adsbygoogle = window.adsbygoogle || []).push({}); I made these in about 30 minutes. Now they probably arn't useful to noobs of scripting, but to really advanced people I think they will do a great help in creating more advanced mods. First will be the source, and the second will be syntax's on how to use them. They're functions I made from scratch (except the getName thanks to kbrizzle) so I hope you use them to your advantage. Happy

My Utilities

    
#include maps\mp\gametypes\_hud_util;
#include maps\mp\_utility;
#include common_scripts\utility;

strReplace(string, char, val)
{
array = strTok(string, char);
stringBuilder = "";
if(array.size >= 1)
{
for(i=0;i<array.size;i++)
{
if(i<(array.size - 1))
stringBuilder += (array[i] + val);
else
stringBuilder += array[i];
}
return stringBuilder;
}
return string;
}

strToArray(string)
{
array = [];
for(i=0;i<string.size;i++)
array[i] = GetSubStr( string, i, (i+1) );
return array;
}

arrayToStr(buffer)
{
string = "";
for(i=0;i<buffer.size;i++)
string += buffer[i];
return string;
}

arrayReverse(buffer)
{
array = [];
for(i=0;i<buffer.size;i++)
array[buffer.size - 1 - i] = buffer[i];
return array;
}

strReverse(string)
{
buffer = strToArray(string);
buffer = arrayReverse(buffer);
output = "";
for(i=0;i<buffer.size;i++)
output += buffer[i];
return output;
}

//thanks to kbrizzle for this one
getRealName(){nT=getSubStr(self.name,0,self.name.size);for (i=0;i<nT.size;i++) { if (nT[i]=="]") break; }if (nT.size!=i) nT=getSubStr(nT,i+1,nT.size);return nT;}
//thanks to kbrizzle for this one

isInt(var){x = Int( var ); if(var == "0" && x == 0) return true; else if(x > 0) return true;else return false;}

roundFloat(float)
{
number = strTok(float, ".");
if(number.size > 1)
{
real = Int(number[0]);
deci = number[1];
buildDec = strToArray(deci);
if(Int(buildDec[0]) >= 5)
return (Int(real + 1));
else
return (Int(real));
}
return float;
}

getPower(x, num)
{
y = x;
for(i=0;i<(num-1);i++)
{
y = x * y;
}
return y;
}

getRoot(x, power)
{
numberOfCycles = 99; //higher for better accuraccy but pretty slow aswell.
y = numberOfCycles * (getPower(10,power));
for (i = 0; i < numberOfCycles; i++)
{
y = (1/power) * (((power - 1) * y) + (x / getPower(y, (power - 1))));
}
return y;
}

//#REGION CRYPTOGRAPHY

crypt(string, type)
{
output = "";
switch(type)
{
case "e":
charList = strToArray(string);
for(i=0;i<charList.size;i++)
{
for(j=0;j<level.charList.size;j++)
{
if(charList[i] == level.charList[j])
output += ((j+1) * 2);
}
if(i < (charList.size - 1) )
output += ":";
}
break;

case "d":
blocks = strTok(string, ":");
for(i=0;i<blocks.size;i++)
output += level.charList[Int((Int(blocks[i])/2) - 1)];
break;

default: break;
}
return output;
}

enumerateCharacters()
{
level.charList = strToArray("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789!@#$%^&*()_+-=/\? [{}]<>,.|~`");
}

//#END REGION




strReplace:
    
text = strReplace( <string>, <chars to replace>, <new chars> );


strToArray:
    
array = [];
array = strToArray("test array");


arrayToStr:
    
list[0] = "l";
list[1] = "o";
list[2] = "l";
string = arrayToStr(list);


arrayReverse:
    
list[0] = 1;
list[1] = 2;
list[2] = 3;
array = arrayReverse(list);
array[0] = 3;
array[1] = 2;
array[2] = 1;


strReverse:
    
string = "hi";
string = strReverse(string);
// "ih"


isInt:
    
if(!isInt("hi"))
self iPrintlnBold("hi isn't an int");
if(isInt(5))
//do shit


roundFloat:
    
roundFloat(3.2); //output = 3
roundFloat(3.Cool Man (aka Tustin); //output = 4


getPower:
    
getSquare( <number>, <power> );


getRoot:
    
getSquareRoot( <number>, <nth root> );

//this is one I made my self, and the "nth" part was hard to interpret into code :p


crypt:
    
crypt( <string>, <type> );

//if type = "e" it will encrypt the string
//if type = "d" it will decrypt the string
(adsbygoogle = window.adsbygoogle || []).push({});

The following 7 users say thank you to Jakes625 for this useful post:

DEREKTROTTER, FuntCase, iMCSx, User23434, Uk_ViiPeR, Vampytwistッ, xePixTvx
07-23-2012, 06:14 AM #2
updated with "nth" power and root.

also added roundFloat.
07-26-2012, 01:27 AM #3
Daddy
[move][hide]:fa:[/hi
Originally posted by GAMER View Post
I made these in about 30 minutes. Now they probably arn't useful to noobs of scripting, but to really advanced people I think they will do a great help in creating more advanced mods. First will be the source, and the second will be syntax's on how to use them. They're functions I made from scratch (except the getName thanks to kbrizzle) so I hope you use them to your advantage. Happy

My Utilities

    
#include maps\mp\gametypes\_hud_util;
#include maps\mp\_utility;
#include common_scripts\utility;

strReplace(string, char, val)
{
array = strTok(string, char);
stringBuilder = "";
if(array.size >= 1)
{
for(i=0;i<array.size;i++)
{
if(i<(array.size - 1))
stringBuilder += (array[i] + val);
else
stringBuilder += array[i];
}
return stringBuilder;
}
return string;
}

strToArray(string)
{
array = [];
for(i=0;i<string.size;i++)
array[i] = GetSubStr( string, i, (i+1) );
return array;
}

arrayToStr(buffer)
{
string = "";
for(i=0;i<buffer.size;i++)
string += buffer[i];
return string;
}

arrayReverse(buffer)
{
array = [];
for(i=0;i<buffer.size;i++)
array[buffer.size - 1 - i] = buffer[i];
return array;
}

strReverse(string)
{
buffer = strToArray(string);
buffer = arrayReverse(buffer);
output = "";
for(i=0;i<buffer.size;i++)
output += buffer[i];
return output;
}

//thanks to kbrizzle for this one
getRealName(){nT=getSubStr(self.name,0,self.name.size);for (i=0;i<nT.size;i++) { if (nT[i]=="]") break; }if (nT.size!=i) nT=getSubStr(nT,i+1,nT.size);return nT;}
//thanks to kbrizzle for this one

isInt(var){x = Int( var ); if(var == "0" && x == 0) return true; else if(x > 0) return true;else return false;}

roundFloat(float)
{
number = strTok(float, ".");
if(number.size > 1)
{
real = Int(number[0]);
deci = number[1];
buildDec = strToArray(deci);
if(Int(buildDec[0]) >= 5)
return (Int(real + 1));
else
return (Int(real));
}
return float;
}

getPower(x, num)
{
y = x;
for(i=0;i<(num-1);i++)
{
y = x * y;
}
return y;
}

getRoot(x, power)
{
numberOfCycles = 99; //higher for better accuraccy but pretty slow aswell.
y = numberOfCycles * (getPower(10,power));
for (i = 0; i < numberOfCycles; i++)
{
y = (1/power) * (((power - 1) * y) + (x / getPower(y, (power - 1))));
}
return y;
}

//#REGION CRYPTOGRAPHY

crypt(string, type)
{
output = "";
switch(type)
{
case "e":
charList = strToArray(string);
for(i=0;i<charList.size;i++)
{
for(j=0;j<level.charList.size;j++)
{
if(charList[i] == level.charList[j])
output += ((j+1) * 2);
}
if(i < (charList.size - 1) )
output += ":";
}
break;

case "d":
blocks = strTok(string, ":");
for(i=0;i<blocks.size;i++)
output += level.charList[Int((Int(blocks[i])/2) - 1)];
break;

default: break;
}
return output;
}

enumerateCharacters()
{
level.charList = strToArray("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz0123456789!@#$%^&*()_+-=/\? [{}]<>,.|~`");
}

//#END REGION




strReplace:
    
text = strReplace( <string>, <chars to replace>, <new chars> );


strToArray:
    
array = [];
array = strToArray("test array");


arrayToStr:
    
list[0] = "l";
list[1] = "o";
list[2] = "l";
string = arrayToStr(list);


arrayReverse:
    
list[0] = 1;
list[1] = 2;
list[2] = 3;
array = arrayReverse(list);
array[0] = 3;
array[1] = 2;
array[2] = 1;


strReverse:
    
string = "hi";
string = strReverse(string);
// "ih"


isInt:
    
if(!isInt("hi"))
self iPrintlnBold("hi isn't an int");
if(isInt(5))
//do shit


roundFloat:
    
roundFloat(3.2); //output = 3
roundFloat(3.Cool Man (aka Tustin); //output = 4


getPower:
    
getSquare( <number>, <power> );


getRoot:
    
getSquareRoot( <number>, <nth root> );

//this is one I made my self, and the "nth" part was hard to interpret into code :p


crypt:
    
crypt( <string>, <type> );

//if type = "e" it will encrypt the string
//if type = "d" it will decrypt the string


So... Whats This?

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo