• 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] Attack With Jass

Status
Not open for further replies.
Level 37
Joined
Aug 14, 2006
Messages
7,602
Hey.

I have a JASS script that worked before but doesn't work anymore. Someone might know what's wrong? Here's the JASS script. By the way, the campaign I'm making doesn't work with vJASS.

This JASS fuction suppose to be like a basic attack in the game. However, when I try to attack with this spell, it just swings the unit's hammer but actually doesn't do anything.

The one who can help will have some REP.

JASS:
//TESH.scrollpos=25
//TESH.alwaysfold=0
//===========================================================================
//===================================SETUP===================================
//===========================================================================
function BookAttack_AID_ATTACK takes nothing returns integer
    return 'A61L' //Change to your attack ability Id
endfunction

function BookAttack_GROUP takes nothing returns group
    //Make a UnitGroup variable
    return udg_TempGroup //Edit. Should be "udg_" plus whatever name you used.
endfunction
//===========================================================================
//================================END OF SETUP===============================
//===========================================================================

function BookAttack_SET_GROUP takes group g returns nothing
    set g = CreateGroup()
endfunction

function BookAttack_DoTrue takes nothing returns boolean
   return true
endfunction

function BookAttack_Select takes nothing returns nothing
    if IsUnitInGroup(GetTriggerUnit(), BookAttack_GROUP()) then //Checks if unit is already in the group, preventing double select.
    else
        call GroupAddUnit(BookAttack_GROUP(), GetTriggerUnit())
    endif
endfunction

function BookAttack_Deselect takes nothing returns nothing
    call GroupRemoveUnit(BookAttack_GROUP(), GetTriggerUnit())
endfunction

function BookAttack_Attack takes nothing returns nothing
    if GetSpellTargetUnit() != null then
        call GroupTargetOrderById(BookAttack_GROUP(), 851983, GetSpellTargetUnit())
    else
        call GroupPointOrderByIdLoc(BookAttack_GROUP(), 851983, GetSpellTargetLoc())
    endif
endfunction

function BookAttack_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == BookAttack_AID_ATTACK()
endfunction

function InitTrig_BookAttack takes nothing returns nothing
    local trigger t1 = CreateTrigger()
    local trigger t2 = CreateTrigger()
    local trigger t3 = CreateTrigger()
    local integer i = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t1, Player(i), EVENT_PLAYER_UNIT_SPELL_CAST, Condition(function BookAttack_DoTrue))
        call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_SELECTED, Condition(function BookAttack_DoTrue))
        call TriggerRegisterPlayerUnitEvent(t3, Player(i), EVENT_PLAYER_UNIT_DESELECTED, Condition(function BookAttack_DoTrue))
        set i = i + 1
        exitwhen i == 12
    endloop
    call TriggerAddCondition(t1, Condition(function BookAttack_Conditions))
    call TriggerAddAction(t1, function BookAttack_Attack)
    call TriggerAddAction(t2, function BookAttack_Select)
    call TriggerAddAction(t3, function BookAttack_Deselect)
    call BookAttack_SET_GROUP(BookAttack_GROUP())
    //Cleanup
    set t1 = null
    set t2 = null
    set t3 = null
    set i = 0
endfunction
 
Level 10
Joined
Jun 26, 2005
Messages
236
I don't really understand what you are trying to do, but
JASS:
GetSpellTargetLoc()
leaks. You must first store it in a local location, then remove and null it.
 
Level 2
Joined
Jun 15, 2007
Messages
12
I don't really understand what you are trying to do, but
JASS:
GetSpellTargetLoc()
leaks. You must first store it in a local location, then remove and null it.


Youre wrong. If you don't store it to a varible, it doesn't leak.


JASS:
function CONDITION takes nothing returns boolean
return IsUnitAlly(GetTriggerUnit(), GetTriggerPlayer())
endfunction

^ doesn't leak at all

JASS:
function CONDITION takes nothing returns boolean
local unit u = GetTriggerUnit()
return IsUnitAlly(u, GetTriggerPlayer())
endfunction

^ leaks

JASS:
function CONDITION takes nothing returns boolean
local unit u = GetTriggerUnit()

if IsUnitAlly(u, GetTriggerPlayer()) then
set u = null
return true
else
return false
endif

endfunction

^ doesn't leak either, but the first example is the simplest/least lamest way.
 
Level 29
Joined
Jul 29, 2007
Messages
5,174
Beside the fact that this is coded like crap and that over-kill of unneeded functions, those '851983' are supposed to be order strings, not integers.
I can assume the one who coded this meant it to be OrderId2String(851983)


The final result should look like this
JASS:
function BookAttack_Attack takes nothing returns nothing
    if GetSpellTargetUnit() != null then
        call GroupTargetOrderById(BookAttack_GROUP(), OrderId2String(851983), GetSpellTargetUnit())
    else
        call GroupPointOrderByIdLoc(BookAttack_GROUP(), OrderId2String(851983), GetSpellTargetLoc())
    endif
endfunction
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Beside the fact that this is coded like crap and that over-kill of unneeded functions, those '851983' are supposed to be order strings, not integers.
I can assume the one who coded this meant it to be OrderId2String(851983)


The final result should look like this
JASS:
function BookAttack_Attack takes nothing returns nothing
    if GetSpellTargetUnit() != null then
        call GroupTargetOrderById(BookAttack_GROUP(), OrderId2String(851983), GetSpellTargetUnit())
    else
        call GroupPointOrderByIdLoc(BookAttack_GROUP(), OrderId2String(851983), GetSpellTargetLoc())
    endif
endfunction

Ghost, you're wrong. Why would GroupTargetOrderById take a STRING as argument, instead of an ID (integer) ... Would make no sense.
The script works perfectly, but the problem he had after importing was that he was already using the TempGroup variable for group leaks in GUI, which means the group was constantly destroyed and obviously, issuing an attack order on a destroyed group doesn't do a lot.

Youre wrong. If you don't store it to a varible, it doesn't leak.
I'm pretty sure it does.
 
Status
Not open for further replies.
Top