Little Jass system not working

dudeim

New Member
Reaction score
22
Heej all,

i've now been bussy with jass for some days and made a little exp system.. But well it doesn't work it automaticly crashes wc3 to the starting screen of wc3 and JassCraft doesn't give any errors at all.. well here's the system

JASS:
// this checks if unit in range of killing hero is a friend 
   function CheckGroup takes nothing returns boolean
   return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(GetTriggerUnit()))
endfunction 

// this is used for floating text doesn't need any changes except if you want to change the exp per creep
 function Floating_Text_Friends takes nothing returns nothing
    local unit k = GetKillingUnit()
    local unit d = GetDyingUnit()
    local location loc = GetUnitLoc(k)
    local real Bonus_Exp = GetRandomReal((0.5 * GetUnitLevel(d)), (1.0 * GetUnitLevel(d)))
    local group friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function CheckGroup))
    local real Start_Exp = GetUnitLevel(k) *9
    local real Total_Exp
    local integer Divide = CountUnitsInGroup(friends)
    local real Total_Exp_Killer
    local unit u = GetEnumUnit()
    
    set Total_Exp = (Start_Exp + Bonus_Exp) / Divide
    set Total_Exp_Killer = Total_Exp * GetRandomReal(1.5,2.0)
    
    call GroupRemoveUnit(friends, k)  
   
    call CreateTextTagUnitBJ( ( ( "+" + I2S(R2I(Total_Exp_Killer)) ) + "EXP!!!" ), GetEnumUnit(), 0, 7, 50.00, 100, 100, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetForceOfPlayer(GetOwningPlayer(k)) )
    call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 90.00, 90 )
    call SetTextTagPermanent( GetLastCreatedTextTag(), false )
    call SetTextTagLifespan( GetLastCreatedTextTag(), 2.00 )
    call AddHeroXP(k,R2I(Total_Exp_Killer),false)
    
    call CreateTextTagUnitBJ( ( ( "+" + I2S(R2I(Total_Exp)) ) + "EXP!!!" ), GetEnumUnit(), 0, 7, 50.00, 100, 100, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetForceOfPlayer(GetOwningPlayer(u)) )
    call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 90.00, 90 )
    call SetTextTagPermanent( GetLastCreatedTextTag(), false )
    call SetTextTagLifespan( GetLastCreatedTextTag(), 2.00 )
    call AddHeroXP(u,R2I(Total_Exp),false)
    
    set k = null
    set d = null
    set u = null
    call RemoveLocation(loc)
    set loc = null
endfunction

function Players_For_FT_Friends takes nothing returns nothing
local unit k = GetKillingUnit()
local group friends = GetUnitsInRangeOfLocMatching(1200,GetUnitLoc(k), Condition(function CheckGroup)) 


    call ForGroup(friends, function Floating_Text_Friends )
        set k = null
endfunction

 function Floating_Text_Killer takes nothing returns nothing
    local unit k = GetKillingUnit()
    local unit d = GetDyingUnit()
    local location loc = GetUnitLoc(k)
    local real Bonus_Exp = GetRandomReal((0.5 * GetUnitLevel(d)), (1.0 * GetUnitLevel(d)))
    local group friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function CheckGroup))
    local real Start_Exp = GetUnitLevel(k) *9
    local real Total_Exp
    local integer Divide = CountUnitsInGroup(friends)
    local real Total_Exp_Killer
    
    set Total_Exp_Killer = Start_Exp + Bonus_Exp  
   
    call CreateTextTagUnitBJ( ( ( "+" + I2S(R2I(Total_Exp_Killer)) ) + "EXP!!!" ), GetEnumUnit(), 0, 7, 50.00, 100, 100, 0 )
    call ShowTextTagForceBJ( false, GetLastCreatedTextTag(), GetPlayersAll() )
    call ShowTextTagForceBJ( true, GetLastCreatedTextTag(), GetForceOfPlayer(GetOwningPlayer(GetEnumUnit())) )
    call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 90.00, 90 )
    call SetTextTagPermanent( GetLastCreatedTextTag(), false )
    call SetTextTagLifespan( GetLastCreatedTextTag(), 2 )
    call AddHeroXP(k,R2I(Total_Exp),false)
    
        call RemoveLocation(loc)
    set loc = null 
            set k = null
    set d = null
endfunction

function Players_For_FT_Killer takes nothing returns nothing
     local unit k = GetKillingUnit()
     local location loc = GetUnitLoc(k)
local group friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function CheckGroup))



    call ForGroup( friends, function Floating_Text_Killer )
        set k = null
                call RemoveLocation(loc)
    set loc = null 
endfunction

// floating text end

 function Add_Exp takes nothing returns nothing
    local unit k = GetKillingUnit()
    local unit d = GetDyingUnit()
    local location loc = GetUnitLoc(k)
    local real Bonus_Exp = GetRandomReal((0.5 * GetUnitLevel(d)), (1.0 * GetUnitLevel(d)))
    local group friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function CheckGroup))
    local real Start_Exp = GetUnitLevel(k) *9
    local real Total_Exp
    local integer Divide = CountUnitsInGroup(friends)
    local real Total_Exp_Killer
        local trigger trig = CreateTrigger(  )
    
    set Total_Exp = (Start_Exp + Bonus_Exp) / Divide
    set Total_Exp_Killer = Start_Exp + Bonus_Exp
        call TriggerAddAction(trig,function Players_For_FT_Friends)
                set k = null
    set d = null
            call RemoveLocation(loc)
    set loc = null 
endfunction 

// this is where i check if the player is hunting alone or if he has any friends with him

function Something_Actions takes nothing returns nothing
    local unit k = GetKillingUnit()
    local unit d = GetDyingUnit()
        local location loc = GetUnitLoc(k)
    local real Bonus_Exp = GetRandomReal((0.5 * GetUnitLevel(d)), (1.0 * GetUnitLevel(d)))
    local group friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function CheckGroup))
    local real Start_Exp = GetUnitLevel(k) *9
    local real Total_Exp
    local integer Divide = CountUnitsInGroup(friends)
    local real Total_Exp_Killer
    
if Divide == 1 then
    set Total_Exp = Start_Exp + Bonus_Exp

    call ForGroup(friends, function Players_For_FT_Killer)
    
elseif Divide > 1 then
        call ForGroup( friends, function Add_Exp )
    set k = null
    set d = null
            call RemoveLocation(loc)
    set loc = null 
endif    
 endfunction 
 
//===========================================================================
function InitTrig_Something takes nothing returns nothing
    local trigger trig = CreateTrigger(  )
       call TriggerRegisterAnyUnitEventBJ( trig, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( trig, function Something_Actions )
endfunction


It's probably really ineffecient and it will leak something if you see some please tell them

Thanks:D
Rep+ for helping
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
EDIT: aw crap, I'm blind

nvm

btw your code is leaking here: GetUnitLoc(k)

and all the non-nulled locals
 

Silvenon

New Member
Reaction score
19
I'm not completely sure, but I'll post all the possibilities.

JASS:
function GroupCheckCond_func takes nothing returns boolean
    return ( IsUnitAlly(GetEnumUnit(), GetOwningPlayer(GetTriggerUnit())) == true )
endfunction


I'm pretty sure that GetTriggerUnit() doesn't work when you call it from a boolexpr function. I suggest you do something like this:

JASS:
function GroupCheckCond_func takes nothing returns boolean
    return ( IsUnitAlly(GetEnumUnit(), GetOwningPlayer(bj_ghoul[100])) == true )
endfunction 

// ...
// ...

local group friends
// ...
set bj_ghoul[100] = d
set friends = GetUnitsInRangeOfLocMatching(1200,GetUnitLoc(k), Condition(function GroupCheckCond_func))


bj_ghoul is an already existing global array variable in wc3, you can use the indexes that are either around 100 or higher. I suggest you don't go much lower because (I think) it can somehow screw AI up. So instead of making a new global, you can just use that one.

There's a location leak when you call GetUnitLoc(k), watch out for that:

JASS:
local group friends
local location loc = GetUnitLoc(k) // declare a location variable
// ...
set bj_ghoul[100] = d
set friends = GetUnitsInRangeOfLocMatching(1200,loc, Condition(function GroupCheckCond_func)) // use it here
// ...
// ...
call RemoveLocation(loc) // destroy it afterward
set loc = null // also null it


There's something else:

JASS:


I'm not sure, but this might cause a crash if the killing unit isn't a creep (because then it can't have levels).

Er, about this function:

JASS:
function Players_For_FT_Killer takes nothing returns nothing
     local unit k = GetKillingUnit()
local group friends = GetUnitsInRangeOfLocMatching(1200,GetUnitLoc(k), Condition(function GroupCheckCond_func))

    call ForGroup( friends, function Floating_Text_Killer )
endfunction


GetKillingUnit() won't work here, because it's another function (and event responses can't be transmitted between functions). You can also use bj_ghoul variable here.

Same thing here:

JASS:
 function Floating_Text_Killer takes nothing returns nothing
    local unit k = GetKillingUnit()
    local unit d = GetDyingUnit()
    // ...
 endfunction


Use bj_ghoul (or create a global variable). Btw, you're also leaking a location here:

JASS:
local group friends = GetUnitsInRangeOfLocMatching(1200,GetUnitLoc(k), Condition(function GroupCheckCond_func))


And in Players_For_FT_Friends function too.

I think that is everything that might have caused the crash (texttags on empty unit variables....ugh, that might have caused a crash too).

EDIT: Lol, I'm an idiot. Both even responses work, the boolexpr and the ForGroup one, I just tested it. So nevermind everything I said except the leaks.
Besides that, I don't see anything. Maybe the texttags are causing a crash somewhere, I don't know. Sorry :)
 

GooS

Azrael
Reaction score
154
crashes wc3 to the starting screen of wc3

Hmm, just gotta check since noone else seems to have asked, you do save the map before testing it right? Otherwise the compiler isn't run properly (?) and it will cause a crash to main screen wc3 even before load screen.

To those more knowing, is this needed in JASS or just vJASS?

//==GooS
 

dudeim

New Member
Reaction score
22
It will just not work:( and this time it doesn't give any error at all:(
Updated Code
 

Silvenon

New Member
Reaction score
19
Is there any other code in your map that might have caused the crash? Are there any imported stuff that could malfunction? If you don't know what else could be the problem, I suggest maybe posting the map?
 

dudeim

New Member
Reaction score
22
Well it's simple if i have the trigger enabled it crashes if i don't it doesn't crash.. so it has to be that trigger maybe some of you copy to a simple map and try if it works?? maybe that will come to conclusions??
Edit: does it matter if i use v1.23 of wc3 cus some things of NewGen didn't work on 1.23 only on 1.21 or so?
 

Tom Jones

N/A
Reaction score
437
I made a copy/paste of your code into a random map I have, and I didn't experience any crashes.

So, what you're going to do is disable that trigger, rename it, save the map, restart NewGen, open your map, enable the trigger, and try again.
 

dudeim

New Member
Reaction score
22
Well somehow it works thanks for that:p rep+

got another question about the system and a global question.

1. Is it more effecient to put ontop of the trigger this:

JASS:

globals
//the locals but now as globals
endglobals


would this be more effecient or handy? (the globals can be used in any func of the trigger right?)

2. can you put 2 conditions in a function so i check if a unit is a friend and a hero? is that possible with 2 returns or you have to do it in 1?
 

Tom Jones

N/A
Reaction score
437
1) What? If you mean;
JASS:
function ...
    globals
        unit u
        local unit v //This will deffinately make a syntax error.
    endglobals
endfunction
I would encourage you to knock that idea right out of your head. If you mean placement of the globals in the script, it doesn't matter because all global blocks will be moved to the top of the script by JassHelper, so there is no effiency to gain or lose.

2) Both actually:

JASS:
function ... returns boolean
    return IsUnitEnemy(...) and IsUnitType(...,UNIT_TYPE_HERO) == true
endfunction

function ... returns boolean
    if IsUnitAlly(...) then
        return false
    elseif IsUnitType(...,UNIT_TYPE_HERO) == false then
        return false
    endif
    return true
endfunction
On a side note, functions will return at the first return statement they meet, so doing as such will not give you the reult you want:
JASS:
function ... returns boolean
    return IsUnitEnemy(...) //Function returns here.
    return IsUnitType(...,UNIT_TYPE_Hero) == true //This will never be executed.
endfunction
 

dudeim

New Member
Reaction score
22
well i mean with the globals that i put em on top like

JASS:

//no functions are before the globals

globals
//the globals
endglobals

//this is where the first func starts.

function one takes nothing returns nothing
//actions
endfunction

//etc


so if i had it like this i can use every global inside the trigger doesn't matter in what function (because making in all function alot of locals again it doesn't help for the readability)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top