• 🏆 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!

[Trigger] Setting points in a circumfrence

Status
Not open for further replies.
Level 9
Joined
Jun 7, 2008
Messages
440
Just as the title says. I was hoping i could get help on a few things.
1) Setting a point behind an attacking unit.
2) Setting points at a certain spot, In a circle. (In GUI for example):
  • Actions
    • Set TempPoint[0] = Position of (casting unit) offset by 500 towards 45 degrees
    • Set TempPoint[1] = Position of (casting unit) offset by 500 towards 90 degrees
  • // E.T.C
Can anyone help me?
 
Level 16
Joined
May 1, 2008
Messages
1,605
Seas =)

You meen something like that:
  • Behind Attacking Unit
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set TempPoint = ((Position of (Attacking unit)) offset by 100.00 towards ((Facing of (Attacking unit)) - 180.00) degrees)
  • Circle
    • Events
    • Conditions
    • Actions
      • Set TempPoint = (Position of (Triggering unit))
      • For each (Integer A) from 1 to 10, do (Actions)
        • Loop - Actions
          • Set TempPointArray[(Integer A)] = (TempPoint offset by 500.00 towards ((Real((Integer A))) x 36.00) degrees)
  • No Leaks
    • Events
    • Conditions
    • Actions
      • -------- First Trigger --------
      • Custom script: call RemoveLocation(udg_TempPoint)
      • -------- Second Trigger --------
      • Custom script: call RemoveLocation(udg_TempPointArray[GetForLoopIndexA()])
      • Custom script: call RemoveLocation(udg_TempPoint)
 
Level 8
Joined
Feb 15, 2009
Messages
463
JASS:
local real x = GetUnitX(unit) + 500 * Cos(45.*bj_DEGTORAD)
local real y = GetUnitY(unit) + 500 * Sin(45.*bj_DEGTORAD)


straight work with Coordinations or put following to get it as a location:

local location l = Location(x,y)
 
Level 7
Joined
Jul 19, 2008
Messages
58
Heres Dr Booms thing in Jass if you want to see it

the point behind target
JASS:
function facing_Actions takes nothing returns nothing
local location loc
local location loc2
local unit u = GetTriggerUnit()

set loc = GetUnitLoc(u)
set loc2 = PolarProjectionBJ(loc,200,GetUnitFacing(u)+180)

call RemoveLocation(loc)
call RemoveLocation(loc2)
set u = null

//something else
endfunction

//===========================================================================
function InitTrig_facing takes nothing returns nothing
    set gg_trg_facing = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_facing, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_facing, function facing_Actions )
endfunction

and the points in a circle
JASS:
function facing2_Actions takes nothing returns nothing
local location loc
local location loc2
local integer a
local integer b

// set loc = GetRectCenter(???)
// set loc = GetUnitLoc(???)

set a = 1
set b = 10
loop
    exitwhen a > b
    set loc2 = PolarProjectionBJ(loc,400,R2I(a)*36)
    //Do Something?
    call RemoveLocation(loc2)
    set a = a + 1
endloop

call RemoveLocation(loc)
endfunction

//===========================================================================
function InitTrig_facing_Copy takes nothing returns nothing
    set gg_trg_facing_Copy = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_facing_Copy, EVENT_PLAYER_UNIT_ATTACKED )
    call TriggerAddAction( gg_trg_facing_Copy, function facing2_Actions )
endfunction
 
Level 9
Joined
Jun 7, 2008
Messages
440
I got the rest of it no problem. The only thing that i couldnt figure out how to do was to set the points in a circle using only natives. Thanks and + rep for the help on points behind the attacking unit. :)
 
Level 9
Joined
Nov 28, 2008
Messages
704
Using only natives for the behind is rather easy.

JASS:
//Using units u and u2, which you have aquired, and if you want the point behind u:

local real x
local real y
local real howFarBehind = 500
local real angle = Atan2(GetUnitY(u) - GetUnitY(u2), GetUnitX(u) - GetUnitX(u2))

set x = Cos(angle) * howFarBehind
set y = Sin(angle) * howFarBehind

I may have put the u and u2's in the atan2 wrong, but I believe they are correct.

As for a circle, assuming you have point (x, y):

JASS:
local real radius = 500
local real array circleX
local real array circleY
local integer i = 100 //However many points you want goes here
local real angle = 0
local real angleChange = 2 * bj_PI / i

loop
    exitwhen i < 1
    set circleX[i] = x + Cos(angle)
    set circleY[i] = y + Sin(angle)
    set angle = angle + angleChange
    set i = i - 1
endloop

That assumes you know how radians work. If you dont, understand that radians are like degrees, but there are 2pi (or 6.28ish) rather than 360 degrees in a circle.
 
Status
Not open for further replies.
Top