stoneharry

Untitled

Feb 22nd, 2012
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.66 KB | None | 0 0
  1. --[[
  2.  
  3. We need a custom DB to store the data in:
  4.  
  5. -- Columns:
  6. -- CreatureID (Primary Key)         // Handles the ID of the creature for that guild which is killed    --
  7. -- Power (Not NULL) (Default 0)     // Stores the 'power' the guild has                                 --
  8. -- GuildID (Not NULL) (Default 0)   // Stores the real guild ID                                         --
  9.  
  10. ]]
  11.  
  12. -- The name of the custom table we create within the Character DB
  13. local TableName = "Guild_Power_Store"
  14.  
  15. function Guild_Leader_Death(pUnit, Event)
  16.     -- Get the ID of the creature killed
  17.     local entry = pUnit:GetEntry()
  18.     -- Now to return the person who dealt the killing blow in Lua is hard
  19.     -- We could search through all the players within say, 100 yards, and then use the faction with the most members
  20.     -- Or we could use my 'hack fix' which is just... The closest player.
  21.     local player = pUnit:GetClosestPlayer()
  22.     if player ~= nil -- you never know
  23.         -- Award the guild who won
  24.         local guild = player:GetGuildId()
  25.         if guild ~= nil then
  26.             CharDBQuery("UPDATE `"..TableName.."` SET `power` = power + 20 WHERE `GuildID` = '"..tostring(guild).."';")
  27.         end
  28.         -- Make the guild who lost lose points
  29.         CharDBQuery("UPDATE `"..TableName.."` SET `power` = power - 15 WHERE `CreatureID` = '"..entry.."';")
  30.     end
  31. end
  32.  
  33. -- Get the creature ID's we need to register
  34. local data = CharDBQuery("SELECT `CreatureID` FROM `"..TableName.."`;")
  35.  
  36. -- For the amount of guilds found
  37. while (data:NextRow()) do
  38.     -- Register the unit for a on death event
  39.     -- Just get the string value then cast it to a number, since I don't know the method to directly get a integer
  40.     RegisterUnitEvent(tonumber(data:GetColumn(0):GetString()), 4, "Guild_Leader_Death")
  41. end
Advertisement
Add Comment
Please, Sign In to add comment