PDA

View Full Version : ffcscript.zh



Saffith
06-30-2011, 06:36 PM
As of RC2, ffc->Script is writable. I made a header file with a few functions to take advantage of this. Specifically, these are for using FFCs as generic script vehicles. Nothing fancy, but I figure it'll be handy.

ffcscript.zh 1.1.1 (http://www.purezc.net/index.php?page=scripts&id=245)


The most obvious use of this is for items; most of them can launch an FFC script now instead of having to be worked into the global script. As an example, here's a simple item that homes in on a random enemy and explodes when it gets close enough or the item is used again:


item script HomingBomb_item
{
void run(int ffcScriptNum, int sprite)
{
int ffcID=FindFFCRunning(ffcScriptNum);

if(ffcID==0) // No bombs active
{
if(Screen->NumNPCs()==0)
Quit();

int args[8]={this->Power, sprite};
RunFFCScript(ffcScriptNum, args);
}
else // Detonate
{
ffc f=Screen->LoadFFC(ffcID);
f->Misc[0]=1;
}
}
}

ffc script HomingBomb_ffc
{
void run(int damage, int sprite)
{
if(Screen->NumNPCs()==0)
Quit();

// Create the bomb, pick a random target
lweapon bomb=Screen->CreateLWeapon(LW_SCRIPT1);
npc target=Screen->LoadNPC(Rand(Screen->NumNPCs())+1);

bomb->X=Link->X;
bomb->Y=Link->Y;
bomb->CollDetection=false;
bomb->UseSprite(sprite);
bomb->Angular=true;
bomb->Step=200;

// Aim toward the enemy; detonate the bomb when it reaches the enemy,
// the enemy dies, or this->Misc[0] is set
while(target->isValid() && this->Misc[0]==0 && !Collision(bomb, target))
{
bomb->Angle=ArcTan(target->X-bomb->X, target->Y-bomb->Y);
Waitframe();
}

// Detonate
lweapon blast=Screen->CreateLWeapon(LW_BOMBBLAST);
blast->Damage=damage;
blast->X=bomb->X;
blast->Y=bomb->Y;
bomb->DeadState=0;
}
}

Saffith
05-01-2013, 12:29 PM
Updated. Just two small changes:
- Invalid script numbers now fail correctly, so you can use Game->GetFFCScript() without validating the result
- The argument array no longer needs to be 8 elements

Saffith
08-20-2014, 11:57 AM
Updated. It will now make sure not to grab changers.