PWE_PRC8/_module/nss/ff_include_other.nss
Jaysyn904 ee1dc35889 Initial Commit
Initial Commit
2025-04-03 10:29:41 -04:00

171 lines
5.1 KiB
Plaintext

///*************************************
//* NWN-FF 4.0 (c) 2004 FastFrench *
//*************************************
// This file is licensed under the terms of the
// GNU GENERAL PUBLIC LICENSE (GPL) Version 2
// ********************
// ** ff_include_other.nss **
// ********************
// ** Some other functions, nothing really related with NWN-FF binaries,
// ** but still very useful. Those functions should be used on Linux servers too.
// This replaces all occurences of textes inclosed with brackets by something
// Mainly used to add colors in the textes, with colors [r], [db]... (check complete list in
// initColor() function )
string ff_Colorize(string sText);
int ff_IsUpperCase(string oS);
int ff_IsLowerCase(string oS);
void ff_JumpToObject(object oPC, object oDest);
void ff_JumpToLocation(object oPC, location lDest);
string ff_GetResRef(object oItem);
//####################################################################################
//# +-[COLORIZE]------------------------------------------------------------------------+
/*
Parses and replace the color codes -
code from buu for kbuu,
adapted and optimised by FF
*/
string ff_Colorize(string sText) {
int Length = GetStringLength(sText);
string sTmp = "";
string sChar;
object oCmdColor_=OBJECT_INVALID;
while (Length>0)
{
int iPos = FindSubString(sText, "[")+1;
if (iPos>0)
{
sTmp += GetStringLeft(sText, iPos-1);
sText = GetStringRight(sText,Length-iPos);
Length -= iPos;
iPos = FindSubString(sText, "]")+1;
int iPos2 = FindSubString(sText, "[")+1;
if (iPos2>0 && iPos>0 && iPos2 < iPos) // [ imbriques
{
sTmp += "["+GetStringLeft(sText, iPos2-1);
sText = GetStringRight(sText,Length-(iPos2-1));
Length -= iPos2-1;
}
else
if (iPos>0)
{
string sKey = GetStringLeft(sText, iPos-1);
sText = GetStringRight(sText,Length-iPos);
Length -= iPos;
string sReplace="";
if (sKey!="")
{
if (oCmdColor_==OBJECT_INVALID) oCmdColor_ = GetObjectByTag("cmdLiteColors");
sReplace = GetLocalString(oCmdColor_, sKey);
}
if (sReplace!="")
{
sTmp += sReplace;
}
else
{
sTmp += "[" + sKey + "]";
}
}
else
{
sTmp += "["+sText;
Length = 0;
}
}
else
{
sTmp += sText;
Length = 0;
}
}
return sTmp;
}
int ff_IsLowerCase(string oS)
{
if (GetStringLowerCase(oS)==oS) return TRUE;
return FALSE;
}
int ff_IsUpperCase(string oS)
{
if (GetStringUpperCase(oS)==oS) return TRUE;
return FALSE;
}
void ff_JumpToObject(object oPC, object oDest)
{
if (!GetIsObjectValid(oPC)) return;
if (!GetIsObjectValid(oDest) || !GetIsObjectValid(GetArea(oDest)))
{
SendMessageToPC(oPC,"Destination invalide !");
SendMessageToAllDMs(GetName(oPC)+": Destination invalide !");
return;
}
if (!GetIsObjectValid(GetArea(oPC)))
{
SendMessageToPC(oPC,"Attente pour le grand saut...");
SendMessageToAllDMs(GetName(oPC)+"Attente pour le grand saut (O)...");
DelayCommand(1.0, ff_JumpToObject(oPC, oDest));
return;
}
AssignCommand(oPC, JumpToObject(oDest));
}
void ff_JumpToLocation(object oPC, location lDest)
{
if (!GetIsObjectValid(oPC)) return;
if (!GetIsObjectValid(GetAreaFromLocation(lDest)))
{
SendMessageToPC(oPC,"Destination invalide !");
SendMessageToAllDMs(GetName(oPC)+": Destination invalide !");
return;
}
if (!GetIsObjectValid(GetArea(oPC)))
{
SendMessageToPC(oPC,"Attente pour le grand saut...");
SendMessageToAllDMs(GetName(oPC)+"Attente pour le grand saut (L)...");
DelayCommand(1.0, ff_JumpToLocation(oPC, lDest));
return;
}
AssignCommand(oPC, JumpToLocation(lDest));
}
// FastFrench: Returns a time as an int value (no binary needed)
int ff_GetTime()
{
return GetTimeMinute()*60+FloatToInt(HoursToSeconds(GetTimeHour()+GetCalendarDay()*24))+GetTimeSecond();
}
string ff_GetStrTotalTime(int iCompteur)
{
string sResult;
int Secondes = iCompteur;//FloatToInt(GetTotalTime(iCompteur));
int Heures = Secondes / 3600;
Secondes %= 3600;
int Minutes = Secondes / 60;
Secondes %= 60;
if (Heures>0)
sResult = IntToString(Heures)+" hours, ";
if (Minutes>0)
sResult += IntToString(Minutes)+" minutes, ";
if (Heures==0)
if (Minutes>0)
sResult += IntToString(Secondes)+" secondes";
else
sResult = "newborn";
return sResult;
}