Cuberite Forum
Broadcast message - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Broadcast message (/thread-2951.html)



Broadcast message - nrgjrteherh435 - 05-18-2017

im trying to broadcast a message when an entity dies (yes i have the hook connected to the function bla bla) and i get an error when trying to execute 

my code:
Code:
function OnKilled(World)
    World:BroadcastChat("Death Lingers...");
    return true;
end

my error:
Code:
LUA: Plugins/CustomPlugin/CustomPlugin.lua:25: attempt to call method 'BroadcastChat' (a nil value)
Stack trace:   Plugins/CustomPlugin/CustomPlugin.lua(25): (no name)
Stack trace end
Error in <attached> calling function <callback>()

any help is greatly appreciated Smile


RE: Broadcast message - Mathias - 05-18-2017

This should work:
Message when mobs and players die:
Code:
function OnKilled(Victim)
    Victim:GetWorld():BroadcastChat("Death Lingers...")
end

Message when players die:
Code:
function OnKilled(Victim)
    if Victim:IsPlayer() then
        Victim:GetWorld():BroadcastChat("Death Lingers...")
    end
end