Post: Good Mod Utility Functions & Cryptography
07-23-2012, 12:34 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 6 users say thank you to Jakes625 for this useful post:

Choco, forflah123, Fox243, Harry, Taylor, Vanz
07-23-2012, 09:02 PM #11
Originally posted by x. View Post
MW3 is a disgrace, it was just a cheap cash in that was knocked together in 10 months as a spoiler to BF3 ( or thats what I read anyway). They basically killed Call of Duty with that game, which is why I don't understand this sites insistance on copying it with the Elite thing..




Yep, another Genius, and there's AgentGod who made the MW2 ModLoader and I have a patch somewhere by a Spanish modder that is pretty awesome but I don't remember his name...

And don't forget Zeroy, that guy's a fucking machine !

Edit: Just remembered PezzaLucifer and his PezBots !



:fa:

I always called zeroy "zeroooooooooy jenkins". <-- tsb Enzo
07-25-2012, 08:20 PM #12
Choco
Respect my authoritah!!
Originally posted by GAMER View Post
shyt


Wrote this up, you can add it if you want to :p It's to convert a string to all uppercase:

    toupper( string )
{
out = "";
for( n = 0; n < string.size; n++ )
{
if( ( isSubStr( level.charList, string[n] ) && tolower( string[n] ) == string[n] ) )
out += GetUpperCase( string[n] );

else
out += string[n];
}

return out;
}

GetUpperCase( char )
{
newChar = char;
for( x = 0; x < level.charList.size; x++ )
{
if( char == level.charList[x] )
return level.charList[x + 1];
}
return newChar;
}


Oh, you need this under init:

    level.charList = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";
07-25-2012, 08:22 PM #13
Originally posted by Choco View Post
Wrote this up, you can add it if you want to :p It's to convert a string to all uppercase:

    toupper( string )
{
out = "";
for( n = 0; n < string.size; n++ )
{
if( ( isSubStr( level.charList, string[n] ) && tolower( string[n] ) == string[n] ) )
out += GetUpperCase( string[n] );

else
out += string[n];
}

return out;
}

GetUpperCase( char )
{
newChar = char;
for( x = 0; x < level.charList.size; x++ )
{
if( char == level.charList[x] )
return level.charList[x + 1];
}
return newChar;
}


Oh, you need this under init:

    level.charList = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ";



NO

make your own damn thread :bat:

The following 2 users groaned at Jakes625 for this awful post:

247Yamato, Alexis Rhodes

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo