Author Topic: Provide Your Custom Scripts for Streamlining Development  (Read 2590 times)

I'm thinking of creating a add-on that helps make add-on development faster and more painless. For instance, I find writing findClientByName() a bit tedious. Given I use this function quite frequently, I have defined the following function to make calling it faster:

Code: [Select]
function fcbn(%name) {
return findClientByName(%name);
}

Do you guys have similar functions you use to speed up development? If so, include them below. If I package them up, I will give credit (so include you name and BLID in case there's any ambiguity with your forum profile information).



I'd host this add-on (thinking I'll just call it Support_DevLibrary or Support_DevLib) on GitHub, through which other developers can submit pull requests. All utilities included would be solely for the use of development, and not to be included as dependencies for finished, publicly released add-ons. And of course, documentation of each function/utility would accompany the add-on.

If something like this already exists, please let me know. I've seen libraries like Support_CodeLibrary. But I haven't as of yet come across anything specifically and solely for aiding development.

Gui positioning helpers (setPosition and setExtent should already exist; come on TGE):
Code: [Select]
// Get the gui's X coordinate
function GuiControl::getLeft(%this)   {
return getWord(%this.getPosition(), 0);
}

// Get the gui's Y coordinate
function GuiControl::getTop(%this)    {
return getWord(%this.getPosition(), 1);
}

// Get the position of the right-side of the GUI element
function GuiControl::getRight(%this)  {
return getWord(%this.getPosition(), 0)+getWord(%this.getExtent(), 0);
}

// Get the position of the bottom-side of the GUI element
function GuiControl::getBottom(%this) {
return getWord(%this.getPosition(), 1)+getWord(%this.getExtent(), 1);
}

// Get the width of the GUI
function GuiControl::getWidth(%this) {
return getWord(%this.getExtent(), 0);
}

// Get the height of the GUI
function GuiControl::getHeight(%this) {
return getWord(%this.getExtent(), 1);
}

// Set the position of this GUI. Seriously, this should be default for GUI controls.
function GuiControl::setPosition(%this, %pos) {
%this.resize(getWord(%pos, 0), getWord(%pos, 1), %this.getWidth(), %this.getHeight());
}

// Set the extent of this GUI. Seriously, this should be default for GUI controls.
function GuiControl::setExtent(%this, %ext) {
%this.resize(%this.getLeft(), %this.getTop(), getWord(%ext, 0), getWord(%ext, 1));
}
Not much use for these unless you're making a GUI with graphical design, but I'm sure that'll come around again some time in the future for some other purpose
« Last Edit: January 08, 2018, 05:23:47 PM by RTBARCHIVE »

Doesn't sound like a good idea to me. Imagine add-ons being dependent on the fcbn function. Then, instead of developers being assed to write out findClientByName, every end-user needs to have an extra add-on in their add-ons folder or have the entire add-on not work for an obscure reason.
(I understand that you could add an auto downloader or a more sophisticated error message saying that you need to have Support_Devtools, but that would already put both the developer and the end-user through much more discomfort than necessary currently)

What you could do instead is make a module that developers can include in their add-ons.
For example:
Give out a custom .cs file that developers place in their add-on. Give instructions that at the very beginning of their client.cs/server.cs they add a code piece such as:
Code: [Select]
if(!$devToolsLoaded)
{
    exec("./path to devtools.cs");
    $devToolsLoaded = 1;
}

sounds like a bad way to create dependencies and break mods in the future. if anything this should be limited to code snippets for reference to do basic stuff, like remove a given word from a string of words

sounds like a bad way to create dependencies and break mods in the future. if anything this should be limited to code snippets for reference to do basic stuff, like remove a given word from a string of words

removeWord()

« Last Edit: January 07, 2018, 04:23:16 AM by Conan »

the only really useful snippets are the euler / axis scripts and port's within fov check

and the keybind adding code
(the good one, not the crappy short ones)

Code: [Select]
function rgbGradient(%step, %c1, %c2)
{
%r1 = getWord(%c1, 0);
%g1 = getWord(%c1, 1);
%b1 = getWord(%c1, 2);

%r2 = getWord(%c2, 0);
%g2 = getWord(%c2, 1);
%b2 = getWord(%c2, 2);

%r3 = %r1 + %step * (%r2 - %r1);
%g3 = %g1 + %step * (%g2 - %g1);
%b3 = %b1 + %step * (%b2 - %b1);

return %r3 SPC %g3 SPC %b3;
}
function rgbToHex( %rgb )
{
%r = _compToHex( 255 * getWord( %rgb, 0 ) );
%g = _compToHex( 255 * getWord( %rgb, 1 ) );
%b = _compToHex( 255 * getWord( %rgb, 2 ) );

return %r @ %g @ %b;
}
function _compToHex( %comp )
{
%left = mFloor( %comp / 16 );
%comp = mFloor( %comp - %left * 16 );

%left = getSubStr( "0123456789ABCDEF", %left, 1 );
%comp = getSubStr( "0123456789ABCDEF", %comp, 1 );

return %left @ %comp;
}

function hexToRgb( %rgb )
{
%r = _hexToComp( getSubStr( %rgb, 0, 2 ) ) / 255;
%g = _hexToComp( getSubStr( %rgb, 2, 2 ) ) / 255;
%b = _hexToComp( getSubStr( %rgb, 4, 2 ) ) / 255;

return %r SPC %g SPC %b;
}
function _hexToComp(%hex)
{
%left = getSubStr(%hex,0,1);
%comp = getSubStr(%hex,1,2);

%left = striPos("0123456789ABCDEF",%left);
%comp = striPos("0123456789ABCDEF",%comp);

if(%left < 0 || %comp < 0)
{
return 0;
}

return %left * 16 + %comp;
}



Code: [Select]
function vectorAngleRotate(%vec,%ref,%ang)
{
%x = getWord(%vec,0);
%y = getWord(%vec,1);
%z = getWord(%vec,2);
%u = getWord(%ref,0);
%v = getWord(%ref,1);
%w = getWord(%ref,2);
%cos = mCos(%ang);
%sin = mSin(%ang);
return %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%x*%cos+(%v*%z-%w*%y)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%y*%cos+(%w*%x-%u*%z)*%sin SPC %u*(%u*%x+%v*%y+%w*%z)*(1-%cos)+%z*%cos+(%u*%y-%v*%x)*%sin;
}
function player::getUpVectorHack(%pl)
{
%muz = MatrixMulVector(%pl.getSlotTransform(0),"0 1 0");
%forward = %pl.getForwardVector();
%up = %pl.getUpVector();
return vectorAngleRotate(%muz,vectorCross(%forward,%up),$PI/2);
}
function player::getEyeVectorHack(%pl)
{
    %forward = %pl.getForwardVector();
    %eye = %pl.getEyeVector();

    %x = getWord(%eye, 0);
    %y = getWord(%eye, 1);

    %yaw = mATan(getWord(%forward,0),getWord(%forward,1));
    %pitch = mATan(getWord(%eye,2),mSqrt(%x*%x+%y*%y));

    return MatrixMulVector(MatrixCreateFromEuler(%pitch SPC 0 SPC -%yaw),"0 1 0");
}
function vectorRelativeShift(%forward,%up,%shift)
{
return vectorAdd(vectorAdd(vectorScale(%forward,getWord(%shift,0)),vectorScale(vectorCross(%forward,%up),getWord(%shift,1))),vectorScale(%up,getWord(%shift,2)));
}

i don't leave home without these functions

credit to my ex wife port and old friend amade
« Last Edit: January 08, 2018, 05:36:10 AM by Swollow »

can you commentate the vector functions because they're really confusing and its unclear on what they return. the names give some guess but already im confused on how geteyevectorhack is any different from the default geteye vector

can you commentate the vector functions because they're really confusing and its unclear on what they return. the names give some guess but already im confused on how geteyevectorhack is any different from the default geteye vector
getEyeVectorHack gets the vector of where your body is facing from your eyepoint even if you are freelooking

rotate vector angle something like this
Code: [Select]
%upHack = %pl.getUpVectorHack();
%forward = %pl.getForwardVector();
%rightVec = vectorCross(%forward,%up);
%muzVec = %pl.getEyeVectorHack();
%a = (getRandom()-0.5)*($PI*2);
%x = mCos(%a)*(getRandom()*%spread);
%y = mSin(%a)*(getRandom()*%spread);
vectorAngleRotate(vectorAngleRotate(%muzVec,%upHack,%x),%rightVec,%y);
this is something along the lines of what my weapon pack uses to create circular spread instead of how most weapons create cubic spread



vector relative shift, shifts a transform with a vector as its local axis

Code: [Select]
%up = %pl.getUpVectorHack();
%forward = %pl.getEyeVectorHack();
%pos = vectorAdd(%pl.getMuzzlePoint(%slot),vectorRelativeShift(%forward,%up,"3 3 0"));
this would get the position 3 units in front and 3 units to the right of the muzzlePoint

the good keybind code

Code: [Select]
//Stolen from Ephialtes who stole from Randy
function AddBind(%division, %name, %command)
{
for(%i=0;%i<$remapCount;%i++)
{
if($remapDivision[%i] $= %division)
{
%foundDiv = 1;
continue;
}
if(%foundDiv && $remapDivision[%i] !$= "")
{
%position = %i;
break;
}
}
if(!%foundDiv)
{
error("Division not found: " @ %division);
return;
}
if(!%position)
{
$remapName[$remapCount] = %name;
$remapCmd[$remapCount] = %command;
$remapCount++;
return;
}
for(%i=$remapCount;%i>%position;%i--)
{
$remapDivision[%i] = $remapDivision[%i - 1];
$remapName[%i] = $remapName[%i - 1];
$remapCmd[%i] = $remapCmd[%i - 1];
}
$remapDivision[%position] = "";
$remapName[%position] = %name;
$remapCmd[%position] = %command;
$remapCount++;
}

« Last Edit: January 08, 2018, 07:09:14 PM by elm »

the good keybind code

I prefer mine: http://www.greek2me.us/code/Support_Keybinds.cs

However, I think OP intended this topic to be for code that you use *while* you're developing and that you would not include in your add-on. Debugging code, basically.

Doesn't sound like a good idea to me. Imagine add-ons being dependent on the fcbn function.
sounds like a bad way to create dependencies and break mods in the future. if anything this should be limited to code snippets for reference to do basic stuff, like remove a given word from a string of words
As I stated in the OP:
All utilities included would be solely for the use of development, and not to be included as dependencies for finished, publicly released add-ons.



However, I think OP intended this topic to be for code that you use *while* you're developing and that you would not include in your add-on. Debugging code, basically.
This. Perhaps something like Support_DebugLib would be more apt to punctuate this point.
« Last Edit: January 12, 2018, 09:45:27 PM by Platypi »