Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SEUp = {}
- --[[
- Credits:
- Foereaper - the base script, idea and dialog
- Rochet2 - recoded the script, fixed any bugs noted, made the script be able to run at more than one place etc.
- Neglected - support :3
- ]]
- -- Not usable in instances! Only use in normal maps and you should be able to use it in multiple locations at once.
- -- It is suggested to keep quest NPC's far away from each other or to reduce the range:
- SEUp.Distance = 50 -- yards
- -- Settings:
- SEUp.Quest = 27000 -- Quest Entry
- SEUp.Quest_NPC = 190000 -- Questgiver Entry
- -- NPC entries we can use as targets, currently all training dummies. (in 50 yards by default)
- SEUp.Target_list = {32667, 32666, 32546, 32545, 32543, 32542, 32541, 31146, 31144, 31143, 30527, 24792, 17578}
- SEUp.Quest_Item = 1046 -- Item Entry. It is not suggested to change this. It is currently fine, unless it is already taken.
- -- Do not touch these!
- SEUp.QuestFailEvent = {}
- SEUp.PlayerData = {}
- --[[ -- Remove this line to use the deleting code and then do reloadscripts or restart server.
- -- Deleting code for testing and clean execute purposes.
- WorldDBQuery("DROP TABLE IF EXISTS `shootemup`;")
- WorldDBQuery("DELETE FROM `quests` WHERE `entry`="..SEUp.Quest..";")
- WorldDBQuery("DELETE FROM `items` WHERE `entry`="..SEUp.Quest_Item..";")
- WorldDBQuery("DELETE FROM `creature_proto` WHERE `entry`="..SEUp.Quest_NPC..";")
- WorldDBQuery("DELETE FROM `creature_names` WHERE `entry`="..SEUp.Quest_NPC..";")
- WorldDBQuery("DELETE FROM `creature_quest_finisher` WHERE `id`="..SEUp.Quest_NPC.." AND `quest`="..SEUp.Quest..";")
- WorldDBQuery("DELETE FROM `creature_quest_starter` WHERE `id`="..SEUp.Quest_NPC.." AND `quest`="..SEUp.Quest..";")
- -- ]]
- for i = 1, #SEUp.Target_list do
- if(WorldDBQuery("SELECT 1 FROM `creature_names` WHERE `Entry` = "..SEUp.Target_list[i]) == nil) then
- error("[Shoot 'Em Up]: ERROR, unexisting NPC entry in the Target_list! Script execution terminated.")
- end
- end
- if(WorldDBQuery("SHOW TABLES LIKE 'shootemup'") == nil and WorldDBQuery("SELECT 1 FROM `quests` WHERE `entry` = "..SEUp.Quest.." OR (SELECT 1 FROM `creature_names` WHERE `entry` = "..SEUp.Quest_NPC..") OR (SELECT 1 FROM `creature_proto` WHERE `entry` = "..SEUp.Quest_NPC..") OR (SELECT 1 FROM `items` WHERE `entry` = "..SEUp.Quest_Item..") LIMIT 1") ~= nil) then
- error("[Shoot 'Em Up]: ERROR, not able to insert quest or questgiver. Duplicate entries detected. Please check the entries and retry. Script execution terminated.")
- elseif(WorldDBQuery("SHOW TABLES LIKE 'shootemup'") == nil) then
- WorldDBQuery("INSERT INTO items (entry, class, subclass, field4, name1, displayid, quality, flags, faction, buyprice, sellprice, inventorytype, allowableclass, allowablerace, itemlevel, requiredlevel, RequiredSkill, RequiredSkillRank, RequiredSpell, RequiredPlayerRank1, RequiredPlayerRank2, RequiredFaction, RequiredFactionStanding, `Unique`, maxcount, ContainerSlots, itemstatscount, stat_type1, stat_value1, stat_type2, stat_value2, stat_type3, stat_value3, stat_type4, stat_value4, stat_type5, stat_value5, stat_type6, stat_value6, stat_type7, stat_value7, stat_type8, stat_value8, stat_type9, stat_value9, stat_type10, stat_value10, ScaledStatsDistributionId, ScaledStatsDistributionFlags, dmg_min1, dmg_max1, dmg_type1, dmg_min2, dmg_max2, dmg_type2, armor, holy_res, fire_res, nature_res, frost_res, shadow_res, arcane_res, delay, ammo_type, `range`, spellid_1, spelltrigger_1, spellcharges_1, spellcooldown_1, spellcategory_1, spellcategorycooldown_1, spellid_2, spelltrigger_2, spellcharges_2, spellcooldown_2, spellcategory_2, spellcategorycooldown_2, spellid_3, spelltrigger_3, spellcharges_3, spellcooldown_3, spellcategory_3, spellcategorycooldown_3, spellid_4, spelltrigger_4, spellcharges_4, spellcooldown_4, spellcategory_4, spellcategorycooldown_4, spellid_5, spelltrigger_5, spellcharges_5, spellcooldown_5, spellcategory_5, spellcategorycooldown_5, bonding, description, page_id, page_language, page_material, quest_id, lock_id, lock_material, sheathID, randomprop, randomsuffix, block, itemset, MaxDurability, ZoneNameID, mapid, bagfamily, TotemCategory, socket_color_1, unk201_3, socket_color_2, unk201_5, socket_color_3, unk201_7, socket_bonus, GemProperties, ReqDisenchantSkill, ArmorDamageModifier, existingduration, ItemLimitCategoryId, HolidayId) VALUES ("..SEUp.Quest_Item..", 12, 0, 0, 'Sniper Rifle', 18405, 1, 192, 0, 0, 0, 26, -1, -1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1000, 0, 30, 63691, 0, 0, 2000, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, -1, 0, 0, 0, -1, 0, -1, 4, 'Benny''s trusty and rusty rifle.', 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0);")
- WorldDBQuery("INSERT INTO quests (entry, ZoneId, sort, flags, MinLevel, questlevel, `Type`, RequiredRaces, RequiredClass, RequiredTradeskill, RequiredTradeskillValue, RequiredRepFaction, RequiredRepValue, LimitTime, SpecialFlags, PrevQuestId, NextQuestId, srcItem, SrcItemCount, Title, Details, Objectives, CompletionText, IncompleteText, EndText, ObjectiveText1, ObjectiveText2, ObjectiveText3, ObjectiveText4, ReqItemId1, ReqItemId2, ReqItemId3, ReqItemId4, ReqItemId5, ReqItemId6, ReqItemCount1, ReqItemCount2, ReqItemCount3, ReqItemCount4, ReqItemCount5, ReqItemCount6, ReqKillMobOrGOId1, ReqKillMobOrGOId2, ReqKillMobOrGOId3, ReqKillMobOrGOId4, ReqKillMobOrGOCount1, ReqKillMobOrGOCount2, ReqKillMobOrGOCount3, ReqKillMobOrGOCount4, ReqCastSpellId1, ReqCastSpellId2, ReqCastSpellId3, ReqCastSpellId4, ReqEmoteId1, ReqEmoteId2, ReqEmoteId3, ReqEmoteId4, RewChoiceItemId1, RewChoiceItemId2, RewChoiceItemId3, RewChoiceItemId4, RewChoiceItemId5, RewChoiceItemId6, RewChoiceItemCount1, RewChoiceItemCount2, RewChoiceItemCount3, RewChoiceItemCount4, RewChoiceItemCount5, RewChoiceItemCount6, RewItemId1, RewItemId2, RewItemId3, RewItemId4, RewItemCount1, RewItemCount2, RewItemCount3, RewItemCount4, RewRepFaction1, RewRepFaction2, RewRepFaction3, RewRepFaction4, RewRepFaction5, RewRepFaction6, RewRepValue1, RewRepValue2, RewRepValue3, RewRepValue4, RewRepValue5, RewRepValue6, RewRepLimit, RewMoney, RewXP, RewSpell, CastSpell, PointMapId, PointX, PointY, PointOpt, RewardMoneyAtMaxLevel, ExploreTrigger1, ExploreTrigger2, ExploreTrigger3, ExploreTrigger4, RequiredOneOfQuest, RequiredQuest1, RequiredQuest2, RequiredQuest3, RequiredQuest4, RemoveQuests, ReceiveItemId1, ReceiveItemId2, ReceiveItemId3, ReceiveItemId4, ReceiveItemCount1, ReceiveItemCount2, ReceiveItemCount3, ReceiveItemCount4, IsRepeatable, bonushonor, bonusarenapoints, rewardtitleid, rewardtalents, suggestedplayers, detailemotecount, detailemote1, detailemote2, detailemote3, detailemote4, detailemotedelay1, detailemotedelay2, detailemotedelay3, detailemotedelay4, completionemotecnt, completionemote1, completionemote2, completionemote3, completionemote4, completionemotedelay1, completionemotedelay2, completionemotedelay3, completionemotedelay4, completeemote, incompleteemote, iscompletedbyspelleffect, RewXPId) VALUES ("..SEUp.Quest..", 0, 284, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "..SEUp.Quest_Item..", 1, 'Shoot ''Em Up!', 'So, yer feelin'' lucky eh $N?\r\nWell step right up an'' try a game o'' \"Shoot ''Em Up\"!\r\nIf ye know the rules, go ahead an'' get them guns blastin''! \r\n\r\nIf ye don''t know ''em, have a wee chat with me before ye accept!\r\n\r\nYe have 20 seconds to shoot ''em target.\r\nI will take 1 second off ev''ry time ye complete them task.\r\nYe can use my gun, but be sure to brin'' it back!', 'Benny wants you to shoot the 5 targets before the time runs out and then bring the rifle back.', 'Great shootin'' there $n! Almost like I would''ve done it masel''! \r\n\r\nHere, ye''ve really earned this prize!', '', '', 'Shoot the targets', '', '', '', "..SEUp.Quest_Item..", 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 0, 0, 0, '', 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);")
- WorldDBQuery("INSERT INTO creature_names (entry, name, subname, info_str, flags1, `type`, family, rank, killcredit1, killcredit2, male_displayid, female_displayid, male_displayid2, female_displayid2, unknown_float1, unknown_float2, leader, questitem1, questitem2, questitem3, questitem4, questitem5, questitem6, waypointid) VALUES ("..SEUp.Quest_NPC..", 'Benny', 'Questgiver', '', 0, 7, 0, 0, 0, 0, 6074, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0);")
- WorldDBQuery("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, walk_speed, run_speed, fly_speed, extra_a9_flags, spell1, spell2, spell3, spell4, spell5, spell6, spell7, spell8, spell_flags, modImmunities, isTrainingDummy, guardtype, summonguard, spelldataid, vehicleid, rooted) VALUES ("..SEUp.Quest_NPC..", 1, 1, 35, 5000, 5000, 0, 1, 2, 2000, 0, 4, 4, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 1, '', 0, 0, 0, 2.5, 8, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);")
- WorldDBQuery("REPLACE INTO creature_quest_finisher (id, quest) VALUES ("..SEUp.Quest_NPC..", "..SEUp.Quest..");")
- WorldDBQuery("REPLACE INTO creature_quest_starter (id, quest) VALUES ("..SEUp.Quest_NPC..", "..SEUp.Quest..");")
- print("[Shoot 'Em Up]: Quest and NPC SQL's imported. Please restart your world.exe before spawning your NPC's.")
- end
- if(WorldDBQuery("SHOW TABLES LIKE 'shootemup'") == nil) then
- WorldDBQuery("CREATE TABLE shootemup ( GUID INT(10) UNSIGNED NOT NULL, Time SMALLINT(5) UNSIGNED NOT NULL DEFAULT '20000', PRIMARY KEY (GUID) ) COLLATE='latin1_swedish_ci' ENGINE=InnoDB;")
- print("[Shoot 'Em Up]: Custom table \"shootemup\" imported!")
- end
- -- Load Data
- local Query = WorldDBQuery("SELECT `GUID`, `Time` FROM `shootemup`")
- if(Query == nil) then
- SEUp.RowCount = 0
- else
- SEUp.RowCount = Query:GetRowCount()
- end
- for i = 1, SEUp.RowCount do
- SEUp[tostring(Query:GetColumn(0):GetLong())] = Query:GetColumn(1):GetLong()
- Query:NextRow()
- end
- Query = nil
- function SEUp.OnLoad(pUnit, event)
- SEUp.Reset(pUnit)
- end
- function SEUp.QuestAccept(event, pPlayer, pQuest, pUnit)
- if(pQuest == SEUp.Quest) then
- local pGUID = tostring(pPlayer:GetGUID())
- if(SEUp.PlayerData[pGUID] ~= nil) then
- SEUp.Reset(SEUp.PlayerData[pGUID][1], pPlayer)
- end
- SEUp.PlayerData[pGUID] = {pUnit, 1}
- if(SEUp[pGUID] == nil) then
- WorldDBQuery("INSERT INTO `shootemup` (`GUID`, `Time`) VALUES (\""..pGUID.."\", 20000)")
- SEUp[pGUID] = 20000
- end
- pUnit:SetNPCFlags(4)
- local S = ""
- if(SEUp[pGUID] > 1000) then
- S = "s"
- end
- pUnit:SendChatMessageToPlayer(12, 0, "Alright "..pPlayer:GetName()..", ye have "..(SEUp[pGUID]/1000).." second"..S.." tae hit each target! Good luck!", pPlayer)
- SEUp.ResetTargets(pUnit)
- local delay = 1000
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 6) end, delay, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 5) end, delay+1000, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 4) end, delay+2000, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 3) end, delay+3000, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 2) end, delay+4000, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 1) end, delay+5000, 1)
- pUnit:RegisterEvent(function() SEUp.Countdown(pPlayer, pUnit, 0) end, delay+6000, 1)
- end
- end
- function SEUp.Countdown(pPlayer, pUnit, pTime)
- if(pTime >= 6) then
- pPlayer:SendAreaTriggerMessage("Get Ready!")
- elseif(pTime > 0) then
- pPlayer:SendAreaTriggerMessage(pTime.."!")
- elseif(pTime == 0) then
- pPlayer:SendAreaTriggerMessage("GO!")
- pUnit:RegisterEvent(function() SEUp.GetTarget(pPlayer, pUnit) end, 2000, 1)
- end
- end
- function SEUp.GetTarget(pPlayer, pUnit)
- local pGUID = tostring(pPlayer:GetGUID())
- pTarget = SEUp.GetTargetS(pUnit)
- if(SEUp.PlayerData[pGUID] ~= nil) then
- SEUp.PlayerData[pGUID]["CurrentTarget"] = pTarget
- end
- pUnit:CastSpellOnTarget(20374, pTarget)
- pUnit:SendChatMessageToPlayer(12, 0, pPlayer:GetName()..", shoot "..pTarget:GetName().." now!", pPlayer)
- SEUp.QuestFailEvent[tostring(pUnit:GetGUID())] = CreateLuaEvent(function() SEUp.QuestFailed(pPlayer, pUnit, pTarget) end, SEUp[pGUID], 1)
- end
- function SEUp.GetTargetS(pUnit)
- local Targets = pUnit:GetInRangeUnits()
- local Units = {}
- for i = 1, #Targets do
- for l = 1, #SEUp.Target_list do
- if(Targets[i]:GetEntry() == SEUp.Target_list[l] and Targets[i]:GetDistanceYards(pUnit) <= SEUp.Distance) then
- Units[#Units+1] = Targets[i]
- break
- end
- end
- end
- return Units[math.random(#Units)]
- end
- function SEUp.QuestFailed(pPlayer, pUnit, pTarget)
- if(SEUp.QuestFailEvent[tostring(pUnit:GetGUID())]) then
- DestroyLuaEvent(SEUp.QuestFailEvent[tostring(pUnit:GetGUID())])
- end
- pUnit:SendChatMessageToPlayer(12, 0, "I'm sorry "..pPlayer:GetName()..", ye missed "..pTarget:GetName()..". Better luck next time.", pPlayer)
- SEUp.Reset(pUnit, pPlayer)
- end
- function SEUp.Reset(pUnit, pPlayer)
- pUnit:RemoveEvents()
- pUnit:SetNPCFlags(2)
- local Targets = pUnit:GetInRangeUnits()
- SEUp.ResetTargets(pUnit)
- if(pPlayer ~= nil) then
- SEUp.PlayerData[tostring(pPlayer:GetGUID())] = nil
- pPlayer:FinishQuest(SEUp.Quest)
- end
- end
- function SEUp.ResetTargets(pUnit)
- local Targets = pUnit:GetInRangeUnits()
- for i = 1, #Targets do
- for l = 1, #SEUp.Target_list do
- if(Targets[i]:GetEntry() == SEUp.Target_list[l] and Targets[i]:GetDistanceYards(pUnit) <= SEUp.Distance) then
- Targets[i]:RemoveAura(20374)
- Targets[i]:SetLevel(1) -- set level of targets to 1 so we can even hit with the spell.
- break
- end
- end
- end
- end
- function SEUp.OnShoot(event, pPlayer, pSpellEntry, pSpell)
- if(pSpellEntry == 63691) and (pPlayer:HasQuest(SEUp.Quest) and pPlayer:GetQuestObjectiveCompletion(SEUp.Quest, 0) <= 4) then
- local Target = pPlayer:GetSelection()
- local pGUID = tostring(pPlayer:GetGUID())
- if(Target == nil or SEUp.PlayerData[pGUID] == nil or SEUp.PlayerData[pGUID]["CurrentTarget"] == nil or (Target:GetDistanceYards(pPlayer) > 30 and Target:GetDistanceYards(pPlayer) < 5) or pPlayer:IsPlayerMoving()) then
- return
- end
- if(tostring(Target) == tostring(SEUp.PlayerData[pGUID]["CurrentTarget"]) and Target:HasAura(20374) and pPlayer:IsInFront(Target)) then
- SEUp.QuestObjective(pPlayer, SEUp.PlayerData[pGUID][1], Target)
- else
- SEUp.QuestFailed(pPlayer, SEUp.PlayerData[pGUID][1], SEUp.PlayerData[pGUID]["CurrentTarget"])
- end
- end
- end
- function SEUp.QuestObjective(pPlayer, pUnit, pTarget)
- local pGUID = tostring(pPlayer:GetGUID())
- SEUp.PlayerData[pGUID][2] = SEUp.PlayerData[pGUID][2]+1
- pTarget:RemoveAura(20374)
- pPlayer:AdvanceQuestObjective(SEUp.Quest, 0)
- if(SEUp.QuestFailEvent[tostring(pUnit:GetGUID())] ~= nil) then
- DestroyLuaEvent(SEUp.QuestFailEvent[tostring(pUnit:GetGUID())])
- end
- if(SEUp.PlayerData[pGUID][2] <= 5) then
- pUnit:SendChatMessageToPlayer(12, 0, (6-SEUp.PlayerData[pGUID][2]).." tae go! Get ready for yer next target!", pPlayer)
- pUnit:RegisterEvent(function() SEUp.GetTarget(pPlayer, pUnit) end, 4000, 1)
- else
- pUnit:SendChatMessageToPlayer(12, 0, "Great job "..pPlayer:GetName().."! Ye hit all the targets!", pPlayer)
- if(SEUp[pGUID] > 1000) then
- SEUp[pGUID] = SEUp[pGUID]-1000
- -- elseif(SEUp[pGUID] > 100) then -- Way too fast if you need to shoot in less than 1 second
- -- SEUp[pGUID] = SEUp[pGUID]-100
- end
- WorldDBQuery("UPDATE `shootemup` SET `Time` = "..SEUp[pGUID].." WHERE `GUID` = \""..pGUID.."\"")
- SEUp.Reset(pUnit, pPlayer)
- end
- end
- function SEUp.QuestCancel(event, pPlayer, pQuest)
- if(pQuest == SEUp.Quest and SEUp.PlayerData[pGUID] ~= nil) then
- SEUp.QuestFailed(pPlayer, SEUp.PlayerData[pGUID][1], SEUp.PlayerData[pGUID]["CurrentTarget"])
- end
- end
- RegisterServerHook(14, SEUp.QuestAccept)
- RegisterServerHook(21, SEUp.QuestCancel)
- RegisterServerHook(10, SEUp.OnShoot)
- RegisterUnitEvent(SEUp.Quest_NPC, 18, SEUp.OnLoad)
- print("[Shoot 'Em Up]: Script loaded")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement