• 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.

Custom Script unit created with locations

Status
Not open for further replies.
  • Unit - Create 1 Tornado Armor for (Owner of Caster) at Point1 facing Default building facing degrees
What is the JASS function (custom script for me) for creating the unit at coordinates X and Y? To be more clear, how can I create units using coordinates.

Also, does using coordinates leak? And if so, how do I clear the leak?

EDIT: Also how do I set x equal to the x coordinate of a unit on a map (same for y, but I had just assumed they were similar). Right now I've only been setting x and y with cosine/sine so it hasnt come up, but just for future reference. I do know how to move a unit with locations so don't bother with that -_-

Thanks in advance
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit

No, using co-ordinates do not leak.

You could do something like this:

  • Custom script: call CreateUnit(Player(0), 'hfoo', GetUnitX(udg_your_unit), GetUnitY(udg_your_unit), 0)
Where Player(0) = Player 1
Player(1) = Player 2 etc

Where 'hfoo' is the raw code of the unit that you want to create (Which can be seen when pressing control + d inside the object editor)

Where GetUnitX is a function that gets the x co-ordinate of a unit and where udg_your_unit is a unit variable created in the variable editor called: your_unit. The same goes for GetUnitY.

real face ofcourse is the degrees in which the unit is facing.

I hope this helps...
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Theres a function for points that converts an X and a Y value to a point. You'd have to set it to a variable and clear it though, because point functions leak
 
New problem.

  • Wind Armor
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Wind Amor
    • Actions
      • Set Caster = (Triggering unit)
      • Set l = (Real((Level of Wind Amor for Caster)))
      • Custom script: set udg_x[1] = GetUnitX(udg_Caster)
      • Custom script: set udg_y[1] = GetUnitY(udg_Caster)
      • Set a = 45.00
      • Set r = 240.00
      • Set x[2] = (x[1] + ((Cos(a)) x r))
      • Set y[2] = (y[1] + ((Sin(a)) x r))
      • Custom script: call CreateUnit(GetTriggerPlayer(), 'u002', udg_x[2], udg_y[2], 0)
      • Set u = (Last created unit)
      • Set t = (3.50 + (3.00 x l))
      • Custom script: set udg_Handle = GetHandleId(udg_Caster)
      • Hashtable - Save t as 1 of Handle in Hashtable
      • Hashtable - Save a as 2 of Handle in Hashtable
      • Hashtable - Save Handle Ofu as 3 of Handle in Hashtable
      • Unit Group - Add Caster to g1
      • Trigger - Turn on Wind Armor Loop <gen>
      • Game - Display to (All players) the text: debug 2
      • Unit - Kill u
I ran this trigger time and time again (without the last function), and it did nothing. Then I added the last function, kill u, and it didn't kill the unit. Is there some weird thing with the custom script creating function, where it doesn't work with last created unit?

  • Custom script: call CreateUnit(GetTriggerPlayer(), 'u002', udg_x[2], udg_y[2], 0)
    • Set u = (Last created unit)
It isn't setting u to be the unit I just made.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
First, you forgot the "r" in "armor"

Second, im not into angles yet (lol) but Cos and Sin involve divison, right? So my guess is that its *somehow* dividing by 0 and causing a thread crash. Put debugs before the 2, than one between, than one after and see if any appear.
 
First, you forgot the "r" in "armor"

Second, im not into angles yet (lol) but Cos and Sin involve divison, right? So my guess is that its *somehow* dividing by 0 and causing a thread crash. Put debugs before the 2, than one between, than one after and see if any appear.

Sine and Cosine are the shape of a circle, to be more specific a function to find a piece of it when given X data. Similar to how you can solve for X by swapping around pieces of an equation, you can find the length of a hypotenuse by swapping sine/cosine into a division process. To simulate the movement of a circle though, I'm using it right. I don't think I really gave that great of an explainanation but basically we use it for circular movement in this instance.

@ Mag, it didn't work, or I didn't do it right. I just reverted back to using a point for the very first trigger to create the unit and assign last created unit, so it works now.
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
@ Mag, it didn't work, or I didn't do it right. I just reverted back to using a point for the very first trigger to create the unit and assign last created unit, so it works now.

its must work since i use this too, when u create unit with regulare gui then its do this

JASS:
  set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)

this is why u can get the last created unit because it is stored to there directly
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
its must work since i use this too, when u create unit with regulare gui then its do this

JASS:
  set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)

this is why u can get the last created unit because it is stored to there directly

This should work 100% Since it sets bj_lastCreatedUnit to be the unit that is created, meaning that you can use Last created unit in gui since it now points to the created unit.
Use this if you want to use Last created unit in GUI.

Magtheridon96 said:
You can't retrieve the last created unit if you're using CreateUnit.

Only the BJ sets bj_lastCreatedUnit to the unit you just created.

Why don't you do this:

  • Custom script: set udg_u = CreateUnit(GetTriggerPlayer(), 'u002', udg_x[2], udg_y[2], 0)

This could be a good alternative but last created unit will not respond to this because bj_lastCreatedUnit is not set. Use the stored unit variable u here instead.
 
Thank you for all the help everyone. I'm just starting to try to move away from really slow GUI functions into a little JASS, so it is hard for me.

  • set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
So this would set a unit created with this:

  • call CreateUnit(Player(0), 'hfoo', GetUnitX(udg_your_unit), GetUnitY(udg_your_unit), 0)
to last created unit, so then I could just do this

  • Set u = (Last created unit)
So the whole thing together would look like

  • Custom script: set udg_Handle = GetHandleId(udg_Caster)
  • Custom script: set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
  • Set u = (Last created unit)
Is that correct?
 
Level 17
Joined
Nov 13, 2006
Messages
1,814
Thank you for all the help everyone. I'm just starting to try to move away from really slow GUI functions into a little JASS, so it is hard for me.

  • set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
So this would set a unit created with this:

  • call CreateUnit(Player(0), 'hfoo', GetUnitX(udg_your_unit), GetUnitY(udg_your_unit), 0)
to last created unit, so then I could just do this

  • Set u = (Last created unit)
So the whole thing together would look like

  • Custom script: set udg_Handle = GetHandleId(udg_Caster)
  • Custom script: set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
  • Set u = (Last created unit)
Is that correct?

but u can do this directly Custom script: set udg_Dummy = CreateUnitAtLoc(id, unitid, loc, face) then u store directly to variable but better if u use local variables because dont will be touched when this trigger run again (global variables changed but locals stay till end of ur trigger)

why u need the handleid?

about creatunit things
1st player id, so something like this Player(0) if player 1 or Player(1) if player 2
2nd unitid = the unit rawcode (look like this 'Hpal' for paladin) also u can get if u use unittype (in gui have unit type variable but acctually that just a integer variable what store rawcodes like how i wrote)
3. this is the point but called in jass location
4. i dont need to tell nothing for this :D

(my advice use jass craft, its good help really if u dont use vjass, u can simple convert ur trigger to custom text and copy that function what u want into jass craft and jass craft tell to u what do that function)
 
Level 14
Joined
Apr 20, 2009
Messages
1,543
But the point of setting u to CreateUnit was to increase code efficiency.

If you use my line, "u" will already be set to that unit.

Yes, basically this:

  • Custom script: set udg_u = CreateUnitAtLoc(id, unitid, loc, face)
is faster then this:

  • Custom script: set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
  • Set u = (Last created unit)
Since you set u to be the created unit instead of setting bj_lastCreatedUnit to set u to be the last created unit.
Therefore it is more efficient to use Magtheridon96's solution.
 
Status
Not open for further replies.
Top