Sat Jul 04, 2015 8:16 am by raptor
We usually use 'events' to send messages to levelgens when certain things happen; however, there isn't one for when a core is destroyed. But, there is usually more than one way to do things when scripting is involved:
What I like to do is something like this. In main() in the levelgen, do:
- Code:
function main()
bf:subscribe(Event.ScoreChanged)
-- global object to keep track of the core I want, this can be used
-- anywhere else in the script since it was declared in main()
core1 = bf:findObjectById(1)
core1destroyed = false
end
function onScoreChanged(scoreChange, teamIndex, player)
-- If a score has changed, then some core must have been destroyed.
-- This is a workaround for missing onCoreDestroyed event
if not core1destroyed then
if core1 == nil or core1:getCurrentHealth() == 0 then
core1destroyed = true
end
end
if core1destroyed then
-- Do something when core is destroyed
levelgen:globalMsg("Core 1 was destroyed!")
end
end