PDA

View Full Version : [Lua] Quiz NPC (Included SQL)


Alvanaar
04-23-2009, 08:08 AM
This here is a Lua quiz NPC script I made. The entry ID for the NPC is 55555.
Once the player successfully answers all the questions correctly, they receive a buff and an item (they can only receive one of the item no matter how many times they do the quiz).
You'll need to edit the questions and answers, it's pretty self-explanatory!

http://i603.photobucket.com/albums/tt118/Alvanaar/NOOB-PROOFGUARANTEE.png

-- Random Quiz NPC
-- Scripted by Alvanaar for AC-Web
--
-- Edit what is needed to be edited.
--
-- Feel free to modify and redistribute, however, please leave the original credits!

function Quiz_OnGossip(unit, event, player)
unit:GossipCreateMenu(700, player, 0)
unit:GossipMenuAddItem(5, "|cFF00008B>>>>>[SERVER NAME]<<<<<", 1, 0)
unit:GossipMenuAddItem(5, "|cFFFF0000---------------------------", 2, 0)
unit:GossipMenuAddItem(0, "Question 1", 3, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 4, 0)
unit:GossipMenuAddItem(5, "Correct answer", 5, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 6, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 7, 0)
unit:GossipSendMenu(player)
end

function Quiz_Questions(unit, event, player, code, intid, id)
if (intid == 4) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Nope...")
end

if (intid == 6) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Incorrect.")
end

if (intid == 7) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Wrong!")
end

if (intid == 5) then
unit:GossipCreateMenu(701, player, 0)
unit:GossipMenuAddItem(0, "Question 2", 8, 0)
unit:GossipMenuAddItem(5, "Correct answer", 9, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 10, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 11, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 12, 0)
unit:GossipSendMenu(player)
end

if (intid == 10) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Noo...")
end

if (intid == 11) then
player:GossipComplete()
unit:SendChatMesage(12, 0, "Wrong answer!")
end

if (intid == 12) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Uh-uh...")
end

if (intid == 9) then
unit:GossipCreateMenu(702, player, 0)
unit:GossipMenuAddItem(0, "Question 3", 13, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 14, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 15, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 16, 0)
unit:GossipMenuAddItem(5, "Correct Answer", 17, 0)
unit:GossipSendMenu(player)
end

if (intid == 14) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "That's not the right answer!")
end

if (intid == 15) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Sadly, that's wrong.")
end

if (intid == 16) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Incorrect answer.")
end

if (intid == 17) then
unit:GossipCreateMenu(703, player, 0)
unit:GossipMenuAddItem(0, "Question 4", 18, 0)
unit:GossipMenuAddItem(5, "Correct answer", 19, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 20, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 21, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 22, 0)
unit:GossipSendMenu(player)
end

if (intid == 20) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Umm, nope.")
end

if (intid == 21) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Incorrect answer!")
end

if (intid == 22) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "No, no, no!")
end

if (intid == 19) then
unit:GossipCreateMenu(704, player, 0)
unit:GossipMenuAddItem(0, "Question 5", 23, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 24, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 25, 0)
unit:GossipMenuAddItem(5, "Correct answer", 26, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 27, 0)
unit:GossipSendMenu(player)
end

if (intid == 24) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Haha, wrong!")
end

if (intid == 25) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Nah, incorrect...")
end

if (intid == 27) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Nope, not the right answer.")
end

if (intid == 26) then
unit:GossipCreateMenu(705, player, 0)
unit:GossipMenuAddItem(0, "Question 6", 28, 0)
unit:GossipMenuAddItem(5, "Correct Answer", 29, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 30, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 31, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 32, 0)
unit:GossipSendMenu(player)
end

if (intid == 30) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Incorrect!")
end

if (intid == 31) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Sorry, that's wrong.")
end

if (intid == 32) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Nooo, wrong answer!!")
end

if (intid == 29) then
unit:GossipCreateMenu(706, player, 0)
unit:GossipMenuAddItem(0, "Question 7", 32, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 33, 0)
unit:GossipMenuAddItem(5, "Correct answer", 34, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 35, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 36, 0)
unit:GossipSendMenu(player)
end

if (intid == 33) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "Definitely not!")
end

if (intid == 35) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "That answer isn't right.")
end

if (intid == 36) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "NO! Wrong...")
end

if (intid == 34) then
unit:GossipCreateMenu(707, player, 0)
unit:GossipMenuAddItem(0, "Question 8", 37, 0)
unit:GossipMenuAddItem(5, "Correct Answer", 38, 0)
unit:GossipMenuAddItem(5, "Wrong answer", 39, 0)
unit:GossipSendMenu(player)
end

if (intid == 39) then
player:GossipComplete()
unit:SendChatMessage(12, 0, "WRONG!")
end

if (intid == 38) then
if player:GetItemCount(40000) < 1 then
player:AddItem(40000, 1)
end
unit:FullCastSpellOnTarget(15366, player)
player:SendAreaTriggerMessage("Congratulations, you won!")
player:SendBroadcastMessage("Congratulations, you won!")
unit:SendChatMessage(12, 0, "Well done! Enjoy your reward...")
player:GossipComplete()
end
end


RegisterUnitGossipEvent(55555, 1, "Quiz_OnGossip")
RegisterUnitGossipEvent(55555, 2, "Quiz_Questions")

Change the blue numbers to the spell ID of the reward buff you want (or leave it as Songflower Serenade - Spell - World of Warcraft (http://www.wowhead.com/?spell=15366))

Change the green numbers to the reward item ID.

Change the "Question 1", "Question 2" and so on, to the questions.

Change the "Wrong answer" options to wrong answers to the questions (hope you could work that out by yourself).

Change the "Correct answer" options to the correct answers to the questions.

Save the script as a .lua file and place it in your "scripts" folder.

Execute this SQL into your database...
insert into `creature_names` (`entry`, `name`, `subname`, `info_str`, `Flags1`, `type`, `family`, `rank`, `unk4`, `spelldataid`, `male_displayid`, `female_displayid`, `male_displayid2`, `female_displayid2`, `unknown_float1`, `unknown_float2`, `civilian`, `leader`)
values ('55555', "Quizererer", "The Quiz Master", '', '0', '10', '0', '1', '0', '0', '7769', '0', '0', '0', '1', '1', '0', '0');

insert into `creature_proto` (`entry`, `minlevel`, `maxlevel`, `faction`, `minhealth`, `maxhealth`, `mana`, `scale`, `npcflags`, `attacktime`, `attacktype`, `mindamage`, `maxdamage`, `can_ranged`, `rangedattacktime`, `rangedmindamage`, `rangedmaxdamage`, `respawntime`, `armor`, `resistance1`, `resistance2`, `resistance3`, `resistance4`, `resistance5`, `resistance6`, `combat_reach`, `bounding_radius`, `auras`, `boss`, `money`, `invisibility_type`, `death_state`, `walk_speed`, `run_speed`, `fly_speed`, `extra_a9_flags`, `spell1`, `spell2`, `spell3`, `spell4`, `spell_flags`, `modImmunities`)
values ('55555', '80', '80', '7', '175000', '175000', '125000', '1', '1', '3000', '0', '3500', '3500', '0', '0', '0', '0', '300000', '17500', '0', '0', '0', '0', '0', '0', '0', '0', "0", '0', '50000', '0', '0', '2.50', '8.00', '14.00', '0', '0', '0', '0', '0', '0', '0');


...and reload your server

If you have any questions, please ask away...

Alvanaar

Sikilde
04-23-2009, 09:55 AM
Looks cool! +rep!

Alvanaar
04-23-2009, 10:34 AM
Thanks!! :)

*bump*

Coreyduffel
04-23-2009, 03:11 PM
Bump , Looks good =)

Alvanaar
04-23-2009, 11:49 PM
Thanks, Corey.

:)

Coreyduffel
04-24-2009, 12:15 AM
No Problem =)

Ill be sure to give ya rep =).

Alvanaar
04-24-2009, 12:22 AM
Damnit I've given out too much rep. I will + rep back. You didn't need to ask!

bump

Coreyduffel
04-24-2009, 12:26 AM
Hehe =]

Alvanaar
04-24-2009, 01:31 AM
*bump*

stoneharry
04-24-2009, 06:33 AM
Looks nice, very similar to mine. Now bring the math.random command into use to randomise questions :)

Alvanaar
04-24-2009, 06:49 AM
I could use math.random... In fact, I might just do that. I won't right now.
:P

Alvanaar

lordcranberry3
04-24-2009, 10:19 PM
gj +rep

Alvanaar
04-24-2009, 10:51 PM
Thank you. :P

Warlord777
07-16-2010, 11:20 PM
im pretty sure everyone has this....comes with almost every repack and its already been released many times

Cronic
07-16-2010, 11:48 PM
^ \faildesk does not dumbass many repacks here ive seen dont have it like 99%