Quote:
Originally Posted by Thurallor
I played with this a while back. Based on my observations, the EffectRemoved event also supplies an Effect argument, but only if you've previously read the effects list (with a effectsObject:Get() loop). You can use that argument to get the name of the effect, although that is by no means a unique identifier. (Lots of different effects have the same names.) It may be good enough for the OP's purposes, though.
|
Ah, thanks Thurallor, that explains some of the weirdness I was seeing. It seems if multiple effects are removed simultaneously the second (or subsequent) EffectRemoved contains the args.Effect since the args.Index is no longer valid. That makes the whole thing workable.
The code would then look like:
Code:
localPlayer=Turbine.Gameplay.LocalPlayer:GetInstance();
effectList=localPlayer:GetEffects()
count=0; -- initialize variable
-- define the AddCallback function
function AddCallback(object, event, callback)
if (object[event] == nil) then
object[event] = callback;
else
if (type(object[event]) == "table") then
table.insert(object[event], callback);
else
object[event] = {object[event], callback};
end
end
return callback;
end
EffectRemovedHandler=function(sender,args)
local effectName=""
Turbine.Shell.WriteLine("args.Effect:"..tostring(args.Effect))
if args.Effect==ni then
effectName=effectList:Get(args.Index):GetName()
else
effectName=args.Effect:GetName()
end
if effectName=="Schnelle Erl\195\182sung" then
killcount=6;
do_update()
end
-- uncomment the following line to see the name of every effect as it is removed in case the name is not "Schnelle Erl\195\182sung"
-- Turbine.Shell.WriteLine("effect:"..effectName)
end
AddCallback(effectList,"EffectRemoved",EffectRemovedHandler)
ChatMonitor = Turbine.Chat;
ChatReceived = function(f, args)
local msg = args.Message;
if(args.ChatType == Turbine.ChatType.PlayerCombat) then
if string.find (args.Message,"Verbesserter Gnadenschuss",1,true)~=nil then
killcount=6;
do_update()
else
if killcount==0 then
do_update()
else
if string.find (args.Message,"Verbesserter Schneller Bogen",1,true)~=nil then
killcount=killcount-0.333
do_update()
end
end
end
end
end
AddCallback(Turbine.Chat, "Received", ChatReceived)
Note, the commented line " Turbine.Shell.WriteLine("effect:"..effectName)" can be uncommented to verify what the effect name is in case it is not "Schnelle Erl\195\182sung"