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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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