Advertisement
cressidagp

masterHandler

Dec 30th, 2024
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.14 KB | None | 0 0
  1. local soldierId = { 43284, 43285 }
  2.  
  3. ARCMERCS = {}
  4.  
  5. --- getMercCount()
  6. ---   Get the ammount of mercenaries than the player has.
  7. ---
  8. --- Parameter(s)
  9. ---   plr
  10. ---   group
  11. ---
  12. --- Return value
  13. ---   Returns the number of mercenaries.
  14. ---
  15. function getMercCount( plr, group )
  16.  
  17.     local data = tostring( plr:GetGUID() )
  18.  
  19.     local count = 0
  20.  
  21.     local result = WorldDBQuery("SELECT entry FROM arcmercs.mercenaries WHERE ownerGuid = '"..data.."' AND groupId = "..group.."")
  22.  
  23.     if result then
  24.  
  25.         local rowcount = result:GetRowCount()
  26.  
  27.         repeat
  28.        
  29.             rowcount = rowcount - 1
  30.            
  31.             local entry = result:GetColumn( 0 ):GetUShort()
  32.  
  33.             if entry ~= 0 then
  34.  
  35.                 count = count + 1
  36.  
  37.             end
  38.  
  39.         result:NextRow()
  40.  
  41.         until rowcount == 0
  42.  
  43.     end
  44.  
  45.     return count
  46.  
  47. end
  48.  
  49. function ARCMERCS.MasterOnHello( unit, event, plr )
  50.  
  51.     unit:GossipCreateMenu( 68000, plr, 0 )
  52.  
  53.     unit:GossipMenuAddItem( 0, "Reset.", 0, 0 )
  54.  
  55.     unit:GossipMenuAddItem( 6, "I want a Soldier.", 1, 0 )
  56.  
  57.     unit:GossipMenuAddItem( 6, "I need a Healer.", 2, 0 )
  58.    
  59.     unit:GossipMenuAddItem( 6, "Give me an Officer.", 3, 0 )
  60.    
  61.     unit:GossipSendMenu( plr )
  62.  
  63. end
  64.  
  65. function ARCMERCS.MasterOnSelection( unit, event, plr, id, intid, code )
  66.  
  67.     local data = tostring( plr:GetGUID() )
  68.  
  69.     local level = plr:GetLevel()
  70.  
  71.     local coins = plr:GetCoinage()
  72.  
  73.     if( intid == 0 ) then
  74.  
  75.         WorldDBQuery("DELETE FROM arcmercs.mercenaries WHERE ownerGuid = '"..tostring(data).."'")
  76.  
  77.         plr:SendBroadcastMessage( "Your mercenary info has been reseted." )
  78.  
  79.         plr:GossipComplete()
  80.  
  81.     end
  82.  
  83.     if( intid == 1 ) then
  84.  
  85.         if( level >= 10 ) then
  86.  
  87.             if getMercCount( plr, intid ) < 3 then
  88.  
  89.                 if( coins > 10 ) then
  90.  
  91.                     local e = soldierId[ plr:GetTeam() + 1 ]
  92.  
  93.                     local angle = math.random( 0, 5 )
  94.                    
  95.                     local merc = plr:CreateGuardian( e, 0, angle, level )
  96.                    
  97.                     WorldDBQuery("INSERT INTO arcmercs.mercenaries (ownerGuid, groupId, entry, display, angle, mercGuid, ownerName, type) VALUES ('"..tostring(data).."', "..intid..", "..e..", "..merc:GetDisplay()..", "..angle..", '"..tostring(merc:GetGUID()).."', '"..plr:GetName().."', 'Soldier' )")
  98.                    
  99.                     local guid = tostring(merc)
  100.                    
  101.                     if not ARCMERCS[guid] then
  102.                    
  103.                         ARCMERCS[guid] = {}
  104.                        
  105.                     end
  106.                    
  107.                     plr:SendBroadcastMessage( "You have hired an "..merc:GetName().."." )
  108.  
  109.                     plr:GossipComplete()
  110.  
  111.                 else
  112.  
  113.                     -- player hasn money to hire
  114.  
  115.                     unit:GossipCreateMenu( 68001, plr, 0 )
  116.  
  117.                     unit:GossipSendMenu( plr )
  118.  
  119.                 end
  120.  
  121.             else
  122.  
  123.                 -- player hasn room for more soldiers
  124.  
  125.                 unit:GossipCreateMenu( 68002, plr, 0 )
  126.  
  127.                 unit:GossipSendMenu( plr )
  128.  
  129.             end
  130.  
  131.         else
  132.  
  133.             -- player level is not enough
  134.  
  135.             unit:GossipCreateMenu( 68003, plr, 0 )
  136.  
  137.             unit:GossipSendMenu( plr )
  138.  
  139.         end
  140.  
  141.     end
  142.  
  143.     if( intid == 2 ) then
  144.  
  145.         plr:SendBroadcastMessage( "You have hired an healer" )
  146.  
  147.     end
  148.  
  149.     if( intid == 3 ) then
  150.  
  151.         plr:SendBroadcastMessage( "You have hired an officer" )
  152.  
  153.     end
  154.  
  155.     if( intid == 4 ) then
  156.  
  157.         -- TODO
  158.  
  159.     end
  160.  
  161.     --plr:GossipComplete()
  162.  
  163. end
  164.  
  165. RegisterUnitGossipEvent( 43283, 1, ARCMERCS.MasterOnHello );
  166. RegisterUnitGossipEvent( 43283, 2, ARCMERCS.MasterOnSelection );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement