• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Creep Deny System (CDS) does not work

Status
Not open for further replies.
I've made a creep deny system but it does not work right..

I use JNGP.

When I load my map with this trigger I come back to the wc3 mainscreen on maptest.

JASS:
globals
real G_MISC_CDS_Health
real G_MISC_CDS_Exp
integer G_MISC_CDS_Gold
endglobals

function CDS_Death_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetKillingUnit()
local player p = GetOwningPlayer(a)

call DisplayTextToPlayer(p,0,0,"Deny!")
endfunction

function CDS_Att_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetAttacker()
local real l = GetUnitState(u, UNIT_STATE_LIFE)
local real ml = GetUnitState(u, UNIT_STATE_MAX_LIFE)
local real p = 0.00

    if (u == null) or (ml == 0) then
        set p = 0.0
    else
        set p =  l / ml * 100.0
    endif

if (p > G_MISC_CDS_Health) then
call IssueImmediateOrder(a,"stop")
endif

set u = null
set a = null
endfunction

function CDS_Death_Conditions takes nothing returns boolean
    return IsPlayerAlly(GetOwningPlayer(GetKillingUnit()),GetOwningPlayer(GetTriggerUnit())) == true
endfunction

function CDS_Att_Conditions takes nothing returns boolean
    return IsPlayerAlly(GetOwningPlayer(GetKillingUnit()),GetOwningPlayer(GetTriggerUnit())) == true
endfunction

function Init_CDS_Actions takes nothing returns nothing
local trigger t
local trigger d
set G_MISC_CDS_Health = 15
set G_MISC_CDS_Exp = 5
set G_MISC_CDS_Gold = 0

set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition(t, Condition(function CDS_Att_Conditions))
call TriggerAddAction( t, function CDS_Att_Actions )

set d = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( d, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(d, Condition(function CDS_Death_Conditions))
call TriggerAddAction( d, function CDS_Death_Actions )
endfunction

//===========================================================================
function InitTrig_CDS takes nothing returns nothing
    local trigger gg_trg_CDS = CreateTrigger(  )
    call TriggerAddAction( gg_trg_CDS, function Init_CDS_Actions )
endfunction
 
JASS:
globals
real G_MISC_CDS_Health
real G_MISC_CDS_Exp
integer G_MISC_CDS_Gold
endglobals

function CDS_Death_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetKillingUnit()
local player p = GetOwningPlayer(a)

call DisplayTextToPlayer(p,0,0,"Deny!")
endfunction

function CDS_Att_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetAttacker()
local real l = GetUnitState(u, UNIT_STATE_LIFE)
local real ml = GetUnitState(u, UNIT_STATE_MAX_LIFE)
local real p = 0.00

call DisplayTextToPlayer(GetOwningPlayer(a),0,0,"Unit Attack!")

    if (ml == 0) then
        set p = 0.0
    else
        set p =  l / ml * 100.0
    endif

if (p > G_MISC_CDS_Health) then
call IssueImmediateOrder(a,"stop")
call DisplayTextToPlayer(GetOwningPlayer(a),0,0,"Attack permission abort!")
endif

set u = null
set a = null
endfunction

function CDS_Death_Conditions takes nothing returns boolean
    return IsPlayerAlly(GetOwningPlayer(GetKillingUnit()),GetOwningPlayer(GetTriggerUnit())) == true
endfunction

function CDS_Att_Conditions takes nothing returns boolean
    return IsPlayerAlly(GetOwningPlayer(GetAttacker()),GetOwningPlayer(GetTriggerUnit())) == true
endfunction

function Init_CDS_Actions takes nothing returns nothing
local trigger t
local trigger d
set G_MISC_CDS_Health = 15.00
set G_MISC_CDS_Exp = 5
set G_MISC_CDS_Gold = 0

set t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition(t, Condition(function CDS_Att_Conditions))
call TriggerAddAction( t, function CDS_Att_Actions )

set d = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( d, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition(d, Condition(function CDS_Death_Conditions))
call TriggerAddAction( d, function CDS_Death_Actions )
endfunction

//===========================================================================
function InitTrig_CDS takes nothing returns nothing
    local trigger gg_trg_CDS = CreateTrigger(  )
    call TriggerAddAction( gg_trg_CDS, function Init_CDS_Actions )
endfunction
Thats the new version. No errors, no infos just does not trigger anything.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,259
JASS:
library CDS initializer Init
    globals
        real G_MISC_CDS_Health = 0.15
        real G_MISC_CDS_Exp = 5
        integer G_MISC_CDS_Gold = 0
        public trigger t = CreateTrigger()
        public trigger d = CreateTrigger()
    endglobals

    private function Death_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit a = GetKillingUnit()
        local player p = GetOwningPlayer(a)

        call DisplayTextToPlayer(p,0,0,"Deny!")
        set u = null
        set a = null
        set p = null
    endfunction

    private function Att_Actions takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local unit a = GetAttacker()
        local real p = GetWidgetLife(u) / GetUnitState(u, UNIT_STATE_MAX_LIFE)
        
        call DisplayTextToPlayer(GetOwningPlayer(a),0,0,"Unit Attack!")

        if p > G_MISC_CDS_Health then
            call IssueImmediateOrder(a,"stop")
            call DisplayTextToPlayer(GetOwningPlayer(a),0,0,"Attack permission abort!")
        endif
        set u = null
        set a = null
    endfunction

    private function Death_Conditions takes nothing returns boolean
        return IsUnitAlly(GetKillingUnit(),GetOwningPlayer(GetTriggerUnit()))
    endfunction

    private function Att_Conditions takes nothing returns boolean
        return IsUnitAlly(GetAttacker(),GetOwningPlayer(GetTriggerUnit()))
    endfunction

    private function Init takes nothing returns nothing
        call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_ATTACKED )
        call TriggerAddCondition(t, Condition(function Att_Conditions))
        call TriggerAddAction( t, function Att_Actions )

        call TriggerRegisterAnyUnitEventBJ( d, EVENT_PLAYER_UNIT_DEATH )
        call TriggerAddCondition(d, Condition(function Death_Conditions))
        call TriggerAddAction( d, function Death_Actions )
    endfunction
endlibrary

Fixed, optimized and improved.
Also tested and assured to work.
 
Status
Not open for further replies.
Top