Jump to content
  • 0

Is it possible to add reg_value to an npc?


Question

Posted (edited)

For example: There are 2 npcs located at same map.. but the other npc is in an isolated same map like for example a tiny cell.. It's like a quest wherein.. 3 players are trying to do the quest at the same time but the problem is the npc only can entertain 1 player at a time. Since they're at the same map (NPC) and getuser won't help to check if there is trying to do the quest.. I want the 2 npc to communicate via a reg_value. If one player talks to an NPC he will warp it to the 2nd npc and then 2nd npc will raise the variable to 1. And if the other 2 players want to take the quest they can't since the 1st npc read the variable as one therefore there is a player still doing the quest..

 

 

Edited by Gnome

3 answers to this question

Recommended Posts

Posted (edited)

Use NPC variables attached to the "main" NPC in the quest:

- one to store the char_id of the character currently doing the quest

- another to store the quest step they're at

Then NPC 2 can use getvariableofnpc to check those variables in NPC 1.

prontera,155,180,0	script	quest_step1	910,{
	if (.char_id == 0) {
		// quest is open
		mes "Do you want to start this quest?"
		mes " ";
		if (select("Yes:No")==1) {
			if (.char_id) {
				mes "Too slow! Someone else already started the quest...";
			} else {
				set .char_id, getcharid(0);
				set .quest_endtime, gettimetick(2) + 300; // 300 seconds = 5 minutes
				set .quest_step, 1;
				initnpctimer "quest_step1";
				mes "^008000 STEP 1 Complete! ^000000";
				mes "Now, go talk to Step 2.";
			}
		}
	} else if (.char_id == getcharid(0)) {
		// in progress
		switch(.quest_step) {
		case 1:
			mes "You've already completed step 1.";
			mes "Proceed to step 2 -->";
			break;
		case 2:
			// other message to tell them they are "in progress"
			break;
		default:
			mes "Keep doing all the steps until you finish!";
			break;
		}
	} else {
		// in progress (another player is doing quest)
		mes "Another player is currently doing this quest.";
		mes "Please wait " + Time2Str(.quest_endtime);
	}
	close;
OnTimer300000:
	stopnpctimer;
	set .char_id, 0;
	set .quest_endtime, 0; // 300 seconds = 5 minutes
	set .quest_step, 0;
	end;
}
 
prontera,158,180,0	script	quest_step2	910,{
	if (getvariableofnpc(.char_id, "quest_step1") == 0) {
		// quest is open
		mes "To start the quest, first talk to Step 1.";
	} else if (getvariableofnpc(.char_id, "quest_step1") == getcharid(0)) {
		// in progress
		switch(getvariableofnpc(.quest_step, "quest_step1")) {
		case 1:
			set getvariableofnpc(.quest_step, "quest_step1"), 2;
			mes "^008000 STEP 2 Complete! ^000000";
			next;
			mes "All done  *_*";
			set getvariableofnpc(.char_id, "quest_step1"), 0;
			set getvariableofnpc(.quest_endtime, "quest_step1"), 0;
			set getvariableofnpc(.quest_step, "quest_step1"), 0;
			stopnpctimer "quest_step1"
			break;
		}
	} else {
		// in progress (another player is doing quest)
		mes "Another player is currently doing this quest.";
		mes "Please wait " + Time2Str(getvariableofnpc(.quest_endtime, "quest_step1"));
	}
	close;
}
Edited by Brian

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...