• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Erm... I'm Kind Of A New JASS Triggerer, I Hope You'll Help Me Here...

Status
Not open for further replies.
Level 31
Joined
Jul 10, 2007
Messages
6,306
Google Lua.

It's run via Grimoire.

Lua code (used here with textmacros) taken from LUA_JASS_IO snippet
JASS:
//! textmacro LUA_JASS_IO takes FILE_NAME
    //! i do
        //! i local PATH = "jass\\luajass.$FILE_NAME$.j"

        //! i function jassread()
            //! i local f = io.open(PATH, "r")
            //! i if (f == nil) then
                //! i return nil
            //! i end
            //! i local code = f:read("*all")
            //! i f:close()

            //! i return code
        //! i end

        //! i function jasswrite(code)
            //! i local f = io.open(PATH, "w")
            //! i f:write(code)
            //! i f:close()
        //! i end
    //! i end
//! endtextmacro

//! refers to preprocessor command
//! i refers to lua code

Executed via grimoire

This is an ObjectMerger multiline script takes from LUA_GET_OBJECT_ID demonstration
JASS:
//! externalblock extension=lua ObjectMerger $FILENAME$
    //! runtextmacro LUA_GET_OBJECT_ID()

    //generates an object id for hpea (peasant) of object type units
    //! i local object obj = getobjectid("hpea", "units")

    //create the object using the retrieved object id
    //! i setobjecttype("units")
    //! i createobject("hpea", obj)
        //modifications
//! endexternalblock

This is single line taken from UnitIndexer
//! external ObjectMerger w3a Adef OUIN anam "Unit Indexing" ansf "(Unit Indexing)" aart "" arac 0

Notice that lua is not used in single line as the parameters are passed directly in.
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
I'm curious, since I'm not very familiar with LUA, what is the equivalent of the last line of code you posted in an LUA script? Also what are setobjecttype and createobject? Where are these functions defined or given?
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
->what is the equivalent of the last line of code you posted in an LUA script?
//! external ObjectMerger w3a Adef OUIN anam "Unit Indexing" ansf "(Unit Indexing)" aart "" arac 0 ??

That is a call to a grimoire function that creates objects. w3a stands for wc3 ability. Adef is the base ability id, OUIN is the ability id assigned to the new object. ObjectMerger refers to the exe used. anam is the ame of ability, ansf is tooltip, aart is the ability art and arac is ability race.

---------------------
The setobjecttype and createobject functions are defined in the ObjectMerger exe (located in grimext folder).

To learn more about grimoire, take a look at the grimoire manual. I've attached it to this post.
 

Attachments

  • GrimexManual.zip
    17.7 KB · Views: 50
Level 18
Joined
Jan 21, 2006
Messages
2,552
There is no information about createobject and setobjecttype in the GrimEx manual; I have read the GrimEx manual before. I was not asking for a vague interpretation of what that external code does, instead I was asking for specific details on where functions like these two are explicitly defined.

There are a whole whack of these functions:

JASS:
//! map.w3x lookuppaths ( w3u | w3t | w3b | w3d | w3a | w3h | w3q ) originalid newid { changeid [ level | variation ] value }

How exactly is one to know that there is a function called lookuppaths (I don't see an API anywhere) and that it takes these parameters; not that I'm really sure of what this code even does.
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
It can... all of those snippets I've put up can be cnp'd into WE and run.

If you put this in WE
//! external ObjectMerger w3a Adef OUIN anam "Unit Indexing" ansf "(Unit Indexing)" aart "" arac 0

and you save your map, close your map, then open it and look in Units, you'll see a new unit called Unit Indexing.

:O?!
Where exactly in WE? Map header?
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
In Trigger Editor as JASS code like you'd put in normal JASS. Requires vJASS to run.

Many of the upper coders use code like the stuff I've put up. The little line came directly out of UnitIndexer, which is a system in JASS section.

Some coders have also worked at, like I said, dynamically generating JASS scripts. If you look through JASS section, u'll see a few Lua recourses by me. They were only accepted because they can be directly run in WE (one of the things azlier remarked on when he was pondering over the validity of lua in JASS section, rofl rofl).
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
I have a little question, I really hope you guys don't mind because I just came back from overseas and my mind could be a bit rusty about JASS, so what does it mean when you do this:

JASS:
function What_Does_Set_Do takes nothing returns nothing
set Example_Function
// What does the 'set' thingy do?
endfunction

Please do help me... I'm really sorry if it's a burden...
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
If you read the line of code is almost makes a perfectly good sentence, where "KILLER" is the name of your unit and GetTriggerUnit() returns the "triggering unit":

"Set KILLER equal to GetTriggerUnit"
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
I bet what's confusing you is that you're "set"ing something to a function, which is code that is ran by the game.

But you're actually just setting a variable to the information that is "returned."

For example, if I wrote function dogrunsfast takes nothing returns real
and then did return 50, every time I did set DogSpeed = dogrunsfast() the DogSpeed variable would be set to 50.

JASS:
function dogrunsfast takes nothing returns real
     return 50
endfunction

function DogGoesVroom takes nothing returns nothing
     local real DogSpeed
     set DogSpeed = dogrunsfast()
endfunction

DogSpeed will be set to 50. You can make this more useful if you have dogrunsfast take unit dog and add some extra calls into it that manipulates the dogs values, then return GetUnitMoveSpeed(dog). You'd have to put a unit between the ( ) of dogrunsfast() though.

JASS:
function dogrunsfast takes unit dog returns real
     call SetUnitMoveSpeed(dog, GetUnitMoveSpeed(dog) + 100)
     return GetUnitMoveSpeed(dog)
endfunction

function DogGoesVroom takes nothing returns nothing
     local real DogSpeed
     set DogSpeed = dogrunsfast(GetTriggerUnit())
endfunction

It can be helpful to realize that all GetTriggerUnit() and CreateUnit() are just functions that are already in the game, made by the game makers.

It may also benefit you to see a useful function I made that illustrates this key concept:

JASS:
function GetPlayerTextColor takes player p returns string//If someone calls GetPlayerTextColor, sets a string to = GetPlayerTextColor, or just shoves this guy in a place the requires you to input a string, this function will be ran.
//Now, we just check which player was put in the ( ) when this function was called.
    if p == Player(0) then
        return "|cffff0000"
    elseif p == Player(1) then
        return "|cff0000ff"
    elseif p == Player(2) then
        return "|cff40e0d0"
    elseif p == Player(3) then
        return "|cff800080"
    elseif p == Player(4) then
        return "|cffffff00"
    elseif p == Player(5) then
        return "|cffffa500"
    elseif p == Player(6) then
        return "|cff00ff00"
    elseif p == Player(7) then
        return "|cffdb7093"
    elseif p == Player(9) then
        return "|cffadd8e6"
    elseif p == Player(10) then
        return "|cff006421"
    elseif p == Player(11) then
        return "|cff592e0d"
    endif
 return "" //If it's none of those players we don't change the color. Simple as that.
endfunction

This simple function saves me the headache of looking up the color codes for text and having to write it out for every single different player. I use it when I'm doing something like telling all players someone has left the game.

JASS:
call DisplayTextToForce(GetPlayersAll(), GetPlayerTextColor(LeavingPlayer) + " This dude|r has left the game.")

Hopefully this helps you understand JASS a little better.
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Hehe! I think I'm ready for a test, could one of you give me a pop quiz on JASS please? Like, having a theory and practical question too, I wanna test whether what I learnt is correct:)
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Hmm... After much questioning and research, I'll give it a try, please do try to correct me if I'm wrong:

JASS:
function takes unit returns real
// Well, I was thinking, since it takes a Test Unit and returns a Real Value, which in this case, is the number the Movement Speed is. Hence my choice of 'takes' and 'returns'.
call SetUnitMoveSpeed (TestUnit Player 1, 300)
// I found this in JASSCraft and thought it would be related to a Unit's Movement Speed, since the unit isn't specified in the question, I chose to use TestUnit instead, Player 1 would be the 'WhichUnit' log and 300 would be the new Movement Speed
endfunction

Please do grade me, and give me corrections too, thank you everyone for helping me out in my JASS learning journey!
 
Level 18
Joined
Jan 21, 2006
Messages
2,552
When you call a function, such as Player must have its parameters contained in ( ). Also, you haven't given a name to your parameter you've simply stated it as unit; you need to give it a name so that you can reference it inside the function.

One more thing, the parameters that you have given for SetUnitMoveSpeed are incorrect - the method only takes two parameters, a specific unit and a real value of the new movement speed.
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
How about this:

JASS:
function Test takes unit(TestUnit) returns real
// Well, I was careless about that, but would the 'Takes' and 'Returns' part be correct this time?
call GetUnitMoveSpeed (TestUnit Player(1))
// I assumed that the movespeed wouldn't be default for the unit (Meaning the unit has items such as Boots) so I didn't use the "Default Move Speed" one.
call SetUnitMoveSpeed (TestUnit Player(1), 300)
endfunction

Please do give me a grade at the end:)
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
Ok...first of all,function GetUnitMoveSpeed requires only unit,no need to put a player. Then...the function SetUnitMoveSpeed requires unit and real.
Also you need to return something at the end of the function by adding a line "return [value]" at the end. The value type must correspond the type the function returns (In this case - real).
So it should be:
JASS:
function Test takes unit TestUnit returns real
    call SetUnitMoveSpeed(TestUnit,300.0)
    return GetUnitMoveSpeed(TestUnit)
endfunction
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Omg I'm so sorry... I'll promise to do better in the next test...

PS: I hope you could give more tests please:)
 
Level 20
Joined
Jul 6, 2009
Messages
1,885
PS: You've failed...horribly!
Omg I'm so sorry... I'll promise to do better in the next test...

PS: I hope you could give more tests please:)

Note the sarcasm tags :p

A test? hmm...
Make a function that takes the cathetuses of a right-angled triangle and returns the hypotenuse (using Pythagorean theorem).
Simple enough.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
Just saying, Reinventing the Craft is really really really not what you want right now. Keep learning the basics, write some stuff on your own and become familiar with the language.

Also:
In a right triangle, the cathetus (originally from the Greek word Κάθετος; plural: catheti), commonly known as a leg, is either of the sides that are adjacent to the right angle. It is called occasionally called the periphrasis ("side about the right angle").

If you don't know the Pythagorean theorem, it's a theorem that relates the cathetuses to the hypotenuse of a right-angled triangle. Google it if you're not sure.
 
Level 13
Joined
Jul 26, 2008
Messages
1,009
Yeah me neither. Anyways. Lets give you a very practical test that you would normally use in JASS.

Set a local variable in one function. The local variable should be an integer that gets a units ability level, the Trigger Unit.

Then, set a global variable in that same function that uses the local variable to decide how much damage it'll do, preferably 80 per level. Use the rawcode 'A000'. Then in that same function make it set a units move speed to 50 per level.

In a new function, which returns a boolean and takes nothing, set the GetFilterUnit()'s life to it current life minus the damage from the global variable. Remember to return a boolean in the function at the end of the code (Anything past a returns won't run).

These are the natives you should be using and their parameters:

GetUnitAbilityLevel( unit whichUnit, abilityrawcode whichrawcode )
SetUnitMoveSpeed( unit whichUnit, real whatSpeed )
SetWidgetLife( widget whichUnit, real howMuchLife )
GetWidgetLife( widget whichUnit )
GetFilterUnit( )
GetTriggerUnit( )

Good luck! Answers in the hidden tags.

JASS:
function HurtsEm takes nothing returns boolean
    call SetWidgetLife( GetFilterUnit(), GetWidgetLife(GetFilterUnit()) - DAMAGE )
 return false
endfunction

function SetHurts takes nothing returns nothing
    local integer lvl = GetUnitAbilityLevel( GetTriggerUnit(), 'A000' )
    set DAMAGE = lvl*80
    call SetUnitMoveSpeed( GetTriggerUnit(), 50*lvl )
endfunction
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Yeah me neither. Anyways. Lets give you a very practical test that you would normally use in JASS.

Set a local variable in one function. The local variable should be an integer that gets a units ability level, the Trigger Unit.

Then, set a global variable in that same function that uses the local variable to decide how much damage it'll do, preferably 80 per level. Use the rawcode 'A000'. Then in that same function make it set a units move speed to 50 per level.

In a new function, which returns a boolean and takes nothing, set the GetFilterUnit()'s life to it current life minus the damage from the global variable. Remember to return a boolean in the function at the end of the code (Anything past a returns won't run).

These are the natives you should be using and their parameters:

GetUnitAbilityLevel( unit whichUnit, abilityrawcode whichrawcode )
SetUnitMoveSpeed( unit whichUnit, real whatSpeed )
SetWidgetLife( widget whichUnit, real howMuchLife )
GetWidgetLife( widget whichUnit )
GetFilterUnit( )
GetTriggerUnit( )

Good luck! Answers in the hidden tags.

JASS:
function HurtsEm takes nothing returns boolean
    call SetWidgetLife( GetFilterUnit(), GetWidgetLife(GetFilterUnit()) - DAMAGE )
 return false
endfunction

function SetHurts takes nothing returns nothing
    local integer lvl = GetUnitAbilityLevel( GetTriggerUnit(), 'A000' )
    set DAMAGE = lvl*80
    call SetUnitMoveSpeed( GetTriggerUnit(), 50*lvl )
endfunction

I'm really sorry... I failed once again. T_T

PS: Could you give me one more, a simpler one, please? Thank you:)
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Please do bear with my mistakes, and help me out...

JASS:
function Test takes location returns unit  
call CasterCastAbilityAOE
returns CreateUnitAtLoc(Player(1), A000, GetSpellTargetLoc, returns A000) 
endfunction

Thank you guys! And rate me please, like a score over 100:)
I'm really sorry if I'm troubling anyone...
 
Please do bear with my mistakes, and help me out...

JASS:
function Test takes location returns unit  
call CasterCastAbilityAOE
returns CreateUnitAtLoc(Player(1), A000, GetSpellTargetLoc, returns A000) 
endfunction

Thank you guys! And rate me please, like a score over 100:)
I'm really sorry if I'm troubling anyone...

ahmmm, the call there is not needed, and will only cause your code to crash...

and you don't actually need to make the function return a unit unless the code which calls it needs a unit...

your usage of the rawcode is also wrong, rawcodes should be inside '', ex. 'A000'

and as the first one, you forgot to name the location parameter...

and the way you returned the unit is also wrong, it should be return not returns

and your parameters for CreateUnitAtLoc are also wrong...

my suggestion is that, you get a copy of JNGP if don't have one, and use the function list there to learn how each function works...

EDIT: oh, TRD beat me to it...

anyway, TRD did it that way because you did it that way... were assuming that you're already feeding the function with the location parameter since you made it take a location parameter...
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Thank you so much... I'm really sorry, but I do have a Christmas Request... Would one of you give me a test please? Thank you so much!
 
Level 12
Joined
Apr 4, 2010
Messages
862
Okay Adiktuz:)
I'm really sorry for giving that request earlier...

JASS:
function Trig_test_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventLeave( gg_trg_test, Player(0) )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

Hurr, does this leak? :D very simple question. And wut is the Event in GUI form?
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
JASS:
function Trig_test_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetRectCenter(GetPlayableMapRect()), bj_UNIT_FACING )
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    set gg_trg_test = CreateTrigger(  )
    call TriggerRegisterPlayerEventLeave( gg_trg_test, Player(0) )
    call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction

Hurr, does this leak? :D very simple question. And wut is the Event in GUI form?

Ewww ugly code :D

JASS:
function Durr takes nothing returns nothing
    call CreateUnit(Player(0), 'hfoo', GetSpellTargetX(), GetSpellTargetY(), 0)
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddAction(t, function Durr)
    set t = null
endfunction

This should work. If you get an error in this line: call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST) then just add a null parameter like this: call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST, null)

Can't remember how many arguments it takes :D
 
Level 12
Joined
Apr 4, 2010
Messages
862
Ewww ugly code :D

JASS:
function Durr takes nothing returns nothing
    call CreateUnit(Player(0), 'hfoo', GetSpellTargetX(), GetSpellTargetY(), 0)
endfunction

//===========================================================================
function InitTrig_test takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddAction(t, function Durr)
    set t = null
endfunction

This should work. If you get an error in this line: call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST) then just add a null parameter like this: call TriggerRegisterPlayerUnitEvent(t, EVENT_PLAYER_UNIT_SPELL_CAST, null)

Can't remember how many arguments it takes :D

Who told you to give the ANSWER?!?!?!?!? :ogre_rage:

Edit: It leaks, he destroy leaks, im speechless.
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Haha... Actually, I might need a bit of guiding about the 'Leaks' part. After reading some guides, I still don't get what Leaks are in Triggering, I know they are bad and can be a little annoying, but what exactly do they do and how do you remove them? Do tell me in layman terms because I am a little... Dumb.
 
Level 12
Joined
Apr 4, 2010
Messages
862
Haha... Actually, I might need a bit of guiding about the 'Leaks' part. After reading some guides, I still don't get what Leaks are in Triggering, I know they are bad and can be a little annoying, but what exactly do they do and how do you remove them? Do tell me in layman terms because I am a little... Dumb.

really easy.

First - Set a Variable point.

JASS:
    set udg_>YOURVARIABLE< = GetUnitLoc(GetLastCreatedUnit())

Second - Remove variable point

JASS:
    call RemoveLocation(udg_>YOURVARIABLE<)
 
Level 19
Joined
Oct 15, 2008
Messages
3,231
Now, what does that do? And how does a Leak look like?

JASS:
function Leak takes nothing returns nothing
endfunction

I'm really confused. Because it seems to me from your example that a Leak is... Well, it's nothing (If you take and remove something, doesn't that give you nothing?).
 
Level 12
Joined
Apr 4, 2010
Messages
862
Level 19
Joined
Oct 15, 2008
Messages
3,231
Like I said in the post before, I'm really confused with the guide's explanation, so I'd love another one that you can give in Layman terms:)
 
Status
Not open for further replies.
Top