Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Quests

Archive::Quests Archive area for Quests's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 01-11-2004, 06:22 AM
Valdain
Fire Beetle
 
Join Date: Feb 2003
Location: WI
Posts: 20
Default NPC and Player Flags Code Fix for Perl

Here are the code snippets for getting both player and npc flag functions working correctly. Since it looks like our perl functions can't return a value (or at least I don't know how to!) we need to add a new exported variable: returnflag. This will allow flagcheck to retrieve the flag's value.

In parser.cpp replace the "flagnpc" if-block with:
Code:
			else if (!strcmp(strlwr(command),"flagnpc")) { 
				int8 tmpFlagNum = atoi(arglist[0]);
				int8 tmpFlagVal = atoi(arglist[1]);
				if(tmpFlagNum >= 0 && tmpFlagNum < 60)								
				{
					if (other)
					  other->flag[tmpFlagNum] = tmpFlagVal;
				}
				else {
					cout << "[SCRIPT ERROR](flagnpc): A flag was requested that was not in the correct range." << endl;
				}
			}
Replace the "flagclient" if-block with:
Code:
			else if (!strcmp(strlwr(command),"flagclient")) {//Valdain - fixed command name
				int8 tmpFlagNum = atoi(arglist[0]);
				int8 tmpFlagVal = atoi(arglist[1]);
				if(tmpFlagNum >= 0 && tmpFlagNum < 60)								
				{
					if (mob && mob->IsClient())
						mob->CastToClient()->flag[tmpFlagNum] = tmpFlagVal;
				}
				else{
					cout << "[SCRIPT ERROR](flagclient): A flag was requested that was not in the correct range." << endl;
				}
			}
Replace the "flagcheck" if-block with:
Code:
			else if (!strcmp(strlwr(command),"flagcheck")) {
				int8 tmpFlagNum1 = atoi(arglist[0]);			//Valdain
				int8 tmpFlagNum2 = atoi(arglist[1]);
				if(tmpFlagNum1 >= 0 && tmpFlagNum1 < 60)								
				{
					if(tmpFlagNum2==0)	//Client Flag
					{
                        if(other && mob && mob->IsClient())
							other->returnflag = mob->CastToClient()->flag[tmpFlagNum1];
					}
					else if(tmpFlagNum2==1) //NPC Flag
					{
                        if(other)
							other->returnflag = other->flag[tmpFlagNum1];
					}
					else
						cout << "[SCRIPT ERROR](flagcheck): tmpFlagNum2 wasn't 0 or 1!" << endl;
				}
				else {
					cout << "[SCRIPT ERROR(]flagcheck): A flag was requested that was not in the correct range." << endl;
				}
			}
Next, in mob.h we need to add:
Code:
	bool			CombatRange(Mob* other);
	int8			flag[60];
--->>>	int8			returnflag; //Valdain - Flag used to store value for flagcheck
Those take care of getting the core functions working. Now for the additions to the perl stuff.

In embparser.cpp in PerlembParser::Event:
Code:
	if (npcmob)
	{
		ExportVar(packagename.c_str(), "mname", npcmob->GetName());
// MYRA - added vars $mobid & $mlevel per Eglin
		ExportVar(packagename.c_str(), "mobid", itoa(npcmob->GetID())); 
		ExportVar(packagename.c_str(), "mlevel", itoa(npcmob->GetLevel())); 
//end Myra
//Valdain - added $returnflag
--->>>		ExportVar(packagename.c_str(), "returnflag", itoa(npcmob->returnflag)); 
	}
Usage

flagnpc and flagclient work the same:
Code:
quest::flagnpc(flag_number, flag_value);
quest::flagclient(flag_number, flag_value);
Where:
flag_number can be from 0 to 59
flag_value can be from 0 to 255

flagcheck now works!
Code:
quest::flagcheck(flag_number, flag_type);
Where:
flag_number can be 0 to 59
flag_type = 0 to check the player's flag or 1 to check the NPC's flags

Getting the results
Now that flagcheck works, we can get the results by getting the $returnflag variable.

Example:
Code:
sub EVENT_SAY() { 
   if ($text=~/hail/i){ 
	   quest::say("Greetings kind sir. Would you like to buy a [ring]?"); 
	   quest::flagnpc(1,1); 
           quest::flagcheck(1,1);  #check flag 1, on the NPC so we can use it next time 
   } 

   if ($text=~/ring/i){ 
	   if($returnflag == 1) 
           { 
                quest::say("It's a special ring they say.  Worth fair amount of money too."); 
		quest::flagnpc(1,2); 
		quest::flagcheck(1,1); #check flag for next time 
           } 
           else
	   { 
                quest::say("I don't know what you're talking about."); 
	   }
   } 
}
Limitations
One limitation I've noticed in testing is that you can't set or check a flag early in the event, then use flagcheck or returnflag to get that value later on in the event. You must follow the example and pre-get the value for next time.

Incorrect Example:
Code:
sub EVENT_SAY() { 
   if ($text=~/hail/i){
	quest::say("Greetings kind sir. Would you like to buy a [ring]?");
	quest::flagnpc(1,1); #set the flag to 1
   } 

quest::flagcheck(1,1);
quest::say("Flag 1: $returnflag");
}
$returnflag will be the value of the flag the LAST time the event was called. So Flag 1 may not return 1! Be sure to code your events to only check for flags on the next firing of the event like in the first example!

Update
flagcheck isn't working as well as I would have hoped. It appears that the perl-side variables aren't being update as quickly as they should be. I'm still working on a fix for it, but I'm still learning how the script system works. flagnpc and flagclient are working just as they should.

Hope that helps all you QuestBuilders out there!
-Valdain
Reply With Quote
  #2  
Old 01-11-2004, 09:58 PM
Lurker_005
Demi-God
 
Join Date: Jan 2002
Location: Tourist town USA
Posts: 1,671
Default

Nice work! I just added a link to this thread from my perl howto.

when I get some free time I'll test this out.
__________________
Please read the forum rules and look at reacent messages before posting.
Reply With Quote
  #3  
Old 01-12-2004, 01:24 AM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

Valdain, you should go into IRC and chat with Lethal/devn00b about developer access... You're code fixes are starting to get to long for my simple mind to merge in...
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #4  
Old 01-12-2004, 02:44 AM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

Quote:
Originally Posted by Trumpcard
to long for my simple mind to merge in...
Heh... "simple mind".... some of us have gotten to know you better than that. Although for a moment I did suffer a bit of envy about your humility (I got over it quickly)

BTW, I have lastname in NPC_types working and NPCs behaving better (less cases of it being to far away to attack when you are standing over it and/or vanishing).

I am going to sit on the NPC one until its right, but if you're interested I can post the lastname fix.
__________________
Maybe I should try making one of these servers...
Reply With Quote
  #5  
Old 01-12-2004, 04:09 AM
Trumpcard
Demi-God
 
Join Date: Jan 2002
Location: Charlotte, NC
Posts: 2,614
Default

You're another one that needs to just suck it up and request developer access!

Merge your own damn changes!
__________________
Quitters never win, and winners never quit, but those who never win and never quit are idiots.
Reply With Quote
  #6  
Old 01-12-2004, 05:03 AM
Scorpious2k's Avatar
Scorpious2k
Demi-God
 
Join Date: Mar 2003
Location: USA
Posts: 1,067
Default

Quote:
Originally Posted by Trumpcard
Merge your own damn changes!
OK, I'll take that as a "not at this time, thank you"
__________________
Maybe I should try making one of these servers...
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:48 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3