Skip to content

Instantly share code, notes, and snippets.

@McTwist
McTwist / compress.cs
Created January 4, 2016 10:15
Compresses a TorqueScript file to a smaller size but can still run
// One file only
// Does not optimize
function Compress(%from, %to)
{
%obj = new FileObject();
%obj.openForRead(findFirstFile(%from));
%chars = "abcdefghijklmnopqrstuvwxyz";
%current = 0;
deleteVariables("$va*");
while (!%obj.isEOF())
@McTwist
McTwist / xml.cs
Created January 4, 2016 10:18
Parsing XML in TorqueScript
// ================
// XML Parser
// ================
// Author: McTwist
// Version: 1.0
// Description: Parses xml code in an easy way
// License: Free to use
// ================
// When adding, prepare stack
@McTwist
McTwist / math.cs
Last active August 21, 2017 21:13
Simple math library for handling large numbers in TorqueScript
// ====================== //
// McTwist's Math library //
// ====================== //
// Version: 0.5 (prototype)
// Integer allowed only(Unless function tells otherwise)
// Note: Library is for demonstration only. Be aware that it might not be
// correct and performance may be horrible on some methods.
function Math::onAdd(%this)
{
@McTwist
McTwist / ini.cs
Created January 4, 2016 10:26
Parsing INI in TorqueScript
// ================
// INI Parser
// ================
// Author: McTwist
// Version: 1.0
// Description: Parses ini code in an easy way
// License: Free to use
// ================
// INI reading
@McTwist
McTwist / bind.cs
Last active November 14, 2017 09:59
Binds a key to a function
// Create a possible bind to a function. This will place it in respective division.
// If division and name is the same, it will replace the function.
function CreateBind(%division, %name, %cmd)
{
if (%name $= "" || %cmd $= "")
return;
%remapid = $remapCount;
%new = true;
@McTwist
McTwist / clone.cs
Last active March 1, 2018 23:48
Clones an object
// Clone current object
function SimObject::clone(%this, %name)
{
%this = %this.getID();
%oldName = %this.getName();
%name = %name !$= "" ? %name : %oldName;
%this.setName(__CLONE_OBJECT__);
%obj = new (%this.getClassName())(%name : __CLONE_OBJECT__);
%this.setName(%oldName);
return %obj;
@McTwist
McTwist / saver.cs
Created November 25, 2016 06:46
A saving system for Blockland where each user is his own file
// --------------------------
// Name: Saver
// Description: Database System
// Version: 1.5a
// Author: McTwist
// Copyright: Free for all
// License: Do not change anything
// --------------------------
// Notes
// No saving system is the same, but all saving systems is the other one alike.
@McTwist
McTwist / num2str.cs
Created August 16, 2017 00:10
Correctly converts a number in TorqueScript to a string
// Converts a number to a string correctly
function num2str(%num)
{
if (mAbs(%num) < 1000000)
return "" @ %num;
if (%num < 0)
{
%neg = true;
%num = -%num;
}

Keybase proof

I hereby claim:

  • I am mctwist on github.
  • I am mctwist (https://keybase.io/mctwist) on keybase.
  • I have a public key ASC5PRJewudjFa2Z5InRBTqnsBW5l0ueJlqTTvOfcI6Z2wo

To claim this, I am signing this object:

@McTwist
McTwist / echos.cs
Last active November 15, 2017 12:46
A secure way to echo out strings in TorqueScript larger than 4095 characters
// Echo a huge string in a safe way
// Note: It will try to make the output consistent, but too long chunks with
// no newline will break the consistency
function echos(%str)
{
// Maximum amount of characters that can be output with normal echo
%max = 4095;
%len = strlen(%str);
for (%i = 0; %i < %len; %i += getMin(%size + 1, %max))
{