- Joined
- Oct 29, 2007
- Messages
- 1,184
As I've learned about jass I figured that GUI has crappy performance. That's why I want to change some of the triggers in my map to jass. I need help converting this trigger:
Here's what I made:
Can someone please look at this and correct the script? The script should create grass around the player if the number of grass is less than 16. Also I would like to know how to get rid of those BJ's, CountUnitsInGroup. I give +rep to people who help me.
-
Grass
-
Events
-
Time - Every 0.04 seconds of game time
-
-
Conditions
-
Actions
-
Custom script: local integer a
-
Custom script: set a = 1000
-
Custom script: set udg_tmp_region = Rect ( 0, 0, 0, 0 )
-
For each (Integer tmp_integer) from 1 to 4, do (Actions)
-
Loop - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Life of Player[tmp_integer]) Not equal to 0.00
-
-
Then - Actions
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
detect_up[tmp_integer] Equal to 1
-
-
Then - Actions
-
Set tmp_loc2 = (Position of Player[tmp_integer])
-
Set tmp_loc = (tmp_loc2 offset by 800.00 towards (Facing of Player[tmp_integer]) degrees)
-
Custom script: call RemoveLocation(udg_tmp_loc2)
-
-
Else - Actions
-
Set tmp_loc = (Position of Player[tmp_integer])
-
-
-
Custom script: call SetRect ( udg_tmp_region, GetLocationX(udg_tmp_loc) - (a * 0.5), GetLocationY(udg_tmp_loc) - (a * 0.5), GetLocationX(udg_tmp_loc) + (a * 0.5), GetLocationY(udg_tmp_loc) + (a * 0.5) )
-
Set tmp_group[1] = (Units in tmp_region matching ((Unit-type of (Matching unit)) Equal to Grass))
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Number of units in tmp_group[1]) Less than 16
-
-
Then - Actions
-
For each (Integer A) from 1 to (16 - (Number of units in tmp_group[1])), do (Actions)
-
Loop - Actions
-
Set tmp_loc2 = (Random point in tmp_region)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
-
(Terrain type at tmp_loc2) Equal to Village Fall - Short Grass
-
-
Then - Actions
-
Unit - Create 1 Grass for Player 5 (Yellow) at tmp_loc2 facing (Random angle) degrees
-
Set tmp_real = (Random real number between 90.00 and 120.00)
-
Animation - Change (Last created unit)'s size to (tmp_real%, tmp_real%, tmp_real%) of its original size
-
Animation - Change (Last created unit)'s animation speed to 0.00% of its original speed
-
-
Else - Actions
-
-
-
-
Custom script: call RemoveLocation(udg_tmp_loc)
-
-
Else - Actions
-
-
Custom script: call RemoveLocation(udg_tmp_loc2)
-
Custom script: call DestroyGroup(udg_tmp_group[1])
-
-
Else - Actions
-
-
-
-
Custom script: call RemoveRect ( udg_tmp_region )
-
-
Here's what I made:
JASS:
function Trig_Create_Grass_Condition takes nothing returns boolean
return ( GetUnitTypeId(GetFilterUnit()) == 'h005' )
endfunction
function Trig_Create_Grass_Actions takes nothing returns nothing
local group g
local integer a = 1000
local integer i = 1
local rect r
local real n
local real x
local real x1
local real y
local real y1
loop
if (GetUnitState(udg_Player[i], UNIT_STATE_LIFE) != 0) then
if (udg_detect_up[i] == 1) then
set x1 = GetUnitX(udg_Player[i])
set y1 = GetUnitY(udg_Player[i])
set x = x + 800 * Cos(GetUnitFacing(udg_Player[i]) * bj_DEGTORAD)
set y = y + 800 * Sin(GetUnitFacing(udg_Player[i]) * bj_DEGTORAD)
else
set x = GetUnitX(udg_Player[i])
set y = GetUnitY(udg_Player[i])
endif
call SetRect ( r, x - (a * 0.5), y - (a * 0.5), x + (a * 0.5), y + (a * 0.5) )
call GroupEnumUnitsInRect(g, r, Condition(function Trig_Create_Grass_Condition))
if (CountUnitsInGroup(g) < 16) then
loop
set x = GetRandomReal(GetRectMinX(r),GetRectMaxX(r))
set y = GetRandomReal(GetRectMinY(r),GetRectMaxY(r))
call CreateUnitAtLoc(Player(4), 'h005', Location(x, y), GetRandomInt(0, 360))
set n = GetRandomReal(0.9, 1.1)
call SetUnitScale(GetEnumUnit(), n, n, n)
if (CountUnitsInGroup(g) == 16) then
exitwhen true
endif
endloop
endif
call RemoveRect(r)
endif
set i = i + 1
if (i == 4) then
exitwhen true
endif
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_Create_Grass takes nothing returns nothing
set gg_trg_Create_Grass = CreateTrigger( )
call TriggerRegisterTimerEventPeriodic( gg_trg_Create_Grass, 0.04 )
call TriggerAddAction( gg_trg_Create_Grass, function Trig_Create_Grass_Actions )
endfunction
Can someone please look at this and correct the script? The script should create grass around the player if the number of grass is less than 16. Also I would like to know how to get rid of those BJ's, CountUnitsInGroup. I give +rep to people who help me.