Jump to content
  • 0
Pink Buddha

Fountain-esque, need some tips or advice

Question

After a week of trial and mostly errors, and trying to optimize the code. I could say I was finally happy with these results. This is my take on creating a healing/regenerative fountain on main towns, and since I haven't dabbled in map editing yet I decided to create an NPC Goddess  and a Bard instead. Currently I only added this feature on Payon.

What I want is, If there are other ways I could optimize the code, i.e. variable types and usage, redundant code blocks or such, I am open to any opinions and criticism. It's been a week since I started relearning coding so I'd be happy if I could have your opinions and such.

// Goddess NPC and Bard NPC(on the leftside) should have atleast 3 cells difference in x-axis and with the same y-axis for the regen area to exactly merge	
payon,131,232,4	script	Goddess Elia	624,{
	OnInit:
	callfunc "regenHigh";	
}	

payon,128,232,4	script	Bard Mikhael	647,{
	OnInit:
	callfunc "regenLow";		
}

function	script	regenLow	{

	getmapxy( .mapn$, .mapx, .mapy, BL_NPC, strnpcinfo(0));	
	set .hrange, 20;
	freeloop(1);
	while (1) {
		specialeffect 793;
		if (getareaunits(BL_PC, .mapn$, (.mapx-.hrange+3), (.mapy-.hrange), (.mapx+.hrange+3), (.mapy+.hrange)) >=1) {
			areapercentheal .mapn$ , (.mapx-.hrange+3), (.mapy-.hrange), (.mapx+.hrange+3), (.mapy+.hrange), 1, 1;
			addrid(4, 0, (.mapx-.hrange+3), (.mapy-.hrange), (.mapx+.hrange+3), (.mapy+.hrange));
			if ( Hp > 0 ) {
				if (Hp != MaxHp) {
				specialeffect2 793;					
				}
			}
			detachrid;
		}
		sleep 1600;
	}
	end;
	freeloop(0);	
}

function	script	regenHigh	{	

	getmapxy( .mapn$, .mapx, .mapy, BL_NPC, strnpcinfo(0));
	set .hrange, 20;
	freeloop(1);
	while (1) {
		specialeffect 514;
		specialeffect 796;
		specialeffect 800;
		if (getareaunits(BL_PC, .mapn$, (.mapx-.hrange), (.mapy-.hrange), (.mapx+.hrange), (.mapy+.hrange)) >=1) {		
			areapercentheal .mapn$ , (.mapx-.hrange), (.mapy-.hrange), (.mapx+.hrange), (.mapy+.hrange), 8, 8;
			addrid(4, 0, (.mapx-.hrange), (.mapy-.hrange), (.mapx+.hrange), (.mapy+.hrange));
			if ( Hp > 0 ) {
				if (Hp != MaxHp) {
				specialeffect2 572;	
				}
			}
			detachrid;			
		}
		sleep 20000;
	}
	end;
	freeloop(0);	
}

//	specialeffect 408;		// <- overkill effect
//	specialeffect2 332;		// <- it had an audio
//	specialeffect2 310;		// <- green bubbles
//	specialeffect2 800;		// <- Red Pillar

 

What it does: 

It heals players that are not dead near the NPCs. For two different ticks, one being every 1.6s and the other being every 20 seconds. I thought it is a good alternative to Healer NPC for lowrate servers(as I plan to make a Healer which is count based that resets daily, and you need to pay if counter is 0). I'm just gonna add it in a few main towns to encourage player interaction.

Features I plan to add to this is that the NPCs will take up donations(zeny or etc items) to increase the healing rate per second, or probably reduced the tick rate  of healing. (yay, more variables that I'm having trouble on what to use best, based on what situations) The donations can come from multiple players and stacks accordingly. The increased healing rate or tick rate only persists on the donated NPC, and not on all the fountains( goddess duplicates in my case) server wide. This increase would probably last for a whole day.

Another is to add a healing constant(I'm planning on changing the renewal health formula, average players at max level would probably have 400k health), the lower health you have, the lesser the time it needs for you to heal fully.

It would be nice if you guys could give me your opinions on where should I go from here.

 

Edited by nasaankaalex
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

Try below script:

payon,131,232,4	script	Goddess Elia	624,{
	OnTimer1600:
		callfunc "regen", 1;
		initnpctimer;
		end;
	
	OnInit:
		initnpctimer;
		end;
}	

payon,128,232,4	script	Bard Mikhael	647,{
	OnTimer20000:
		callfunc "regen", 0;
		initnpctimer;
		end;
	
	OnInit:
		initnpctimer;
		end;
}

function	script	regen	{
	[email protected] = getarg(0, 0); // 0 - low | 1 - high
	[email protected] = 20;
	[email protected] = [email protected] ? 1 : 8;
	
	getmapxy [email protected]$, [email protected], [email protected], BL_NPC, strnpcinfo(1);
	
	specialeffect 514;
	specialeffect 796;
	specialeffect 800;
	
	[email protected] = getareaunits(BL_PC, [email protected]$, ([email protected] - ([email protected] + 3)), [email protected] - [email protected], ([email protected] + ([email protected] + 3)), [email protected] + [email protected], [email protected]);
	
	if ([email protected] > 0) {
		for ([email protected] = 0; [email protected] < [email protected]; [email protected]++) {
			if (attachrid([email protected][[email protected]])) {
				if (Hp && (Hp != MaxHp)) {
					specialeffect2 312;
					percentheal [email protected], [email protected];
				}
				detachrid;
			}
		}
	}
	
	return;
}

Same result but I removed unnecessary executions

 

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.