Jump to content

Photo

Bobomb NPC Script


  • Please log in to reply
No replies to this topic

#1 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 05 March 2019 - 08:45 AM

BobOmb
An example npc script for 2.55, adapted from my EotM #25 submission. It may be interesting to compare the two, just to see how much more efficient npc scripts are, versus old methods.
 
Demonstration Quest | Script File


bobomb.png



import "std.zh"

//////////////////////////////////
/// BobOmb for 2.55            ///
/// By: ZoriaRPG               ///
/// 5th May, 2019              ///
/// v0.3                       ///
//////////////////////////////////

//v0.2 - Fixed a typo in isValid()
//v0.3 - Trivial performance edit on timer. 

//const int NPC_BOBOMB = 177; //Moved to bobomb.ID

//Use on a walking enemy with every defence set to Stun
npc script bobomb
{
	const int TIMER 	= 14; //Misc Index to store Timer
	const int CSET 		= 13; //Misc Index to store CSet
	const int FLASH_CSET 	= 8; //Some defaults. IDK if I should auto-assign them.
	const int DURATION 	= 120; //Some defaults. IDK if I should auto-assign them.
	const int ID 		= 177; //The enemy ID. Call as bobomb.ID elsewhere, if needed. 
	//Misc[] index of timer, misc index to store base cset, value fo flash cset, duration of timer
	void run(int misc_timer, int misc_cset, int flash_cset)
	{
		itemdata id = Game->LoadItemData(I_BOMB); 
		int pow = (this->WeaponDamage > 0) ? (this->WeaponDamage) : id->Power;
		
		//Auto-assign if the user forgot to set them.
		misc_timer = ( misc_timer > 0 ) ? misc_timer : TIMER;
		misc_cset = ( misc_cset > 0 ) ? misc_cset : CSET;
		flash_cset = ( flash_cset > 0 ) ? flash_cset : FLASH_CSET;
		this->Misc[misc_timer] = -1;
		while(this->isValid())
		{
			if ( this->Stun > 1 ) 
			{
				//check its timer
				
				switch(this->Misc[misc_timer])
				{
					case -1: 
					{
						//uninitialised
						this->Misc[misc_timer] = 0;
						continue; //initialise and move on to case 0. 
						//This is to ensure that the effect does not repeat. 
					}
					case 0:
					{
						//its not yet flashing, so set its timer.
						this->Misc[misc_timer] = DURATION;  //This is the duration of the flash, not the explosion. 
						this->Misc[misc_cset] = this->CSet;
						break;
					}
					default:
					{
						--this->Misc[misc_timer];
						if ( !(this->Misc[misc_timer] % 5) ) 
						{
							//Make it flash
							this->CSet = flash_cset;
						}
						else this->CSet = this->Misc[misc_cset];
						break;
					}
				}
				
			}
			if ( this->Stun == 1 ) 
			{
				//time to explode
				eweapon e = Screen->CreateEWeapon(EW_SBOMBBLAST);
				e->Damage = pow;
				e->X = this->X; e->Y = this->Y;
				this->HP = -9999;
			}
			
			Waitframe();
		}
	}
}



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users