Page 1 of 1

Referencing Item IDs?

PostPosted: Fri Jul 03, 2015 10:52 pm
by furbuggy
I figure that items have ID numbers now so that it is easier to reference them. Is there an easy way to do this in the code? For example, if I want a message "BOOM!" to appear when Core #1 falls to 0 hit points, how would I go about doing that? (lame example, but I figure a concrete piece of code would help)

Re: Referencing Item IDs?

PostPosted: 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:

function main()

    -- 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

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
    if core1destroyed then
        -- Do something when core is destroyed
        levelgen:globalMsg("Core 1 was destroyed!")

Re: Referencing Item IDs?

PostPosted: Sat Jul 04, 2015 7:16 pm
by watusimoto

Re: Referencing Item IDs?

PostPosted: Thu Jul 23, 2015 3:14 pm
by furbuggy
Oh wow! I didn't understand your response until now, thanks! That's very helpful.