|
|
 |
 |
 |
 |
|
 |
 |
|
 |
 |
|
 |
|
Development::Development Forum for development topics and for those interested in EQEMu development. (Not a support forum) |

04-19-2009, 09:33 PM
|
Developer
|
|
Join Date: Dec 2007
Posts: 122
|
|
I might be missing something, but why mess with the database at all? What about structuring it something like:
quest::saylink(text,value)
and have the function return a link to a fictitious item. You could use your plan of using item values over 1,000,000, or maybe negative item values if you wanted to be sure of never interfering with anything. Then you could adjust the code to activate a ChannelMessageReceived function based on the value you entered.
So, for example quest::saylink("test",1) would create a link on the word "test." When you clicked it, it would send a message of SayLink1, or something along those lines. That way, you could have multiple saylinks in one quest without too much complexity. I won't have a chance to look at the source for a bit, but I have a basic idea of how it might be coded.
|
 |
|
 |

04-20-2009, 01:44 AM
|
Developer
|
|
Join Date: Dec 2007
Posts: 122
|
|
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.");
}
}
|
 |
|
 |
 |
|
 |

04-20-2009, 04:52 AM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
Thanks for the info
I had thought about doing something like that, but it wouldn't be quite as ideal as what I am wanting to do with it. Basically, I want to make the saylinks an option to players. So, if they prefer clicking the links, they can click them, but if they prefer to just type the phrase, they can do that as well. And, it wouldn't require any extra scripting to handle the saylinks or normal say messages. I know at least a few players who play almost solely with the keyboard and only ever have to touch their mouse when they are looting a corpse.
The idea you had would work fine, but it would make quest scripting a bit more involved, which is one of the main things I am trying not to do. If I can't get the way I am wanting to do it working, we could definitely put it in the way you have it coded though.
Here is the difference of what it would take to write the same exact quest to use your code as it would for what I am suggesting (including the option to /say the phrase):
Your idea:
Code:
my $test1 = quest::saylink("test,1");
sub EVENT_SAY {
if($text=~/Hail/i) {
quest::say("Would you like to $test1 a say link?");
}
if($text=~/SayLink1/) {
quest::say("The test was a success!");
}
if($text=~/test/i) {
quest::say("The test was a success!");
}
}
My idea:
Code:
my $test1 = quest::saylink("test");
sub EVENT_SAY {
if($text=~/Hail/i) {
quest::say("Would you like to $test1 a say link?");
}
if($text=~/test/i) {
quest::say("The test was a success!");
}
}
Not really a huge deal, but it would get tougher to manage if you have long scripts with lots of phrases and text.
I really appreciate the help on this though. I think it will be something cool to play with when it is all done. I bet players will be really surprised to see it when it first shows up on servers. And, I bet it isn't long before EQLive has something similar lol.
Last edited by trevius; 04-20-2009 at 02:12 PM..
|
 |
|
 |

04-20-2009, 07:39 AM
|
Sarnak
|
|
Join Date: Jan 2008
Posts: 47
|
|
What're you saying Trev? That we've had some great ideas that showed up on Live? Why, that just means SoE listens to its fanbase. 
|

04-20-2009, 12:04 PM
|
Developer
|
|
Join Date: Dec 2007
Posts: 122
|
|
Ok, that's a good point. You could also probably cram a second string into the space that's normally used for augments and that sort of thing. It would mean you're limited to just under 40 characters for the response string, but that doesn't seem like it would be a problem very often.
|
 |
|
 |

04-20-2009, 07:34 PM
|
 |
Developer
|
|
Join Date: Aug 2006
Location: USA
Posts: 5,946
|
|
I thought about using the augments section for handling the phrase, but coding that is out of my skill range. It would have to be able to take the string and then fill in the rest of the nulls after it to make sure that it builds the link properly. Then, after the link is clicked, it would need to have a way to take each of those fields and tie them together and then convert them back into a string.
If you know how to do that, I am sure 40 characters would be plenty for almost any scenario. That would probably be the best possible way to handle say links. By putting the string into the actual link, the item ID wouldn't matter at all. So, the item ID that the quest::saylink() command creates could be hard set to 999999 (or any other invalid item ID number) for all links it creates.
Also, an a related topic, I was playing with the code you posted to handle saylinks and was trying to get it to work where you only input the item ID, and have it create a normal item link from just that. There is already a quest command for quest::itemlink(), but that command causes the NPC to send a tell to the player with a link to the item. Something I have wanted for a long time is a very simple way to create an item link to an actual item that can be set as a variable for use in the middle of a say message. On Storm Haven, we currently have to do something like this to create an itemlink:
Code:
my $cloth_cap = sprintf("%c%06X%s%s%c",0x12,1001,"000000000000000000000000000000000000000","Cloth Cap",0x12);
sub EVENT_SAY {
if ($text =~/Hail/i) {
quest::say ("Here is a link to a $cloth_cap."); }
}
While that isn't overly complex to do, it would be nice if we could do something like this instead:
Code:
my $cloth_cap = quest::itemlink(1001);
sub EVENT_SAY {
if ($text =~/Hail/i) {
quest::say ("Here is a link to a $cloth_cap."); }
}
The way you wrote the quest::saylink() command above actually works nicely for this. But it could be simplified a bit more by having it do a GetItem() and then an item->name to automatically populate the name of the itemlink. I worked with what you wrote for a while last night, but everything I tried to do was crashing the zone lol. Not trying to derail this thread at all, but figured I would mention this since I worked on it a while last night.
|
 |
|
 |
 |
|
 |

04-21-2009, 11:04 AM
|
Developer
|
|
Join Date: Dec 2007
Posts: 122
|
|
I haven't gotten a chance to look at using the augments section to store anything yet, but I did come up with some code for storing a link as a perl variable. The syntax is just $var = quest::itemlink2(item id).
My source is way too messed up for a diff right now, but here's the changes I made for this. The total string, including all the link variables and stuff, is limited to 250 chars (totally arbitrary number) right now, so no ridiculously long item names.
questmgr.h add:
Code:
const char* ItemLink2(char* perltext, int item_id);
questmgr.cpp:
Code:
const char* QuestManager::ItemLink2(char* perltext, int item_id) {
const ItemInst* inst = database.CreateItem(item_id, 20, 99999, 99999, 99999, 99999, 99998);
if (!inst) return 0; // return an empty string if the item is invalid
char* link = 0;
char* tempstr = 0;
if (initiator->MakeItemLink(link, inst)) { // make a link to the item
MakeAnyLenString(&tempstr, "%c%s%s%c", 0x12, link, inst->GetItem()->Name, 0x12); // format the string that the client receives
strncpy(perltext, tempstr,250); // the perl string is only 250 chars, so make sure the link isn't too large
safe_delete_array(tempstr); // MakeAnyLenString() uses new, so clean up after it
}
safe_delete_array(link); // MakeItemLink() uses new also
return perltext;
}
perlparser.cpp:
Code:
XS(XS__ItemLink2);
XS(XS__ItemLink2) {
dXSARGS;
if (items != 1)
Perl_croak(aTHX_ "Usage: itemlink2(itemID)");
dXSTARG;
Const_char * RETVAL;
char text[250];
uint16 itemID;
itemID = (int)SvUV(ST(0));
RETVAL = quest_manager.ItemLink2(text, itemID);
sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
XSRETURN(1);
}
and at the bottom of perlparser add:
Code:
newXS(strcpy(buf, "itemlink2"), XS__ItemLink2, file);
By the way, the most likely cause of your zone crashes is in passing (char *) strings back and forth between functions. It's really easy to accidently write more to the char array than you allocated and overwrite other stuff on the stack. At least, that's what seemed to cause all of my problems.
|
 |
|
 |
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 12:19 PM.
|
|
 |
|
 |
|
|
|
 |
|
 |
|
 |