PDA

View Full Version : [Lua]World First Kill



Dr. Fallen
13-03-10, 08:41 AM
This Lua script will on world first kill of a creature kill write who killed it and how many to a file, and then Announce it to the world that, that boss have now been killed world first.
This is the Lua


--[[the TxTFile is for so we can Write to a Special file if the boss dies we can't have all bosses have the same worldfirst file because it will only write the first kill of one of the bosses]]
function WorldCheck(pUnit,BossName, TxTFile) --[[The function we should call]]
if io.open(TxTFile, "r") == nil and type(pUnit) == "userdata" and type(BossName) == "string" and type(TxTFile) == "string" then --[[Checks if The file exist and if it doesn't then we send the message and writes to the file]]
UnitWorldFirst(pUnit, BossName,TxTFile) --[[Write down in the file you defined]]
AnnounceWorldFirst(pUnit, BossName) --[[Announce it to the world that the boss was killed]]
end
end

function UnitWorldFirst(pUnit, BossName, TxTFile) --[[called by WorldCheck]]
local file = io.open(TxTFile, "w") --[[Open the file that we will write the names of the players who killed the boss]]
file:write("The world first kill of the boss "..BossName.." was made by \n") --[[First line writes that it was the first kill of the boss]]
for i,v in ipairs(pUnit:GetInRangePlayers()) do --[[loop till we get all players in range]]
file:write("Player number["..i.."] the players name is"..v:GetName()"\n") --[[Writes The number of the player and The name of the player in the file]]
end
file:write("Amount of players in the kill"..#pUnit:GetInRangePlayers()) --[[Writes how many players that was close to the boss when it was killed ]]
file:flush() --[[saves the file]]
file:close() --[[close da file!]]
end

function AnnounceWorldFirst(pUnit, BossName)
for i,v in ipairs(GetPlayersInWorld()) do --[[Loop all players in world so every one can see it]]
v:SendAreaTriggerMessage(BossName.." have been killed by "..#pUnit:GetInRangePlayers().." players for the first time") --[[sends the message to players online]]
end
endnow how to use it
We can use this Lua script this way


function On_HardBossDie(pUnit, Event)
WorldCheck(pUnit,"Hard Boss", "WorldFirstKillHardBoss.Txt")
end
Every time the boss dies it will check if the boss have been killed and if it haven't before then it will write all the names of the players that was attacking it and write it to a file and Announce it to the world
if you have problems reading the commands in the lua script here it is without comments but it is still used the same way without the comments


function WorldCheck(pUnit,BossName, TxTFile)
if io.open(TxTFile, "r") == nil and type(pUnit) == "userdata" and type(BossName) == "string" and type(TxTFile) == "string" then
UnitWorldFirst(pUnit, BossName,TxTFile)
AnnounceWorldFirst(pUnit, BossName)
end
end

function UnitWorldFirst(pUnit, BossName, TxTFile)
local file = io.open(TxTFile, "w")
file:write("The world first kill of the boss "..BossName.." was made by \n")
for i,v in ipairs(pUnit:GetInRangePlayers()) do
file:write("Player number["..i.."] the players name is"..v:GetName()"\n")
end
file:write("Amount of players in the kill"..#pUnit:GetInRangePlayers())
file:flush()
file:close()
end

function AnnounceWorldFirst(pUnit, BossName)
for i,v in ipairs(pUnit:GetPlayersInWorld()) do
v:SendAreaTriggerMessage(BossName.." have been killed by "..#pUnit:GetInRangePlayers().." players for the first time")
end
end

Avidgamer
13-03-10, 10:17 AM
Never seen this one yet, so good job.

Dr. Fallen
13-03-10, 10:34 AM
thx for comment :)

Dimman
13-03-10, 10:48 AM
Cool, Epic idea :)

Dr. Fallen
13-03-10, 11:07 AM
Cool, Epic idea :)

hehe :) thank you so much for ur comment mate