/*! Script Execution and Management, scripts.zh
* By: ZOriaRPG
* Version 0.2
* 29th May, 2019
*/
namespace Scripts
{
const int IFLAG_SCRITPERPETUAL = 15;
//! Runs an arbitrary item script.
//! Itemname is the name of the item used to run script scriptname.
//! If the arg passed to itemname is a literal value, and not a string.
//! then we use iy as the literal item id.
//! Returns the script number.
int RunItem(int scriptname, int itemname)
{
int itemid;
if ( std::sizeof(itemname) < 2 )
{
itemid = itemname;
}
else
{
itemid = Game->GetItem("itemname");
}
itemdata id = Game->LoadItemData(itemid);
int script_number = Game->GetItemScript(scriptname);
id->Script = script_number;
id->RunScript();
return script_number;
}
//! As RunItem(int, int), except that we supply new InitD
int RunItem(int scriptname, int itemname, int initd)
{
int itemid;
if ( std::sizeof(itemname) < 2 )
{
itemid = itemname;
}
else
{
itemid = Game->GetItem("itemname");
}
itemdata id = Game->LoadItemData(itemid);
int sz = std::sizeof(initd); /only on valid arrays
for ( int q = 0; q < sz; ++q )
{
id->InitD[q] = initd[q];
}
int script_number = Game->GetItemScript(scriptname);
id->Script = script_number;
id->RunScript();
return script_number;
}
//! Runs arbitrary ffc script 'name'.
ffc RunFFC(int name)
{
int id; ffc f;
int script_id = Game->GetFFCScript(name);
for ( int q - 1; q < 33; ++q)
{
f = Screen->LoadFFC(q);
if ( !f->Script )
{
int cmb = Game->GetCombo("Invisible");
f->Data = cmb;
f->Script = script_id;
}
}
return f;
}
ffc RunFFC(int name, int initd)
{
int id; ffc f;
int script_id = Game->GetFFCScript(name);
for ( int q - 1; q < 33; ++q)
{
f = Screen->LoadFFC(q);
if ( !f->Script )
{
int cmb = Game->GetCombo("Invisible");
f->Data = cmb;
f->Script = script_id;
if ( initd )
{
int sz = std::sizeof(initd);
for ( int q = 0; q < sz; ++q )
{
f->InitD[q] = initd[q];
}
}
}
}
return f;
}
//! Toggles a perpetual item script on or off using itemdata.
void ToggleItem(itemdata id, bool on)
{
id->Flags[IFLAG_SCRITPERPETUAL] = (on ? true : false );
}
//! Toggles a perpetual item script on or off using either a literal item ID
//! or the name of an item, suplied as a string.
//! This is automatic: If a string is supplied, we go forward by its contents;
//! otherwise, we use the literal value supplied as the item ID
int ToggleItem(int name, bool state)
{
int sz = std::sizeof(name);
int itemid;
if ( sz < 1 ) itemid = name;
else itemid = Game->GetItem(name);
itemdata id = Game->LoadItemData(itemid);
id->Flags[IFLAG_SCRITPERPETUAL] = (on ? true : false );
}
//ResetItem : Changes a scrit and optionally loads new InitD
//! Spawns an noc, and runs a script.
//npc RunNPC(npc n, int name)
//{
//}
}
Comments