Random fact addon update
Hey lads and ladies,
a few years ago a great guy called tyrolit made an addon called random facts and since then i have been adding my own facts to the savedvariables file but one of the main things that bugs me is that i want to add some kind of automation to the original addon. let me explain what happens normally: i log on and type /fact to display the random fact of the day in the guild chat. if anyone missed it they can whisper me the word fact to get it send to them. What i want to add/ get added: Some one sends me a the word fact and it tells them a random fact except this time its a different one every time they whisper me. Other implementaions that would help: if possible to be able to send multiple whispers for facts that don't fit the 255 character limit. A filter you can toggle ,like spam sentry uses, that filters the display of facts when a person requests multiple facts over a short period of time. anyway, hope this isnt too much to ask. if you could just give me some help constructing the functions then that would be great too. |
To reply to whispers, you need to set up an event handler for CHAT_MSG_WHISPER, see:
http://www.wowwiki.com/Events/Communication http://www.wowwiki.com/Handling_events and then to reply: http://www.wowwiki.com/API_SendChatMessage To send multiple whispers at a time is just a loop, strsubbing 254 characters and sending each iteration. See http://www.wowwiki.com/API_strsub . You could make it smarter and search for the nearest previous space too although that would be slightly more complicated. Note that if you have anything that's *really* long, don't send more than 9 chat messages without adding a delay between them or you'll DC yourself. |
Quote:
The Random fact addon was my first and only attempt at getting into Lua programing cut short by me having a year away from the game. Your requests should be easy enough to implement, feel free to have ago your self if you wish as a learning experience for Lua, or anyone else for that matter. I may look into it my self when i get time ( away with work at present ). The addon allready responds to wispered requests, so to increment the replyed "Fact" for each person who wispers you would require :- - Storing the players name in a saved variable if it isn't already, with an index to the last fact they recieved. - after sending the latest fact incrementing the index and reseting if its reached the end. I've not looked at the addon for a very long time now so sorry I can't be of more help right now, I hopefully come home in the next week of so, or maybe I'll get some free time here to look at it. But have a go at it your self as well. Good luck and I'm glad you liked it :D |
a mention by the author himself ! im honored, i realy am.
as far as the "storing player names" bit goes, im not sure thats needed as the data base of facts i have so far exceeds over 2500 facts so it wont matter if the person who whispers me first wont get the same fact as the person wo whispered me second. also i have a very basic knowledge of lua (even less than tyrolit) so substrings mean almost nothing to me. i realy only have the concept of functions if im stretching it. |
Quote:
Code:
local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything |
I don't play WoW anymore, but looking at the .lua, it shouldn't be terribly hard. I have a couple questions, though.
1) With a database the size of 2500, I think there could be some nice potential for a "calendar base", plus optional 'random facts'. Meaning, the first 365 or 730 (if you want to do even/odd years) would be the actual "fact of the day" and the remainder would be the random facts. Just by looking at the .lua Code:
if cmd == "next" then 2) Could it be as simple as adding a -sendchatMessage "/fact next"- after each whisper you respond to? You would lose the current fact of the day for those who missed it, and if you wanted to fetch it, it may prove to be a pain, if database facts are unassigned. It would only advance after the first person who whispers you, though. It also may be as simple as "/fact next -1", assuming that is a valid command (I can't test, if I could, a lot of this tl;DR would be shorter). If number 2) is fine, try editing the .lua in the last few lines to this..(remember to backup your working version, if you are forgetful. Code:
end Well, Akryn beat me up, err, beat me to it.... and I'd trust them more than me, anyway. |
Quote:
Quote:
|
Code:
end Quote:
|
ok i inserted this into the code and it seems to have done the trick
Code:
function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? Quote:
|
Quote:
Also, it should actually be this...still haven't tested it though :) Code:
local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything |
Code:
function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? |
ok i inserted the local function at the end of the addon so it now reads as:
Code:
However im getting the error Quote:
Code:
Date: 2009-05-26 19:34:53 Quote:
Quote:
|
Quote:
The function needs to be *above* where you call it, and you also do have to actually call it at some point. The calls to SendChatMessage...eh I'll just do it, see below... By the way this function could be written a lot better...if nothing else it shouldn't keep calling strsplit...it shouldn't make any noticeable difference but maybe if you feel like it some day you can fix it up :p Code:
if not FactDB then FactDB={" "} end |
BTW, the above code does work, I just tested it.
|
Although, here's an update that doesn't increment the FOTD every whisper but still whispers random facts:
Code:
if not FactDB then FactDB={" "} end |
1 Attachment(s)
you my man are a ledgend, i just tested it (after whispering myself well over 100 times) and i was able to print a fact over 255 characters long !
how ever i came across one error that concerned the data base. Code:
Date: 2009-05-27 00:01:18 i can upload the fact data base if needed but im not sure if it would help as im going to do a revamp on it. the reason i bring this up is so i know what to avoid when rebuilding the data base. |
Glad you got it working. Yeah there are a lot of weird characters in your DB file, for example the (presumably supposed to be quote marks?) around PREDATOR in:
JeanClaude Van Damme was the alien in the original ‘PREDATOR’in almost all the jumping and climbing scenes. edit: Oh yeah they are...Firefox renders them properly as quotes on the actual forum page, but it would probably be best to just do a global replace on them to ' s |
right, is there any website or better yet a compiler that can help me with that ?
im not sure my SciTE Version 1.70 is as usful as it once was. unless its just a setting to show all the lines that would be problematic ? |
It might be as easy as saving it with ASCII encoding? Or opening it in Notepad and telling it to convert to plain text.
|
Quote:
opening the facts.lua file with note pad and saving as a text document type. doing the same thing except while saving choosing UTF-8 in the encoding drop down box. " " choosing unicode in the encoding drop down menu. " " choosing ANSI in the encoding drop down menu. changing the language in SciTE to text. changing the encoding in SciTE to UTF-8. thats all i can think of. also when i look over the facts data base they all seem to be ok. all facts that use films or something with double quotation marks ( " ) have been replaced with single quotation marks ( ' ). also if its just alien characters then whats wrong with the following line in the data base : Code:
"The Ecuadorian poet, José Olmedo, has a statue in his honour in his home country. But, unable to commission a sculptor, due to limited funds, the government brought a secondhand statue .. Of the English poet Lord Byron.", -- [613] tis odd. |
All times are GMT -6. The time now is 10:02 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI