Before anyone accuses me of trying to revive an old thread (if such a thread exists) let me say that I am genuinely interested in this. I am not doing this with thoughts of creating a vault submission, just seeking to build up my (and hopefully other peoples) arsenal of scripting weapons. If there is actually an old thread please "Bump" it and I will use that instead.
I am wondering if anyone else (other than me) has any small (preferably 10 lines or less) routines that they find genuinely useful and that they'd like to share. You know the sort of thing that while only maybe 3 or 4 lines of code long, either saves loads of typing or helps to make your code more readable. As an example, here are a pair of routines that I wrote which I have found to be useful.
void IncLocalInt(string sLocalInt, object oInMe = OBJECT_SELF) //convenience routine equivalent to LocalInt++
{
int iThisVar = GetLocalInt(oInMe, sLocalInt);
iThisVar++;
SetLocalInt(oInMe, sLocalInt, iThisVar);
}
void DecLocalInt(string sLocalInt, object oInMe = OBJECT_SELF) //convenience routine equivalent to LocalInt--
{
int iThisVar = GetLocalInt(oInMe, sLocalInt);
iThisVar--;
SetLocalInt(oInMe, sLocalInt, iThisVar);
}
Then there are the standard small routines that everybody uses such as
string PaddedStringDigits(int iInValue, int iNumChars) //convenience routine used to pad (with leading zeros) x digit numbers to iNumChars characters long
{
string sReturnMe = IntToString(iInValue); //in other programming languages you'd probably have to trim leading/trailing spaces
while(GetStringLength(sReturnMe) < iNumChars)
sReturnMe = "0" + sReturnMe;
}
and
void UseExamine() //goes in the OnUsed event - when the player clicks on a usable object the PC goes to the object and the description text is displayed
{
object oPC = GetLastUsedBy();
if(!(GetIsPC(oPC)))
return;
object oMe = OBJECT_SELF; //needed for next line
AssignCommand(oPC, ActionExamine(oMe)); // if OBJECT_SELF is used here instead of oMe, oPC's description displayed instead
}
Hopefully none of the above appear in the lexicon. I don't want to be accused of plagiarism after all.
So over to you (please).
TR