cressidagp

Twiggy Flathead

Jun 2nd, 2023 (edited)
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.26 KB | None | 0 0
  1. --[[
  2.  
  3. .npc portto 43359
  4. .quest start 1718 (the islander)
  5.  
  6. TODO:
  7.  
  8. *) use AT
  9.  
  10. --]]
  11.  
  12. -- QUESTID_THE_AFFRAY = 1719
  13. -- CREATUREID_TWIGGY_FLATHEAD = 6248
  14. -- CREATUREID_AFFRAY_CHALLENGER = 6240
  15. -- CREATUREID_BIG_WILL = 6238
  16. -- EMOTE_ONESHOT_ROAR = 15
  17. -- EMOTE_STATE_READY_UNARMED = 27
  18. -- FACTION_ENEMY = 14
  19. -- FACTION_FRIENDLY = 35
  20. -- OBJECT_END               = 0x0006
  21. -- UNIT_FIELD_FLAGS         = 0x0006 + 0x0035
  22. -- UNIT_FIELD_TARGET        = 0x0006 + 0x000C
  23. -- UNIT_FLAG_NOT_ATTACKABLE_9   = 0x00000100;
  24. -- UNIT_FLAG_NOT_SELECTABLE = 0x02000000;
  25.  
  26. local AffrayLoc = {
  27.  
  28.     {-1683, -4326, 2.79, 0},
  29.     {-1682, -4329, 2.79, 0},
  30.     {-1683, -4330, 2.79, 0},
  31.     {-1680, -4334, 2.79, 1.49},
  32.     {-1674, -4326, 2.79, 3.49},
  33.     {-1677, -4334, 2.79, 1.66}
  34. };
  35.  
  36. local AffrayDisplay = { 4968, 4969, 4970, 4971 };
  37.  
  38. THE_AFFRAY = {}
  39.  
  40. function twiggyFlathead_onAIUpdate( unit, _ )
  41.  
  42.     local ref = THE_AFFRAY[tostring( unit )]
  43.    
  44.     -- the green bastard look for Warriors witch have started the quest
  45.     local tbl_plrs = unit:GetInRangePlayers()
  46.     if tbl_plrs and ref.eventInProgress == false then
  47.         for _, v in ipairs ( tbl_plrs ) do
  48.             if v:GetPlayerClass() == "Warrior" and v:GetQuestObjectiveCompletion( 1719, 0 ) == 0 then
  49.                 if unit:GetDistance( v ) <= 90 then
  50.                    ref.eventInProgress = true
  51.                    ref.plrTarget = v
  52.                    ref.plrGuid = v:GetGUID()   
  53.                 end
  54.             end
  55.         end
  56.     end
  57.    
  58.     -- check if event has started and then spawn challengers
  59.     if( ref.eventSpawned == false and ref.eventInProgress == true ) then
  60.  
  61.         local p = unit:GetUnitByGUID( ref.plrGuid )
  62.         if p:HasQuest( 1719 ) then
  63.             local x = p:GetX()
  64.             local y = p:GetY()
  65.            
  66.             -- there is an AT in the center of the circle (like
  67.             -- in all quest about step in some place) but not sure
  68.             -- if we should have to much serverhook functions (maybe
  69.             -- a big one with all quest like this???)
  70.             if( (x >= -1684 and x <= -1674) and (y >= -4334 and y <= -4324) ) then
  71.                 unit:SendChatMessage( 12, 0, "The Affray has begun.  "..p:GetName()..", get ready to fight!" )
  72.                        
  73.                 for i = 1, 6, 1 do
  74.    
  75.                     local mob = unit:SpawnCreature( 6240, AffrayLoc[ i ][ 1 ], AffrayLoc[ i ][ 2 ], AffrayLoc[ i ][ 3 ], AffrayLoc[ i ][ 4 ], 35, 600000, 1899, 1, 1, 1, 0 );
  76.                     mob:SetModel( AffrayDisplay[math.random(1, 4)] )
  77.                     mob:SetByteValue( 0x7A, 0, 1 )
  78.                     mob:SetFaction( 35 )
  79.                     mob:SetFlag( 0x0006 + 0x0035, 0x00000100 + 0x02000000 )
  80.                     mob:DisableCombat( 1 )
  81.                     mob:Emote( 15, 1000 )
  82.                     ref.affrayChallenger[ i ] = mob:GetGUID()  
  83.                 end
  84.                        
  85.                 ref.eventSpawned = true
  86.                 ref.waveTimer = 5
  87.                 ref.challengerChecker = 1      
  88.             end
  89.         end
  90.        
  91.     elseif( ref.eventInProgress == true ) then
  92.    
  93.         ref.waveTimer = ref.waveTimer - 1  
  94.        
  95.         -- check if a challenger is dead
  96.         if( ref.challengerChecker <= 1 ) then
  97.        
  98.             for i = 1, 6, 1 do
  99.            
  100.                 if( ref.affrayChallenger[ i ] ) then
  101.                
  102.                     local npc = unit:GetUnitByGUID( ref.affrayChallenger[ i ] )
  103.                    
  104.                     if( npc == nil or ( npc:IsAlive() == false and ref.challengerDown[ i ] == false ) ) then
  105.  
  106.                         unit:SendChatMessage( 12, 0, "Challenger is down!" )
  107.                         ref.challengerDown[ i ] = true
  108.                     end
  109.                 end
  110.             end
  111.    
  112.             ref.challengerChecker = 1;
  113.         else
  114.             ref.challengerChecker = ref.challengerChecker - 1
  115.         end
  116.        
  117.         -- wait twenty seconds and then activate another Challenger
  118.         if( ref.waveTimer <= 1 ) then
  119.        
  120.             if( ref.wave < 7 and ref.affrayChallenger[ ref.wave ] and ref.eventBigWill == false ) then
  121.                 unit:SendChatMessage( 12, 0, "You!  Enter the fray!" )
  122.                 local npc = unit:GetUnitByGUID( ref.affrayChallenger[ ref.wave ] )
  123.                 if( npc and npc:IsAlive() == true ) then
  124.                     npc:Emote( 15, 0 )
  125.                     npc:SetFaction( 14 )
  126.                     npc:SetUInt64Value( 0x0006 + 0x000C, ref.plrGuid );
  127.                     npc:RegisterAIUpdateEvent( 3000 )
  128.                     ref.wave = ref.wave + 1
  129.                     ref.waveTimer = 20
  130.                 end
  131.            
  132.             -- no more Challengers so spawn Big Will
  133.             elseif( ref.wave >= 6 and ref.eventBigWill == false ) then
  134.            
  135.                 local bw = unit:SpawnCreature( 6238, -1722, -4341, 6.12, 6.26, 35, 480000, 1, 1, 1, 1, 0 )
  136.                 if( bw ) then
  137.                     bw:SetFlag( 0x0006 + 0x0035, 0x00000100 + 0x02000000 )
  138.                     bw:DisableCombat( 1 )
  139.                     bw:Emote( 27, 0 )
  140.                     ref.bigWill = bw:GetGUID()
  141.                     ref.eventBigWill = true
  142.                     ref.waveTimer = 1
  143.                     --test
  144.                     bw:RegisterAIUpdateEvent( 20000 )
  145.                     bw:SetUInt64Value( 0x0006 + 0x000C, ref.plrGuid );
  146.                 end
  147.                        
  148.             elseif( ref.wave >= 6 and ref.eventBigWill and ref.bigWill ) then
  149.            
  150.                 local bw = unit:GetUnitByGUID( ref.bigWill )
  151.                 if( bw == nil or bw:IsAlive() == false ) then
  152.                     unit:SendChatMessage( 12, 0, "The Affray is over!" )
  153.                     ref.eventInProgress = false
  154.                     unit:Despawn( 1000, 0 ) -- reset variables
  155.                 end
  156.             end
  157.         end
  158.     end
  159. end
  160.  
  161. function twiggyFlathead_onLoad( unit, _ )
  162.  
  163.     local sUnit = tostring( unit )
  164.    
  165.     THE_AFFRAY[ sUnit ] = {
  166.    
  167.     eventInProgress = false,
  168.     eventSpawned = false,
  169.     affrayChallenger = { nil, nil, nil, nil, nil, nil },
  170.     challengerDown = { false, false, false, false, false, false },
  171.     waveTimer = 0,
  172.     challengerChecker = 0,
  173.     eventBigWill = false,
  174.     wave = 1,
  175.     bigWill = nil,
  176.     plrTarget = nil,
  177.     plrGuid = nil
  178.    
  179.     }
  180.     unit:RegisterAIUpdateEvent( 1000 )
  181. end
  182.  
  183. RegisterUnitEvent( 6248, 18, twiggyFlathead_onLoad )
  184. RegisterUnitEvent( 6248, 21, twiggyFlathead_onAIUpdate )
Tags: lua arcemu
Add Comment
Please, Sign In to add comment