- Joined
- Jul 10, 2006
- Messages
- 3,315
Is there a StringBreak snippet for making text tags that go on multiple lines?
I stumbled on one here: http://www.wc3jass.com/5016/system-wordwrap/
Is there a StringBreak snippet for making text tags that go on multiple lines?
I stumbled on one here: http://www.wc3jass.com/5016/system-wordwrap/
does the creator know that you can just put in \n and it will go to the next linebut its what i need and will work for now, thanks.
DisplayTimedTextToPlayer
is not the only native that uses strings, therefore you might need to break the lines manually? I, for example, found a similar library pretty useful multiple times already.function BoundInt takes integer i, integer min, integer max returns integer
return IMaxBJ(IMinBJ(i, max), min)
endfunction
function BoundReal takes real r, real min, real max returns real
return RMaxBJ(RMinBJ(r, max), min)
endfunction
does the creator know that you can just put in \n and it will go to the next linebut its what i need and will work for now, thanks.
set event = 0
set event = 1
function Parabola takes real h, real dr, real cdr returns real
return (4 * h / dr ) * ( dr - cdr ) * ( cdr / dr )
endfunction
/* How to call the function?? Parabola(height,distance,counterdistance)
It just needs height , distance , and the current distance.
Simply: If you are setting the unit fly height use this
Height : 300
Distance Range: 500
Current Distance: 0.00
Speed Plus: 18.00
In the looping trigger 0.03 adds the Current Distance to the Speed like this:
set Current Dist = Current Dist + Speed = 18.00 and so on...
( 300 ) ( 500. ) ( 18.00 )
call SetUnitFlyHeight(udg_YOUR_UNIT,Parabola(height,distance,currentdistance),0)
Simplify like this: 4 * height divided by distance equals 2.4 finished at the first procedure now go to 2nd.
2.4 * (500 - 18.) equal to 1182 go to 3rd or last procedure
1182 * (18. / 500) equal to 42.
*/
Sure, but it's been posted here a million and one times.
private function EnemyFilter takes nothing returns boolean
return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), tempPlayer) and UnitAlive(GetFilterUnit())
endfunction
function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean
local group g = CreateGroup()
local unit u
set tempPlayer = p
call GroupEnumUnitsInRange(g, x, y, radius, Condition(function EnemyFilter))
set u = FirstOfGroup(g)
call DestroyGroup(g)
set g = null
if u == null then
return false
endif
set u = null
return true
endfunction
I would rather call it IsEnemyInRangeXYOld thread is old. Made this just now.
JASS:private function EnemyFilter takes nothing returns boolean return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), tempPlayer) and UnitAlive(GetFilterUnit()) endfunction function IsEnemyInRangeOfLoc takes player p, real x, real y, real radius returns boolean local group g = CreateGroup() local unit u set tempPlayer = p call GroupEnumUnitsInRange(g, x, y, radius, Condition(function EnemyFilter)) set u = FirstOfGroup(g) call DestroyGroup(g) set g = null if u == null then return false endif set u = null return true endfunction
private function EnemyFilter takes nothing returns boolean
return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), tempPlayer) and UnitAlive(GetFilterUnit())
endfunction
function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean
set tempPlayer = p
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, Condition(function EnemyFilter))
return FirstOfGroup(bj_lastCreatedGroup) != null
endfunction
function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean
local unit FoG
local group g = CreateGroup()
call GroupEnumUnitsInRange(g, x, y, radius, null)
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
call GroupRemoveUnit(g, FoG)
if IsUnitEnemy(FoG, p) and UnitAlive(FoG) then
call DestroyGroup(g)
set g = null
set FoG = null
return true
endif
endloop
call DestroyGroup(g)
set g = null
return false
endfunction
globals
group ENEMYINRANGE_GROUP = CreateGroup()
endglobals
function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean
local unit FoG
call GroupEnumUnitsInRange(ENEMYINRANGE_GROUP, x, y, radius, null)
loop
set FoG = FirstOfGroup(ENEMYINRANGE_GROUP)
exitwhen FoG == null
call GroupRemoveUnit(ENEMYINRANGE_GROUP, FoG)
if IsUnitEnemy(FoG, p) then
call GroupClear(ENEMYINRANGE_GROUP)
set FoG = null
return true
endif
endloop
return false
endfunction
function GroupEnumUnitsInCone takes group whichGroup, real x, real y, real radius, real direction, real angle returns group
local unit FoG
local group g = CreateGroup()
local real x2
local real y2
local real difference
call GroupEnumUnitsInRange(g, x, y, radius, null)
loop
set FoG = FirstOfGroup(g)
exitwhen FoG == null
set difference = DeNormalizeAngle(AngleBetweenCoordinates(x, y, GetWidgetX(FoG), GetWidgetY(FoG)) - direction)
if difference > -angle and difference < angle then
call GroupAddUnit(whichGroup, FoG)
endif
call GroupRemoveUnit(g,FoG)
endloop
call DestroyGroup(g)
set g = null
return whichGroup
endfunction
function NormalizeAngle takes real angle returns real
loop
if angle < 0 then
set angle = angle + 360
elseif angle >= 360 then
set angle = angle - 360
else
return angle
endif
endloop
return 0.
endfunction
function DeNormalizeAngle takes real angle returns real
loop
if angle <= -180 then
set angle = angle + 360
elseif angle > 180 then
set angle = angle - 360
else
return angle
endif
endloop
return 0.
endfunction
function AngleBetweenCoordinates takes real x1, real y1, real x2, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
local group g = GroupEnumUnitsInCone(CreateGroup(), X, Y, RADIUS, DIRECTION, ANGLE)
I would change that:
JASS:private function EnemyFilter takes nothing returns boolean return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), tempPlayer) and UnitAlive(GetFilterUnit()) endfunction function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean set tempPlayer = p call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, Condition(function EnemyFilter)) return FirstOfGroup(bj_lastCreatedGroup) != null endfunction
What trickery is this? Would you really?![]()
function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean
local unit u
call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, null)
loop
set u = FirstOfGroup(bj_lastCreatedGroup)
exitwhen u == null
call GroupRemoveUnit(bj_lastCreatedGroup, u)
if IsUnitEnemy(u, p) and UnitAlive(u) then
set u = null
return true
endif
endloop
return false
endfunction
If you want no global variables:
JASS:function IsEnemyInRangeXY takes player p, real x, real y, real radius returns boolean local unit u call GroupEnumUnitsInRange(bj_lastCreatedGroup, x, y, radius, null) loop set u = FirstOfGroup(bj_lastCreatedGroup) exitwhen u == null call GroupRemoveUnit(bj_lastCreatedGroup, u) if IsUnitEnemy(u, p) and UnitAlive(u) then set u = null return true endif endloop return false endfunction
GroupEnum... already clears the group so the clear action is wasteful. Also, bj_lastCreatedGroup never gets destroyed so you save from having to create a new one.
GUI only uses GetLastCreatedGroup, never the variable directly. You have been misinformed or have misunderstood the awesomeness
bj_lastCreatedUnit or bj_lastReplacedUnit
do you also useinstead of local units?JASS:bj_lastCreatedUnit or bj_lastReplacedUnit
May cause conflicts, when using it over a whole map script ...
but in general you can do so.
library Cinematic initializer Init
// Improved version of CinematicModeExBJ
//
globals
private boolean array allowCinematicSkip// Per player.
private integer PlayersInCineMode = 0
private force InCineMode = CreateForce()
endglobals
function IsPlayerInCineMode takes player whichPlayer returns boolean
return IsPlayerInForce(whichPlayer, InCineMode)
endfunction
private function RemoveFromCineForce takes nothing returns nothing
local player picked = GetEnumPlayer()
set allowCinematicSkip[GetPlayerId(picked)] = false
if IsPlayerInForce(picked, InCineMode) then
call ForceRemovePlayer(InCineMode, picked)
set PlayersInCineMode = PlayersInCineMode - 1
// Perform local code
if (GetLocalPlayer() == picked) then
// Use only local code (no net traffic) within this block to avoid desyncs.
call ShowInterface(true, bj_cineFadeContinueDuration)
call EnableUserControl(true)
call EnableOcclusion(true)
call VolumeGroupReset()
call EndThematicMusic()
call FogMaskEnable(true)
call FogEnable(true)
//call CameraSetSmoothingFactor(0)
endif
endif
if (PlayersInCineMode == 0) and IsTriggerEnabled(bj_cineSceneBeingSkipped) then
call DisableTrigger(bj_cineSceneBeingSkipped)
endif
set picked = null
endfunction
private function AddToCineForce takes nothing returns nothing
local player picked = GetEnumPlayer()
if (bj_rescueChangeColorUnit) then
set allowCinematicSkip[GetPlayerId(picked)] = true
if not (IsTriggerEnabled(bj_cineSceneBeingSkipped)) then
call EnableTrigger(bj_cineSceneBeingSkipped)
endif
endif
if not IsPlayerInForce(picked, InCineMode) then
call ForceAddPlayer(InCineMode, picked)
set PlayersInCineMode = PlayersInCineMode + 1
endif
set picked = null
endfunction
function CinematicMode takes boolean cineMode, force forForce, real interfaceFadeTime, boolean allowCineSkip, boolean disableFog returns nothing
if (cineMode) then
// Scrap game speed and random seed.
// Leave less important settings global
//
// global boolean with low potential usage.
set bj_rescueChangeColorUnit = allowCineSkip
call ForForce(forForce, function AddToCineForce)
if IsPlayerInForce(GetLocalPlayer(), forForce) then
call ShowInterface(false, interfaceFadeTime)
call EnableUserControl(false)
call EnableOcclusion(false)
if (disableFog) then
call FogEnable(false)
call FogMaskEnable(false)
endif
endif
// Perform global changes
call EnableWorldFogBoundary(false)
//call EnableDawnDusk(false)
else
set bj_cineModeAlreadyIn = false
set bj_cineFadeContinueDuration = interfaceFadeTime
call ForForce(forForce, function RemoveFromCineForce)
// Perform global changes
call EnableWorldFogBoundary(true)
//call EnableDawnDusk(bj_cineModePriorDawnDusk)
endif
endfunction
// May use a global for interface fade time.
private function OnEndCinematic takes nothing returns boolean
local integer id = GetPlayerId(GetTriggerPlayer())
if (allowCinematicSkip[id]) then
if (GetLocalPlayer() == Player(id)) then
call EndCinematicScene()
endif
call CinematicModee(false, bj_FORCE_PLAYER[id], bj_CINEMODE_INTERFACEFADE, false, false)
endif
return false
endfunction
// Register ESC event.
private function Init takes nothing returns nothing
local integer index = 0
local player p
set bj_cineSceneBeingSkipped = CreateTrigger()
loop
set p = Player(index)
if (GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING) and (GetPlayerController(p) == MAP_CONTROL_USER) then
call TriggerRegisterPlayerEvent(bj_cineSceneBeingSkipped, p, EVENT_PLAYER_END_CINEMATIC)
endif
set index = index + 1
exitwhen index == 12
endloop
call TriggerAddCondition(bj_cineSceneBeingSkipped, Condition(function OnEndCinematic))
call DisableTrigger(bj_cineSceneBeingSkipped)
endfunction
endlibrary
//Checks whether a point is clockwise to another point/vector
function IsPointClockwise takes real x1, real x2, real y1, real y2 returns boolean
return -x1*y2 + y1*x2 > 0.
endfunction
//c = center, s = start, e = end
function IsPointInSector takes real px, real py, real cx, real cy, real sx, real sy, real ex, real ey, real range returns boolean
set px = px - cx
set py = py - cy
return (not isClockwise(sx, px, sy, py)) and isClockwise(ex, px, ey, py) and (px*px) + (py*py) <= range*range
endfunction
library MathRound
function floor takes real r returns integer
local integer i = R2I(r)
if r == i then
return i
endif
if r > 0 then
return i
else // if r < 0 then
return i - 1
endif
endfunction
function ceil takes real r returns integer
local integer i = R2I(r)
if r == i then
return i
endif
if r > 0 then
return i + 1
else // if r < 0 then
return i
endif
endfunction
function round takes real r returns integer
if r > 0 then
return R2I(r + 0.5)
else // if r < 0 then
return R2I(r - 0.5)
endif
endfunction
function nearest_floor takes real r, real n returns real
return floor(r / n) * n
endfunction
function nearest_ceil takes real r, real n returns real
return ceil(r / n) * n
endfunction
function nearest takes real r, real n returns real
return round(r / n) * n
endfunction
function round_places takes real r, real places returns real
local real ten_pow_places = Pow(10, places)
return round(r * ten_pow_places) / ten_pow_places
endfunction
endlibrary
local real array round_values
local real array nearest_values
local integer i
set round_values[0] = -0.6
set round_values[1] = -0.5
set round_values[2] = -0.4
set round_values[3] = 0.0
set round_values[4] = 0.4
set round_values[5] = 0.5
set round_values[6] = 0.6
set i = 0
loop
exitwhen i >= 7
call BJDebugMsg("floor(" + R2S(round_values[i]) + ") = " + R2S(floor(round_values[i])))
set i = i + 1
endloop
// output:
// floor(-0.6) = -1
// floor(-0.5) = -1
// floor(-0.4) = -1
// floor(0) = 0
// floor(0.4) = 0
// floor(0.5) = 0
// floor(0.6) = 0
set i = 0
loop
exitwhen i >= 7
call BJDebugMsg("ceil(" + R2S(round_values[i]) + ") = " + R2S(ceil(round_values[i])))
set i = i + 1
endloop
// output:
// ceil(-0.6) = 0
// ceil(-0.5) = 0
// ceil(-0.4) = 0
// ceil(0) = 0
// ceil(0.4) = 1
// ceil(0.5) = 1
// ceil(0.6) = 1
set i = 0
loop
exitwhen i >= 7
call BJDebugMsg("round(" + R2S(round_values[i]) + ") = " + R2S(round(round_values[i])))
set i = i + 1
endloop
// output:
// round(-0.6) = -1
// round(-0.5) = -1
// round(-0.4) = 0
// round(0) = 0
// round(0.4) = 0
// round(0.5) = 1
// round(0.6) = 1
set nearest_values[0] = -25
set nearest_values[1] = -24
set nearest_values[2] = 24
set nearest_values[3] = 25
set i = 0
loop
exitwhen i >= 4
call BJDebugMsg("nearest_floor(" + R2S(nearest_values[i]) + ", 10) = " + R2S(nearest_floor(nearest_values[i], 10)))
set i = i + 1
endloop
// output
// nearest_floor(-25, 10) = -30
// nearest_floor(-24, 10) = -30
// nearest_floor(24, 10) = 20
// nearest_floor(25, 10) = 20
set i = 0
loop
exitwhen i >= 4
call BJDebugMsg("nearest_ceil(" + R2S(nearest_values[i]) + ", 10) = " + R2S(nearest_ceil(nearest_values[i], 10)))
set i = i + 1
endloop
// output:
// nearest_ceil(-25, 10) = -20
// nearest_ceil(-24, 10) = -20
// nearest_ceil(24, 10) = 30
// nearest_ceil(25, 10) = 30
set i = 0
loop
exitwhen i >= 4
call BJDebugMsg("nearest(" + R2S(nearest_values[i]) + ", 10) = " + R2S(nearest(nearest_values[i], 10)))
set i = i + 1
endloop
// output:
// nearest(-25, 10) = -30
// nearest(-24, 10) = -20
// nearest(24, 10) = 20
// nearest(25, 10) = 30
set i = 5
loop
exitwhen i < 0
call BJDebugMsg("round_places(3.14159, " + I2S(i) + ") = " + R2SW(round_places(bj_PI, i), 1, 5))
set i = i - 1
endloop
// output:
// 3.14159
// 3.1416
// 3.142
// 3.14
// 3.1
// 3
function floor takes real r returns real
return I2R(R2I(r))
endfunction
function ceil takes real r returns real
return floor(r) + 1
end
function floor takes real r returns real
return I2R(R2I(r))
endfunction
floor(-0.4) => -1, not 0
function ceil takes real r returns real
return floor(r) + 1
end/*function*/
ceil(1) => 1, not 2
JASS:function floor takes real r returns real return I2R(R2I(r)) endfunction
That's truncation, i.e rounding towards 0, flooring is rounding towards -∞
floor(-0.4) => -1, not 0
JASS:function ceil takes real r returns real return floor(r) + 1 end/*function*/
That doesn't compile..., even if it did it would be wrong.
ceil(1) => 1, not 2
function RoundReal takes real r returns integer
if r > 0.00 then
return R2I(r + 0.50)
endif
return R2I(r - 0.50)
endfunction
Yes, agree.Rounding can be simplified:
FunctionNamesLikeThis not_like_this if you want to stick to intuitive syntax.
function Round takes real r, real nearest returns real
return R2I(r/nearest + 0.5) * nearest
endfunction
function RandomRectX takes rect r returns real
local real minX = GetRectMinX(r)
local real maxX = GetRectMaxX(r)
return GetRandomReal(minX,maxX)
endfunction
function RandomRectY takes rect r returns real
local real minY = GetRectMinY(r)
local real maxY = GetRectMaxY(r)
return GetRandomReal(minY,maxY)
endfunction
Perfect for shortening your codes
RectRandomX
makes more sense imo.How? You could directly do.Perfect for shortening your codes
GetRandomReal(GetRectMinX(r), GetRectMaxX(r))
How? You could directly do.
GetRandomReal(GetRectMinX(r), GetRectMaxX(r))
Except that produces procedural coupling. You are basically duplicating that code everywhere you want a random X/Y inside a rect.How? You could directly do.
GetRandomReal(GetRectMinX(r), GetRectMaxX(r))
GetRandomXInRect(r)
and GetRandomYInRect(r)
looks neater and keeps with the WC3 style of GetRandomLocInRect(r)
.function GetRandomXInRect takes rect whichRect returns real
return GetRandomReal(GetRectMinX(whichRect), GetRectMaxX(whichRect))
endfunction
function GetRandomYInRect takes rect whichRect returns real
return GetRandomReal(GetRectMinY(whichRect), GetRectMaxY(whichRect))
endfunction
function IsBuildingUnderConstruction takes unit u returns boolean
if IsUnitType(u,ConvertUnitType(14)) then
if GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0 then
return true
endif
else
if GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0 then
return true
endif
endif
return false
endfunction
JASS:function IsBuildingUnderConstruction takes unit u returns boolean if IsUnitType(u,ConvertUnitType(14)) then if GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0 then return true endif else if GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0 then return true endif endif return false endfunction
Gives a boolean if a unit is under construction.
Tested it with default buildings.
function IsBuildingUnderConstruction takes unit u returns boolean
if IsUnitType(u,ConvertUnitType(14)) then
return GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0
else
return GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0
endif
endfunction
ConvertUnitType(14)
? If there is a constant for it then better to use it. UNIT_TYPE_UNDEAD
function IsBuildingUnderConstruction takes unit u returns boolean
if IsUnitType(u,UNIT_TYPE_UNDEAD) then
return GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0
else
return GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0
endif
endfunction
JASS:function IsBuildingUnderConstruction takes unit u returns boolean if IsUnitType(u,ConvertUnitType(14)) then if GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0 then return true endif else if GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0 then return true endif endif return false endfunction
Gives a boolean if a unit is under construction.
Tested it with default buildings.
function IsBuildingUnderConstruction takes unit u returns boolean
if IsUnitType(u,ConvertUnitType(14)) then
return GetUnitAbilityLevel(u,'Abgs')!= 0 or GetUnitAbilityLevel(u,'Abgl')!= 0
endif
return GetUnitAbilityLevel(u,'Abds')!= 0 or GetUnitAbilityLevel(u,'Abdl')!= 0
endfunction