05-25-09, 09:11 AM | #1 |
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. |
|
05-25-09, 10:22 AM | #2 |
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. |
|
05-25-09, 11:02 AM | #3 | |
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
__________________
click HERE for the ultimate idiot test. |
||
05-25-09, 07:27 PM | #4 |
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. |
|
05-25-09, 08:19 PM | #5 | |
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 message = strtrim(message) local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD" for i=2, select(#, strsplit(" ",message)) do local new = select(i, strsplit(" ",message)) if not new then SendChatMessage(msg, chan, nil, player) return end if strlen(msg) + strlen(new) > 254 then SendChatMessage(msg, chan, nil, player) msg = "" end msg = msg .. " " .. new end end |
||
05-25-09, 08:36 PM | #6 |
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 FactDB.Count = FactDB.Count + 1 Facts_ShowFact() end 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 function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) sendchatMessage "/fact next" end end Well, Akryn beat me up, err, beat me to it.... and I'd trust them more than me, anyway. Last edited by Yhor : 05-25-09 at 08:38 PM. Reason: Akryn beat me up |
|
05-25-09, 08:52 PM | #7 | ||
|
|||
05-25-09, 08:58 PM | #8 |
Code:
end function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) FactDB.Count = FactDB.Count + 1 end end |
|
05-26-09, 03:15 AM | #9 | |
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? if msg == key then Facts_ShowFact(sender) FactDB.Count = FactDB.Count + 1 end end
|
||
05-26-09, 11:38 AM | #10 | |
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 message = strtrim(message) local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD" for i=2, select(#, strsplit(" ",message)) do local new = select(i, strsplit(" ",message)) if not new then SendChatMessage(msg, chan, nil, player) return end if strlen(msg) + strlen(new) > 254 then SendChatMessage(msg, chan, nil, player) msg = "" end msg = msg .. " " .. new end if msg and msg ~= "" and msg ~= " " then SendChatMessage(msg, chan, nil, player) end end |
||
05-26-09, 11:50 AM | #11 |
Code:
function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) FactDB.Count = FactDB.Count + 1 end end |
|
05-26-09, 12:37 PM | #12 | |||
ok i inserted the local function at the end of the addon so it now reads as:
Code:
if not FactDB then FactDB={" "} end local key = "fact" -- whispered command to get current fact function Facts_OnLoad() SLASH_FACTS1 = "/fact" SlashCmdList["FACTS"] = Facts_Command this:RegisterEvent("CHAT_MSG_WHISPER") end function Facts_Command(msg) if IsInGuild() then local cmd,newFact = Facts_GetCommand(msg) if cmd == "reset" then FactDB.Count = 1 end if cmd == "next" then FactDB.Count = FactDB.Count + 1 Facts_ShowFact() end if cmd == "new" then if newFact ~= "" then pos = table.getn(FactDB) + 1 FactDB[pos] = newFact else message("Please add a new fact after new") end end if cmd == "" then Facts_ShowFact() end end end function Facts_ShowFact(sender) if FactDB.Count > table.getn(FactDB) then FactDB.Count = 1 end local FactOfTheDay = FactDB[FactDB.Count] if sender then SendChatMessage("RANDOM FACT OF THE DAY !: "..FactOfTheDay, "WHISPER", nil, sender) else SendChatMessage("RANDOM FACT OF THE DAY !: "..FactOfTheDay, "GUILD") -- is the message printed before your fact end end function Facts_GetCommand(msg) -- seperate the command and the following string if msg then local a,b,c=strfind(msg, "(%S+)"); --contiguous string of non-space characters if a then return c, strsub(msg, b+2); else return ""; end end end function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) FactDB.Count = FactDB.Count + 1 end end local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything message = strtrim(message) local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD" for i=2, select(#, strsplit(" ",message)) do local new = select(i, strsplit(" ",message)) if not new then SendChatMessage(msg, chan, nil, player) return end if strlen(msg) + strlen(new) > 254 then SendChatMessage(msg, chan, nil, player) msg = "" end msg = msg .. " " .. new end if msg and msg ~= "" and msg ~= " " then SendChatMessage(msg, chan, nil, player) end end However im getting the error
Code:
Date: 2009-05-26 19:34:53 ID: 1 Error occured in: Global Count: 1 Message: ..\AddOns\Facts\Facts.lua line 74: unexpected symbol near ',' Debug: [C]: ? AddOns: Zoom, v Swatter, v5.5.4254 (WombatII) WowheadLooter, v30100 Ace2, v Ace3, v AucAdvanced, v5.5.4254 (WombatII) AucFilterBasic, v5.5.4254 (WombatII) AucFilterOutlier, v5.5.4254.2531 AucMatchUndercut, v5.5.4254.2531 AucStatClassic, v5.5.4254 (WombatII) AucStatHistogram, v5.5.4254 (WombatII) AucStatiLevel, v5.5.4254 (WombatII) AucStatSales, v5.5.4254.2842 AucStatWOWEcon, v5.5.4254.2530 AucUtilAHWindowControl, v5.5.4254.3311 AucUtilAppraiser, v5.5.4254.2530 AucUtilAskPrice, v5.5.4254.3175 AucUtilAutoMagic, v5.5.4254.3142 AucUtilCompactUI, v5.5.4254.2530 AucUtilEasyBuyout, v5.5.4254.3583 AucUtilItemSuggest, v5.5.4254.3108 AucUtilPriceLevel, v5.5.4254.2545 AucUtilScanButton, v5.5.4254.2530 AucUtilScanFinish, v5.5.4254.2530 AucUtilScanProgress, v5.5.4254.2530 AucUtilSearchUI, v5.5.4254.3655 AucUtilSimpleAuction, v5.5.4254.0 AucUtilVendMarkup, v5.5.4254.2530 AutoEmote, v Babylonian, v5.1.DEV.130 BagnonForever, v1.1.1 BagnonTooltips, v BankStack, vv13 BeanCounter, v5.5.4254 (WombatII) Bejeweled, v1.03b Buffet, v3.0.9.27 BulkMail2Inbox, v3.0.2 Cartographer, v2.0 Combuctor, v2.1.0 CombuctorSets, v Configator, v5.1.DEV.130 Cutup, v Deathstimator, v0.6 DebugLib, v5.1.DEV.130 DoTimer, v4.3.1 DurabilityCount, v1.2 Facts, v1.0 SlideBar, v5.5.4254 (WombatII) Stubby, v5.5.4254 (WombatII) (ck=56c)
Last edited by playsatan : 05-26-09 at 12:48 PM. Reason: Testing |
||||
05-26-09, 04:32 PM | #13 | |
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 Code:
if not FactDB then FactDB={" "} end local key = "fact" -- whispered command to get current fact function Facts_OnLoad() SLASH_FACTS1 = "/fact" SlashCmdList["FACTS"] = Facts_Command this:RegisterEvent("CHAT_MSG_WHISPER") end function Facts_Command(msg) if IsInGuild() then local cmd,newFact = Facts_GetCommand(msg) if cmd == "reset" then FactDB.Count = 1 end if cmd == "next" then FactDB.Count = FactDB.Count + 1 Facts_ShowFact() end if cmd == "new" then if newFact ~= "" then pos = table.getn(FactDB) + 1 FactDB[pos] = newFact else message("Please add a new fact after new") end end if cmd == "" then Facts_ShowFact() end end end local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything message = strtrim(message) local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD" for i=2, select("#", strsplit(" ",message)) do local new = select(i, strsplit(" ",message)) if not new then SendChatMessage(msg, chan, nil, player) return end if strlen(msg) + strlen(new) > 254 then SendChatMessage(msg, chan, nil, player) msg = "" end msg = msg .. " " .. new end if msg and msg ~= "" and msg ~= " " then SendChatMessage(msg, chan, nil, player) end end function Facts_ShowFact(sender) if FactDB.Count > table.getn(FactDB) then FactDB.Count = 1 end local FactOfTheDay = FactDB[FactDB.Count] if sender then SendSplitMessages("RANDOM FACT OF THE DAY !: "..FactOfTheDay, sender) else SendSplitMessages("RANDOM FACT OF THE DAY !: "..FactOfTheDay) -- is the message printed before your fact end end function Facts_GetCommand(msg) -- seperate the command and the following string if msg then local a,b,c=strfind(msg, "(%S+)"); --contiguous string of non-space characters if a then return c, strsub(msg, b+2); else return ""; end end end function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) FactDB.Count = FactDB.Count + 1 end end |
||
05-26-09, 04:52 PM | #14 |
BTW, the above code does work, I just tested it.
|
|
05-26-09, 04:57 PM | #15 |
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 local key = "fact" -- whispered command to get current fact function Facts_OnLoad() SLASH_FACTS1 = "/fact" SlashCmdList["FACTS"] = Facts_Command this:RegisterEvent("CHAT_MSG_WHISPER") end function Facts_Command(msg) if IsInGuild() then local cmd,newFact = Facts_GetCommand(msg) if cmd == "reset" then FactDB.Count = 1 end if cmd == "next" then FactDB.Count = FactDB.Count + 1 Facts_ShowFact() end if cmd == "new" then if newFact ~= "" then pos = table.getn(FactDB) + 1 FactDB[pos] = newFact else message("Please add a new fact after new") end end if cmd == "" then Facts_ShowFact() end end end local function SendSplitMessages(message, player) --player is optional, name of the player to whisper -- assumes Guild chat if you don't send it anything message = strtrim(message) local msg, chan = strsplit(" ",message), player and "WHISPER" or "GUILD" for i=2, select("#", strsplit(" ",message)) do local new = select(i, strsplit(" ",message)) if not new then SendChatMessage(msg, chan, nil, player) return end if strlen(msg) + strlen(new) > 254 then SendChatMessage(msg, chan, nil, player) msg = "" end msg = msg .. " " .. new end if msg and msg ~= "" and msg ~= " " then SendChatMessage(msg, chan, nil, player) end end function Facts_ShowFact(sender) if FactDB.Count > table.getn(FactDB) then FactDB.Count = 1 end local FactOfTheDay = FactDB[FactDB.Count] if sender then SendSplitMessages("RANDOM FACT !: "..FactDB[math.random(1, #FactDB)], sender) else SendSplitMessages("RANDOM FACT OF THE DAY !: "..FactOfTheDay) -- is the message printed before your fact end end function Facts_GetCommand(msg) -- seperate the command and the following string if msg then local a,b,c=strfind(msg, "(%S+)"); --contiguous string of non-space characters if a then return c, strsub(msg, b+2); else return ""; end end end function Facts_OnEvent(msg, sender) -- has someone whispered me the key command? if msg == key then Facts_ShowFact(sender) end end |
|
05-26-09, 05:41 PM | #16 |
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 ID: 3 Error occured in: Global Count: 254 Message: SendChatMessage(): Chat message must be UTF-8 text Debug: [C]: ? [C]: ? [C]: SendChatMessage() Facts\Facts.lua:53: Facts\Facts.lua:37 Facts\Facts.lua:63: Facts_ShowFact() Facts\Facts.lua:83: Facts_OnEvent() [string "*:OnEvent"]:1: [string "*:OnEvent"]:1 AddOns: Zoom, v Swatter, v5.5.4254 (WombatII) WowheadLooter, v30100 Ace2, v Ace3, v AucAdvanced, v5.5.4254 (WombatII) AucFilterBasic, v5.5.4254 (WombatII) AucFilterOutlier, v5.5.4254.2531 AucMatchUndercut, v5.5.4254.2531 AucStatClassic, v5.5.4254 (WombatII) AucStatHistogram, v5.5.4254 (WombatII) AucStatiLevel, v5.5.4254 (WombatII) AucStatSales, v5.5.4254.2842 AucStatWOWEcon, v5.5.4254.2530 AucUtilAHWindowControl, v5.5.4254.3311 AucUtilAppraiser, v5.5.4254.2530 AucUtilAskPrice, v5.5.4254.3175 AucUtilAutoMagic, v5.5.4254.3142 AucUtilCompactUI, v5.5.4254.2530 AucUtilEasyBuyout, v5.5.4254.3583 AucUtilItemSuggest, v5.5.4254.3108 AucUtilPriceLevel, v5.5.4254.2545 AucUtilScanButton, v5.5.4254.2530 AucUtilScanFinish, v5.5.4254.2530 AucUtilScanProgress, v5.5.4254.2530 AucUtilSearchUI, v5.5.4254.3655 AucUtilSimpleAuction, v5.5.4254.0 AucUtilVendMarkup, v5.5.4254.2530 AutoEmote, v Babylonian, v5.1.DEV.130 BagnonForever, v1.1.1 BagnonTooltips, v BankStack, vv13 BeanCounter, v5.5.4254 (WombatII) Bejeweled, v1.03b Buffet, v3.0.9.27 BulkMail2Inbox, v3.0.2 Cartographer, v2.0 CartographerBattlegrounds, v2.0 CartographerCoordinates, v2.0 CartographerFoglight, v2.0 CartographerGroupColors, v2.0 CartographerGuildPositions, v2.0 CartographerInstanceLoot, v2.0 CartographerInstanceMaps, v2.0 CartographerInstanceNotes, v2.0 CartographerLookNFeel, v2.0 CartographerNotes, v2.0 CartographerPOI, v2.0 CartographerWaypoints, v2.0 CartographerZoneInfo, v2.0 Combuctor, v2.1.0 CombuctorSets, v Configator, v5.1.DEV.130 Cutup, v Deathstimator, v0.6 DebugLib, v5.1.DEV.130 DoTimer, v4.3.1 DurabilityCount, v1.2 Enchantrix, v5.5.4254 (WombatII) Facts, v1.0 FBMergeDatabase, v0.9.4g FBOutfitDisplayFrame, v0.9.4g FBTrackingFrame, v0.9.4g FishingBuddy, v0.9.7d FlightMap, v GatherMate, vv1.18 GatherTogether, vr0.5.1 GatherTogetherGathererSupport, vr0.5.1 GatherTogetherGatherMateSupport, vr0.5.1 GatherTogetherMetaMapSupport, vr0.5.1 GoGoMount, v0003010300 HatRack, v1.2 Informant, v5.5.4254 (WombatII) LevelSnap, v1.31 LightHeaded, v288 Multishot, v0.6 NoteIt, v NotesUNeed, v6.57.30100 NugMiniPet, v1.3.2b OPie, v OptionlessHouse, v Outfitter, v4.7.3 Pawn, v1.1.11 Peggle, v1.01a Poisoner, v3.0 ProfessionsBook, v3.0.3 Quartz, v1.0 QuartzInterrupt, v1.0 QuartzLatency, v1.0 QuartzPlayer, v1.0 QuartzRange, v1.0 QuartzTradeskill, v1.0 ReagentRestocker, v0.9c RecipeBook, v ReverseEngineering, v3.1 SexyMap, v SlideBar, v5.5.4254 (WombatII) SpamMeNot, v3.0 SpeedyGonzales, v1.3.0 Stubby, v5.5.4254 (WombatII) TooManyAddons, v TrinketMenu, v Unlock, v WhoHas, v3.0.2 (ck=ac4) 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. Last edited by playsatan : 05-26-09 at 05:46 PM. Reason: Included data base |
|
05-26-09, 06:11 PM | #17 |
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 |
|
05-27-09, 01:26 AM | #18 |
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 ? |
|
05-27-09, 05:49 AM | #19 |
It might be as easy as saving it with ASCII encoding? Or opening it in Notepad and telling it to convert to plain text.
|
|
05-28-09, 01:52 PM | #20 | |
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. |
||
WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Random fact addon update |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|