Thread: Say Links
View Single Post
  #6  
Old 04-20-2009, 01:44 AM
realityincarnate
Developer
 
Join Date: Dec 2007
Posts: 122
Default

I played around with the idea a little bit tonight, and here's what I've come up with as a first attempt.
Code:
Index: zone/client_packet.cpp
===================================================================
--- zone/client_packet.cpp	(revision 437)
+++ zone/client_packet.cpp	(working copy)
@@ -2163,8 +2166,17 @@
 
 	const Item_Struct* item = database.GetItem(ivrs->item_id);
 	if (!item) {
-		Message(13, "Error: The item for the link you have clicked on does not exist!");
-		return;
+		if (ivrs->item_id > 1000000)
+		{
+			char response[20];
+			sprintf(response,"SayLink%u",ivrs->item_id - 1000000);
+			this->ChannelMessageReceived(8, 1, 100, response);
+			return;
+		}
+		else {
+			Message(13, "Error: The item for the link you have clicked on does not exist!");
+			return;
+		}
 	}
 
 	ItemInst* inst = database.CreateItem(item, item->MaxCharges, ivrs->augments[0], ivrs->augments[1], ivrs->augments[2], ivrs->augments[3], ivrs->augments[4]);
@@ -7155,7 +7167,7 @@
 	if(!p_timers.Load(&database)) {
 		LogFile->write(EQEMuLog::Error, "Unable to load ability timers from the database for %s (%i)!", GetCleanName(), CharacterID());
 	}
-
+	
 #ifdef _EQDEBUG
 	printf("Dumping inventory on load:\n");
 	m_inv.dumpInventory();
Index: zone/perlparser.cpp
===================================================================
--- zone/perlparser.cpp	(revision 437)
+++ zone/perlparser.cpp	(working copy)
@@ -2446,7 +2446,31 @@
 	XSRETURN_UV(quantity);
 }
 
+XS(XS__SayLink);
+XS(XS__SayLink) {
+	dXSARGS;
+	if (items != 2)
+		Perl_croak(aTHX_ "Usage: saylink(text, saylinkID)");
+	dXSTARG;
 
+	Const_char * RETVAL;
+	char text[250];
+	uint16 ID;
+	
+	strcpy(text,(char *)SvPV_nolen(ST(0)));
+
+	ID = (int)SvUV(ST(1));
+	
+	RETVAL = quest_manager.SayLink(text,ID);
+
+	sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
+	XSRETURN(1);
+}
+
+
+
+
+
 /*
 This is the callback perl will look for to setup the
 quest package's XSUBs
@@ -2617,6 +2641,7 @@
 		newXS(strcpy(buf, "updatespawntimer"), XS__UpdateSpawnTimer, file);
 		newXS(strcpy(buf, "MerchantSetItem"), XS__MerchantSetItem, file);
 		newXS(strcpy(buf, "MerchantCountItem"), XS__MerchantCountItem, file);
+		newXS(strcpy(buf, "saylink"), XS__SayLink, file);
 
 	XSRETURN_YES;
 }
Index: zone/questmgr.cpp
===================================================================
--- zone/questmgr.cpp	(revision 437)
+++ zone/questmgr.cpp	(working copy)
@@ -1821,3 +1821,10 @@
 
 	return Quant;	// return the quantity of itemid (0 if it was never found)
 }
+
+const char * QuestManager::SayLink(char* text, uint16 value) {
+	char linktext[250];
+	sprintf(linktext,"%c%06X%s%s%c",0x12,1000000+value,"000000000000000000000000000000000000000",text,0x12);
+	strcpy(text,linktext);
+	return text;
+};
Index: zone/questmgr.h
===================================================================
--- zone/questmgr.h	(revision 437)
+++ zone/questmgr.h	(working copy)
@@ -197,6 +197,8 @@
 
 	void MerchantSetItem(int32 NPCid, int32 itemid, int32 quantity = 0);
 	int32 MerchantCountItem(int32 NPCid, int32 itemid);
+
+	const char* SayLink(char* text, uint16 value);
 	
 	//not in here because it retains perl types
 	//thing ChooseRandom(array_of_things)
It only does the Titanium formating at the moment, and it will break if there are ever legitimate item ids over 1 million, but I tested a couple of different things and it seems to do all right. There's not much in the way of error checking, so it'll probably crash the zone if anything too strange gets entered as parameters.

The syntax is quest::saylink(message,n)
And when the link is clicked, it sends a message "SayLinkn". Here was my simple test script:
Code:
my $test1 = quest::saylink("trying,1");
my $test2 = quest::saylink("forget,2");

sub EVENT_SAY {
  if($text=~/Hail/i) {
    quest::say("I've noticed that sometimes certain words I say just feel... different.  Should I keep $test1 to see what I can do with them, or just $test2 the whole thing?");
  }

  if($text=~/SayLink1/) {
    quest::say("You're right, I bet I can make something out of them.");
  }
  if($text=~/SayLink2/) {
    quest::say("I knew it was too much to hope for.");
  }
}
Reply With Quote