• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Am i right doing this ?

Status
Not open for further replies.
Level 1
Joined
Dec 13, 2010
Messages
2
hello, this is my first time to post in this forum, so, be nice to me XD
i've created a simple library to store item ID's that will drop if the specified unit dies, and i just wondering why if i kills an NPC, that NPC will drop item too even if i didn't register it to the system :vw_wtf:

so, here's the system :
JASS:
library ItemDrop requires Table

globals
    private Table IDTable = 0
    private integer Creep = 0
endglobals

struct Creep
    integer unitID = 0
    integer array it[99]
    integer itemcountdrop = 0
    
    private static method AddCreep takes integer unitid returns thistype
        local thistype this = thistype.allocate()
        
        set .unitID = unitid
        set IDTable[.unitID] = this
        
        return this
    endmethod
    
    private static method Drop takes nothing returns nothing
        local unit d = GetTriggerUnit()
        local real x = GetUnitX(d)
        local real y = GetUnitY(d)
        local thistype this = IDTable[GetUnitTypeId(d)]
        
        call CreateItem(.it[GetRandomInt(0,.itemcountdrop)], x, y )
    endmethod
    
    private static method Check takes nothing returns boolean
        local unit d = GetTriggerUnit()
        local thistype this = IDTable[GetUnitTypeId(d)]
        
        if this == 0 or IsUnitType(d, UNIT_TYPE_MECHANICAL) or IsUnitType(d, UNIT_TYPE_HERO) then
        return false
        else
        return true
        endif
    endmethod
    
    private static method onInit takes nothing returns nothing
        local Creep c = 0
        local trigger t = CreateTrigger()
        set IDTable = Table.create()
    
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(t, function thistype.Drop)
        call TriggerAddCondition(t, function thistype.Check)
        
        //Deria
        set c = Creep.AddCreep('n000')
        set c.itemcountdrop = 2
        set c.it[0] = 'I006'
        set c.it[1] = 'I007'
        set c.it[2] = 'I008'
        set c = Creep.AddCreep('n007')
        set c.itemcountdrop = 2
        set c.it[0] = 'I006'
        set c.it[1] = 'I007'
        set c.it[2] = 'I008'
        //Appello
        set c = Creep.AddCreep('n009')
        set c.itemcountdrop = 2
        set c.it[0] = 'I00F'
        set c.it[1] = 'I007'
        set c.it[2] = 'I00E'
        set c = Creep.AddCreep('n008')
        set c.itemcountdrop = 2
        set c.it[0] = 'I00F'
        set c.it[1] = 'I007'
        set c.it[2] = 'I00E'
        //Wolfram
        set c = Creep.AddCreep('n00B')
        set c.itemcountdrop = 2
        set c.it[0] = 'I00Q'
        set c.it[1] = 'I007'
        set c.it[2] = 'I00E'
        set c = Creep.AddCreep('n00C')
        set c.itemcountdrop = 2
        set c.it[0] = 'I00Q'
        set c.it[1] = 'I007'
        set c.it[2] = 'I00E'
    endmethod

endstruct

endlibrary

thank you :D


- 4thAvenueCafe
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Put a debug message in to let you know what the value of "this" is in the Check method for units who shouldn't be dropping items. If it's 0 then your problem is probably related to the default item drop tables or something. If it isn't then you've found your problem.

Also, you should be nulling units.
 
Status
Not open for further replies.
Top