Noob Jass Questions

Status
Not open for further replies.
H

Hjalle

Guest
Ok, this is among my first triggers i made in Jass, since i learned it yesterday. :)

So i wanted to make a hero revive trigger that revives the hero at the position where it died after 10 seconds.

So first I wonder if this is a good way to do it:

JASS:
function If_Hero takes nothing returns boolean
    if( not( IsUnitType( GetTriggerUnit() , UNIT_TYPE_HERO ) == true ) ) then
        return false
    endif
    return true
endfunction

function Revive_Hero takes nothing returns nothing
    local real X = GetUnitX( GetTriggerUnit() )
    local real Y = GetUnitY( GetTriggerUnit() ) 
    call DisplayTextToForce( GetPlayersAll(), "|cffff0000Hello there, a hero died|r." )
    call TriggerSleepAction( 10.00 )
    call ReviveHeroLoc( GetTriggerUnit(), OffsetLocation( GetRectCenter( GetEntireMapRect() ), X, Y ), true )
endfunction

//===========================================================================
function InitTrig_TRevive takes nothing returns nothing
    set gg_trg_TRevive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TRevive, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_TRevive, function Revive_Hero )
endfunction


Secondly, can i create a local unit variable in, lets say the first function. And call it u, set it to triggering unit.
Then create another function that takes unit u, the local variable to another function?

At last, How come my revive trigger revive creeps that dies to?
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
First question:

Nice that you used reals instead of locations, but, you used them in such a way that you didn't gain anything. You could have used instead of ReviveHeroLoc:

JASS:
native          ReviveHero          takes unit whichHero, real x, real y, boolean doEyecandy returns boolean


Which means it would look like this:

JASS:
call ReviveHero(GetTriggerUnit,X,Y,true)


In your way you took reals and converted them to a location, what is slower and cuases leaks.

Also as for the condition you could switch:

JASS:
function If_Hero takes nothing returns boolean
    if( not( IsUnitType( GetTriggerUnit() , UNIT_TYPE_HERO ) == true ) ) then
        return false
    endif
    return true
endfunction


With:

JASS:
function If_Hero takes nothing returns boolean
    return IsUnitType(GetTriggerUnit() ,UNIT_TYPE_HERO) == true
endfunction


Faster and easier to read. Lastly if you want to show the message only to the owning player you should have done instead of

JASS:
call DisplayTextToForce( GetPlayersAll(), "|cffff0000Hello there, a hero died|r." )


This:

JASS:
call DisplayTextToPlayer(GetOwningPlayer(GetTriggerUnit()),0.,0., "|cffff0000Hello there, a hero died|r." )


Second Question:

If I understood you question properly, then yes indeed. For example:

JASS:

function Kill_U takes unit u returns nothing
    call KillUnit(u)
endfunction

function U takes nothing returns nothing
    local unit u = GetTriggerUnit
    call Kill_U(u)
endfunction


Third Question:

Yoour trigger should revive only heros as far as I can see, even if they are creeps.
 
H

Hjalle

Guest
Thank you, it helps alot.
And yes, you understood my question :).
+rep

But as for the last question,
I tried killing creeps with my hero.
And when a creep died, i saw the "Hello there, a hero died." message.

It seems like the trigger ignore my condition.
Is anything wrong with it?

edit:
can't give you rep ATM, sry :(

And btw, another question.
Do i get memory leaks while using local locations (point)?
 

Omni

Ultra Cool Member
Reaction score
37
Do i get memory leaks while using local locations (point)?

yep

and i'll+rep him <3

ps.
if u use the x, and y revive hero native a Rheias said it wont leak of course ^^
 

Omni

Ultra Cool Member
Reaction score
37
yep, you can remove local locations just like globals.

and at the end of a function, null variables!

eg.

JASS:
set L = null


because it will leave a tiny leak if you dont

Edit:

so first remove the location w/ call Remove blabla
and then at the end do : set ? = null
units,locations,groups etc. have to be nulled if you dont want it to leak a bit ^____^
 
H

Hjalle

Guest
Ok, thank you again.

Hm, still needs help on why that message keeps showing up even if i dont kill a hero. I just want the message to be showed if a hero dies.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Ok, this is among my first triggers i made in Jass, since i learned it yesterday. :)

So i wanted to make a hero revive trigger that revives the hero at the position where it died after 10 seconds.

So first I wonder if this is a good way to do it:

JASS:
function If_Hero takes nothing returns boolean
    if( not( IsUnitType( GetTriggerUnit() , UNIT_TYPE_HERO ) == true ) ) then
        return false
    endif
    return true
endfunction

function Revive_Hero takes nothing returns nothing
    local real X = GetUnitX( GetTriggerUnit() )
    local real Y = GetUnitY( GetTriggerUnit() ) 
    call DisplayTextToForce( GetPlayersAll(), &quot;|cffff0000Hello there, a hero died|r.&quot; )
    call TriggerSleepAction( 10.00 )
    call ReviveHeroLoc( GetTriggerUnit(), OffsetLocation( GetRectCenter( GetEntireMapRect() ), X, Y ), true )
endfunction

//===========================================================================
function InitTrig_TRevive takes nothing returns nothing
    set gg_trg_TRevive = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_TRevive, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddAction( gg_trg_TRevive, function Revive_Hero )
endfunction


Secondly, can i create a local unit variable in, lets say the first function. And call it u, set it to triggering unit.
Then create another function that takes unit u, the local variable to another function?

At last, How come my revive trigger revive creeps that dies to?

You need to add this to the InitTrig after the event:
JASS:
call TriggerAddCondition(gg_trg_TRevive, Condition(function If_Hero))


:)
 
H

Hjalle

Guest
doh! :banghead:

Thank you :) forgot about that...

Edit:
Since im still in the learning off JASS im converting the GUI to JASS to see how to do different tasks,
And when using JAssCraft i noticed a small thing, the native list. So i found the function there i was looking for, "SetPlayerStateBJ" (i was changing players gold). I clicked it and found that it was using "AdjustPlayerStateBJ", I also found that in the native list so i clicked that and found this:
"AdjustPlayerStateSimpleBJ".

What i understood all will do almost the same thing.
So I wodered if it is better to use "AdjustPlayerStateSimpleBJ" instead of "SetPlayerStateBJ"?
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Oh sorry. I was just looking at YOUR script (that's not updated with the fix) not the replies.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
doh! :banghead:

Thank you :) forgot about that...

Edit:
Since im still in the learning off JASS im converting the GUI to JASS to see how to do different tasks,
And when using JAssCraft i noticed a small thing, the native list. So i found the function there i was looking for, "SetPlayerStateBJ" (i was changing players gold). I clicked it and found that it was using "AdjustPlayerStateBJ", I also found that in the native list so i clicked that and found this:
"AdjustPlayerStateSimpleBJ".

What i understood all will do almost the same thing.
So I wodered if it is better to use "AdjustPlayerStateSimpleBJ" instead of "SetPlayerStateBJ"?

JASS:
function SetPlayerStateBJ takes player whichPlayer, playerstate whichPlayerState, integer value returns nothing
    local integer oldValue = GetPlayerState(whichPlayer, whichPlayerState)
    call AdjustPlayerStateBJ(value - oldValue, whichPlayer, whichPlayerState)
endfunction


AdjustPlayerStateBJ is:
JASS:
function AdjustPlayerStateBJ takes integer delta, player whichPlayer, playerstate whichPlayerState returns nothing
    // If the change was positive, apply the difference to the player&#039;s
    // gathered resources property as well.
    if (delta &gt; 0) then
        if (whichPlayerState == PLAYER_STATE_RESOURCE_GOLD) then
            call AdjustPlayerStateSimpleBJ(whichPlayer, PLAYER_STATE_GOLD_GATHERED, delta)
        elseif (whichPlayerState == PLAYER_STATE_RESOURCE_LUMBER) then
            call AdjustPlayerStateSimpleBJ(whichPlayer, PLAYER_STATE_LUMBER_GATHERED, delta)
        endif
    endif

    call AdjustPlayerStateSimpleBJ(whichPlayer, whichPlayerState, delta)
endfunction


AdjustPlayerStateSimpleBJ is:
JASS:
function AdjustPlayerStateSimpleBJ takes player whichPlayer, playerstate whichPlayerState, integer delta returns nothing
    call SetPlayerState(whichPlayer, whichPlayerState, GetPlayerState(whichPlayer, whichPlayerState) + delta)
endfunction


=========

Finally, after going through 3 BJs, you reach SetPlayerState. This is the best native to use out of all four of those. Here is the native parameters:
JASS:
native SetPlayerState   takes player whichPlayer, playerstate whichPlayerState, integer value returns nothing


:D

Remember that:
Natives > BJ

Except for some like PolledWait > TriggerSleepAction where PolledWait is a BJ and you know the rest. :p
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232

SFilip

Gone but not forgotten
Reaction score
633
To make your condition code a LOT easier, change:

JASS:
function If_Hero takes nothing returns boolean
    if( not( IsUnitType( GetTriggerUnit() , UNIT_TYPE_HERO ) == true ) ) then
        return false
    endif
    return true
endfunction


to:

JASS:
function If_Hero takes nothing returns boolean
  return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO)
endfunction
You need a == true there like Rheias wrote it.
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == true
IsUnitType is the only function that requires this though.
 
H

Hjalle

Guest
I have that working now,

But now another questiom :)

I tried to make it so the killer gets gold when he kills a hero. ( Well, i have only made the message yet )
I used this trigger:

JASS:
    local player killer = GetOwningPlayer( GetKillingUnit() )
    local player victim = GetOwningPlayer( GetTriggerUnit() )
    local integer bonusgold = GetRandomInt( 40, 60 )
    call DisplayTextToForce( GetPlayersAll(), (GetPlayerName( killer )) + &quot; have just killed &quot; + (GetPlayerName( victim )) + &quot; for another |cffffcc00&quot; + bonusgold + &quot;|r gold!&quot; )


I get the error:
Code:
Invalid Type for specified operator.

Please, may you tell me what I have made wrong?
 

SFilip

Gone but not forgotten
Reaction score
633
You used bonusgold without converting it to string first.
So...
Code:
call DisplayTextToForce( GetPlayersAll(), (GetPlayerName( killer )) + " have just killed " + (GetPlayerName( victim )) + " for another |cffffcc00" + bonusgold + "|r gold!" )
should be
Code:
call DisplayTextToForce( GetPlayersAll(), (GetPlayerName( killer )) + " have just killed " + (GetPlayerName( victim )) + " for another |cffffcc00" + [B]I2S(bonusgold)[/B] + "|r gold!" )

If you want it more optimized, here's a nifty trick I learned from phyrex1an's tutorial
Code:
call DisplayTextToPlayer( GetLocalPlayer(), 0., 0., (GetPlayerName( killer )) + " have just killed " + (GetPlayerName( victim )) + " for another |cffffcc00" + I2S(bonusgold) + "|r gold!" )
Only displays the message to human players.
 
H

Hjalle

Guest
Ah, thanks alot :D

Well, I see no use for it to be displayed to human players, but may be useful in the future, so I keep that in mind.:cool:


(may come up more questions later :eek: )


EDIT:
Another question ^^

Hmm, I don't understand how to make global variables without going (CTRL-B),
yes, i know i should put "udg_" in front of the name...
But how do i declare it? I can't find my answear using the search function.

JASS:
local string udg_playercolor[0] = &quot;|cffff0000&quot;
local string udg_playercolor[1] = &quot;|cff0000ff&quot;
etc...

It seems... strange...
 
Status
Not open for further replies.
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