- Joined
- Nov 13, 2006
- Messages
- 1,814
Problems:
1. if i dont declare atleast 1 point to variable in map init then dont work the GetLocationZ(variable name), coz allways return with 0, if i declare example center of playable map in map init then work, but its leak too, no?
2. i failed so hard on make missile homming with parabola, 1st i tryed find functions what let me declare the the height where missile stop, so endZ but every formula was wrong t me because: or missile was above the unit, or on lower height than unit, or just made a whole parabola
overall now crashing sometimes the map when i try the homing missile, sometimes the missile going away or jump to sky etc
after i tryed every formule i decided , use parabola function and when only short left then i just decrease unit height step by step till he reach the target but this dont solved nothing, same problem about sometimes missile go to sky or somewhere else
3. first i tryed this functions (bottom\/) with vex dummy unit (after i made this http://www.wc3c.net/showthread.php?t=105830) but if i lock to target when missile do parabola, the missile angle is weird because lets say parabola is max height is higher than target unit height, arrow look to target direction even still arrow flying up.
same problem when dummy arrow flying up, if i focus to target location then also unrealistic when its fly up or on way :/
Jass triggers \/
called functions
timer trigger
test trigger
1. if i dont declare atleast 1 point to variable in map init then dont work the GetLocationZ(variable name), coz allways return with 0, if i declare example center of playable map in map init then work, but its leak too, no?
2. i failed so hard on make missile homming with parabola, 1st i tryed find functions what let me declare the the height where missile stop, so endZ but every formula was wrong t me because: or missile was above the unit, or on lower height than unit, or just made a whole parabola
overall now crashing sometimes the map when i try the homing missile, sometimes the missile going away or jump to sky etc
after i tryed every formule i decided , use parabola function and when only short left then i just decrease unit height step by step till he reach the target but this dont solved nothing, same problem about sometimes missile go to sky or somewhere else
3. first i tryed this functions (bottom\/) with vex dummy unit (after i made this http://www.wc3c.net/showthread.php?t=105830) but if i lock to target when missile do parabola, the missile angle is weird because lets say parabola is max height is higher than target unit height, arrow look to target direction even still arrow flying up.
same problem when dummy arrow flying up, if i focus to target location then also unrealistic when its fly up or on way :/
JASS:
// To make the dummy face a 2 dimensional orientation instantly:
function SetDummyFacing takes unit u, real angle returns nothing
call SetUnitLookAt(u, "Bone_Head", u, Cos(angle) * 1000000., Sin(angle) * 1000000., 0.)
endfunction
// To make the dummy face a 3 dimensional orientation instantly:
function SetDummyOrientation takes unit u, real x, real y, real z returns nothing
call SetUnitLookAt(u, "Bone_Head", u, x * 1000000., y * 1000000., z * 1000000.)
endfunction
//To make the dummy always face a particular unit, for homing missiles:
function SetDummyHomingTarget takes unit u, unit target returns nothing
call SetUnitLookAt(u, "Bone_Head", target, 0., 0., 0.)
endfunction
function DummyRecycle takes unit u returns nothing
if udg_Dummy_Index < udg_Dummy_Max and GetUnitTypeId(u)=='h000' then
set udg_Dummy_Index = udg_Dummy_Index + 1
set udg_Dummy_Unit[udg_Dummy_Index] = u
call ShowUnit(u, false)
endif
endfunction
Jass triggers \/
called functions
JASS:
function DummyRecycle takes unit u returns nothing
if udg_Dummy_Index < udg_Dummy_Max and GetUnitTypeId(u)=='h000' then
set udg_Dummy_Index = udg_Dummy_Index + 1
set udg_Dummy_Unit[udg_Dummy_Index] = u
call ShowUnit(u, false)
endif
endfunction
function GetNewDummy takes real x1, real y1, real ang returns unit
if udg_Dummy_Unit[1] == null then
set udg_unit = udg_Dummy_Unit[1]
set udg_unit = CreateUnit(Player(15), 'h000', x1, y1, ang)
call UnitAddAbility( udg_unit, 'Arav' )
call UnitRemoveAbility( udg_unit, 'Arav' )
else
set udg_unit = udg_Dummy_Unit[1]
call ShowUnit(udg_unit, true)
set udg_Dummy_Unit[1] = udg_Dummy_Unit[udg_Dummy_Index]
set udg_Dummy_Unit[udg_Dummy_Index] = null
set udg_Dummy_Index = udg_Dummy_Index - 1
endif
return udg_unit
endfunction
function Missile takes unit launcher, unit target, string sfx1, string sfx2, real collision, real x1, real y1, real x2, real y2, real startheight, real speed, real maxspeed, real accelerate, real arc, real arcdist, boolean parabola, real height, real dmg1, real dmg2, real aoe, real dmg3, boolean homing, boolean heightlock returns nothing
local integer i
local real dx = x2 - x1
local real dy = y2 - y1
local real r
local real launcherheight = GetUnitFlyHeight(launcher) + startheight
set udg_MS_Index = udg_MS_Index + 1
set i = udg_MS_Index
set udg_MS_X[i] = x1
set udg_MS_Y[i] = y1
set udg_MS_Angle[i] = Atan2(y2 - y1, x2 - x1)
set udg_MS_CurDist[i] = 0
set udg_MS_MaxDist[i] = SquareRoot(dx * dx + dy * dy)
set udg_MS_Speed[i] = speed
set udg_MS_Launcher[i] = launcher
if arc != 0 then
set udg_MS_ArcDist[i] = arcdist
set udg_MS_ArcAngle[i] = udg_MS_Angle[i] + arc
set udg_MS_Arc[i] = true
else
set udg_MS_ArcDist[i] = 0
set udg_MS_ArcAngle[i] = 0
set udg_MS_Arc[i] = false
endif
if parabola then
set udg_MS_MaxHeight[i] = height
set udg_MS_Parabola[i] = true
else
set udg_MS_MaxHeight[i] = 0
set udg_MS_Parabola[i] = false
endif
if speed != maxspeed then
set udg_MS_MaxSpeed[i] = maxspeed
set udg_MS_Accelerate[i] = accelerate
set udg_MS_SpeedUp[i] = true
else
set udg_MS_SpeedUp[i] = false
set udg_MS_MaxSpeed[i] = 0
set udg_MS_Accelerate[i] = 0
endif
if dmg1 != 0 then
set udg_MS_Dmg_On[i] = true
set udg_MS_Dmg[i] = dmg1
set udg_MS_Collision[i] = collision
else
set udg_MS_Dmg_On[i] = false
set udg_MS_Dmg[i] = 0
set udg_MS_Collision[i] = 0
endif
if dmg2 != 0 then
set udg_MS_Dmg_Ex_On[i] = true
set udg_MS_Aoe_Dmg[i] = dmg2
set udg_MS_Dmg_Area[i] = aoe
else
set udg_MS_Dmg_Ex_On[i] = false
set udg_MS_Aoe_Dmg[i] = 0
set udg_MS_Dmg_Area[i] = 0
endif
set udg_MS_Dmg_Ex[i] = dmg3
if homing then
set udg_MS_Homing_Target[i] = target
set udg_MS_Suicide[i] = true
set udg_MS_StartZ[i] = launcherheight
set r = GetUnitMoveSpeed(target) * 0.03
if speed < r then
set udg_MS_Speed[i] = r + 1
endif
if maxspeed < r then
set udg_MS_MaxSpeed[i] = r + 1
endif
else
set udg_MS_Homing_Target[i] = null
set udg_MS_Suicide[i] = false
endif
if heightlock then
call MoveLocation(udg_p, x1 , y1)
set udg_MS_Height[i] = launcherheight + GetLocationZ(udg_p)
set udg_MS_LockedHeight[i] = true
else
set udg_MS_LockedHeight[i] = false
endif
set udg_MS_Player[i] = GetOwningPlayer(launcher)
set udg_MS_Homing[i] = homing
set udg_MS_Unit[i] = GetNewDummy(x1, x2, udg_MS_Angle[i])
if heightlock then
call SetUnitUserData(udg_MS_Unit[i],100)
endif
call AddSpecialEffectTarget(sfx1, udg_MS_Unit[i], "overhead")
if sfx1 != null then
set udg_MS_SFX[i] = AddSpecialEffectTarget(sfx1, udg_MS_Unit[i], "overhead")
endif
if sfx2 != null then
set udg_MS_SFX_Hit[i] = sfx2
endif
set udg_MS_Height[i] = GetUnitFlyHeight(udg_MS_Unit[i])
call SetUnitFlyHeight( udg_MS_Unit[i], launcherheight, 0.00 )
if homing then
call SetDummyHomingTarget(udg_MS_Unit[i], udg_MS_Homing_Target[i])
else
call SetDummyFacing (udg_MS_Unit[i], udg_MS_Angle[i])
endif
endfunction
timer trigger
JASS:
function Trig_Missile_Timer takes nothing returns nothing
local integer i = 1
local real x
local real y
local real dx
local real dy
local real h
local real r1
local real ang
loop
exitwhen i > udg_MS_Index
if udg_MS_CurDist[i] >= udg_MS_MaxDist[i] then
call DummyRecycle(udg_MS_Unit[i])
call DisplayTextToForce( GetPlayersAll(), "|cffffff00Recycleable Dummy units on stock: "+I2S(udg_Dummy_Index) +"|r")
if udg_MS_SFX[i] != null then
call DestroyEffect(udg_MS_SFX[i])
endif
if i != udg_MS_Index then
set udg_MS_SFX_Hit[i] = udg_MS_SFX_Hit[udg_MS_Index]
set udg_MS_SFX[i] = udg_MS_SFX[udg_MS_Index]
set udg_MS_Unit[i] = udg_MS_Unit[udg_MS_Index]
set udg_MS_Homing_Target[i] = udg_MS_Homing_Target[udg_MS_Index]
set udg_MS_Launcher[i] = udg_MS_Launcher[udg_MS_Index]
set udg_MS_Player[i] = udg_MS_Player[udg_MS_Index]
set udg_MS_X[i] = udg_MS_X[udg_MS_Index]
set udg_MS_Y[i] = udg_MS_Y[udg_MS_Index]
set udg_MS_Homing[i] = udg_MS_Homing[udg_MS_Index]
set udg_MS_LockedHeight[i] = udg_MS_LockedHeight[udg_MS_Index]
set udg_MS_Height[i] = udg_MS_Height[udg_MS_Index]
set udg_MS_MaxHeight[i] = udg_MS_MaxHeight[udg_MS_Index]
set udg_MS_SpeedUp[i] = udg_MS_SpeedUp[udg_MS_Index]
set udg_MS_Accelerate[i] = udg_MS_Accelerate[udg_MS_Index]
set udg_MS_Speed[i] = udg_MS_Speed[udg_MS_Index]
set udg_MS_MaxSpeed[i] = udg_MS_MaxSpeed[udg_MS_Index]
set udg_MS_CurDist[i] = udg_MS_CurDist[udg_MS_Index]
set udg_MS_MaxDist[i] = udg_MS_MaxDist[udg_MS_Index]
set udg_MS_Arc[i] = udg_MS_Arc[udg_MS_Index]
set udg_MS_Parabola[i] = udg_MS_Parabola[udg_MS_Index]
set udg_MS_ArcAngle[i] = udg_MS_ArcAngle[udg_MS_Index]
set udg_MS_Angle[i] = udg_MS_Angle[udg_MS_Index]
set udg_MS_Collision[i] = udg_MS_Collision[udg_MS_Index]
set udg_MS_Suicide[i] = udg_MS_Suicide[udg_MS_Index]
set udg_MS_Dmg_Ex_On[i] = udg_MS_Dmg_Ex_On[udg_MS_Index]
set udg_MS_Dmg_On[i] = udg_MS_Dmg_On[udg_MS_Index]
set udg_MS_Dmg[i] = udg_MS_Dmg[udg_MS_Index]
set udg_MS_Dmg_Area[i] = udg_MS_Dmg_Area[udg_MS_Index]
set udg_MS_Dmg_Ex[i] = udg_MS_Dmg_Ex[udg_MS_Index]
set udg_MS_Dmg_Ex[i] = udg_MS_Dmg_Ex[udg_MS_Index]
set udg_MS_StartZ[i] = udg_MS_StartZ[udg_MS_Index]
endif
set i = i - 1
set udg_MS_Index = udg_MS_Index - 1
else
set x = GetUnitX(udg_MS_Unit[i])
set y = GetUnitY(udg_MS_Unit[i])
if udg_MS_SpeedUp[i] and udg_MS_Accelerate[i]!=0 then
if udg_MS_Accelerate[i] > 0 and udg_MS_MaxSpeed[i] > udg_MS_Speed[i] then
set udg_MS_Speed[i] = udg_MS_Speed[i] + udg_MS_Accelerate[i]
elseif udg_MS_Accelerate[i] < 0 and udg_MS_MaxSpeed[i] < udg_MS_Speed[i] then
set udg_MS_Speed[i] = udg_MS_Speed[i] + udg_MS_Accelerate[i]
endif
endif
if udg_MS_Homing[i] then
set dx = GetUnitX(udg_MS_Homing_Target[i]) - x
set dy = GetUnitY(udg_MS_Homing_Target[i]) - y
set udg_MS_CurDist[i] = udg_MS_MaxDist[i] + 50 - SquareRoot(dx * dx + dy * dy)
set udg_MS_Angle[i] = Atan2(dy, dx)
else
set udg_MS_CurDist[i] = udg_MS_CurDist[i] + udg_MS_Speed[i]
endif
set dx = x + 50 * Cos(udg_MS_Angle[i])
set dy = y + 50 * Sin(udg_MS_Angle[i])
if dx > udg_MapMinX and dx < udg_MapMaxX and dy > udg_MapMinY and dy < udg_MapMaxY then
if udg_MS_Arc[i] then
set r1 = ( 4 * udg_MS_ArcDist[i] / udg_MS_MaxDist[i] ) * ( udg_MS_MaxDist[i] - udg_MS_CurDist[i] ) * ( udg_MS_CurDist[i] / udg_MS_MaxDist[i] / 2 )
set x = udg_MS_X[i] + udg_MS_Speed[i] * Cos(udg_MS_Angle[i])
set y = udg_MS_Y[i] + udg_MS_Speed[i] * Sin(udg_MS_Angle[i])
set x = x + r1 * Cos(udg_MS_ArcAngle[i])
set y = y + r1 * Sin(udg_MS_ArcAngle[i])
call SetUnitX(udg_MS_Unit[i], x)
call SetUnitY(udg_MS_Unit[i], y)
set ang = Atan2(y - udg_MS_Y[i], x - udg_MS_X[i])
call SetUnitFacing(udg_MS_Unit[i], ang)
set udg_MS_X[i] = udg_MS_X[i] + udg_MS_Speed[i] * Cos(udg_MS_Angle[i])
set udg_MS_Y[i] = udg_MS_Y[i] + udg_MS_Speed[i] * Sin(udg_MS_Angle[i])
else
call SetUnitX(udg_MS_Unit[i], (x + udg_MS_Speed[i] * Cos(udg_MS_Angle[i])))
call SetUnitY(udg_MS_Unit[i], (y + udg_MS_Speed[i] * Sin(udg_MS_Angle[i])))
endif
if udg_MS_LockedHeight[i] then
call MoveLocation(udg_p, x, y)
set r1 = udg_MS_Height[i] - GetLocationZ(udg_p)
call SetUnitFlyHeight( udg_MS_Unit[i], r1, 0.00 )
call DisplayTextToForce( GetPlayersAll(), "r1-"+R2S(r1)+" h-: "+R2S(udg_MS_Height[i]) )
set dx = x + 50 * Cos(udg_MS_Angle[i])
set dy = y + 50 * Sin(udg_MS_Angle[i])
call MoveLocation(udg_p, dx, dy)
set r1 = udg_MS_Height[i] - GetLocationZ(udg_p)
call DisplayTextToForce( GetPlayersAll(), "r1"+R2S(r1)+" h: "+R2S(udg_MS_Height[i]) )
if r1 > udg_MS_Height[i] then
set udg_MS_CurDist[i] = udg_MS_MaxDist[i]
endif
else
if udg_MS_Parabola[i] then
if udg_MS_Homing[i] then
set udg_MS_Height[i] = ( 4 * udg_MS_MaxHeight[i] / udg_MS_MaxDist[i] ) * ( udg_MS_MaxDist[i] - udg_MS_CurDist[i] ) * ( udg_MS_CurDist[i] / udg_MS_MaxDist[i] )
set r1 = (udg_MS_MaxDist[i] - udg_MS_CurDist[i]) / udg_MS_Speed[i]
if r1 < 20 then
set h = (GetUnitFlyHeight(udg_MS_Homing_Target[i]) - udg_MS_Height[i]) / ((udg_MS_MaxDist[i] - udg_MS_CurDist[i]) / udg_MS_Speed[i])
set udg_MS_Height[i] = udg_MS_Height[i] + h
else
set udg_MS_Height[i] = ( 4 * udg_MS_MaxHeight[i] / udg_MS_MaxDist[i] ) * ( udg_MS_MaxDist[i] - udg_MS_CurDist[i] ) * ( udg_MS_CurDist[i] / udg_MS_MaxDist[i] )
endif
//set udg_MS_Height[i] = ParabolaZ(udg_MS_StartZ[i], GetUnitFlyHeight(udg_MS_Homing_Target[i]), 500, udg_MS_CurDist[i], udg_MS_MaxDist[i])
//set udg_MS_Height[i] = ParabolaZ(udg_MS_StartZ[i], GetUnitFlyHeight(udg_MS_Homing_Target[i]), 500, udg_MS_CurDist[i], udg_MS_MaxDist[i])
else
set udg_MS_Height[i] = ( 4 * udg_MS_MaxHeight[i] / udg_MS_MaxDist[i] ) * ( udg_MS_MaxDist[i] - udg_MS_CurDist[i] ) * ( udg_MS_CurDist[i] / udg_MS_MaxDist[i] )
endif
// call DisplayTextToForce( GetPlayersAll(), "Dummy["+I2S(i)+"] height: "+R2S(udg_MS_Height[i]) )
call SetUnitFlyHeight( udg_MS_Unit[i], udg_MS_Height[i], 0.00 )
endif
endif
if udg_MS_Dmg_On[i] then
call GroupEnumUnitsInRange(udg_UG, x, y, udg_MS_Collision[i], null)
loop
set udg_unit = FirstOfGroup(udg_UG)
exitwhen (udg_unit==null)
if IsUnitEnemy(udg_unit, udg_MS_Player[i]) then
set r1 = GetUnitFlyHeight(udg_unit)
if r1 > (udg_MS_Height[i] - udg_MS_Collision[i] / 2) and r1 < (udg_MS_Height[i] + udg_MS_Collision[i] / 2) then
if udg_MS_SFX_Hit[i] != null then
call DestroyEffect(AddSpecialEffectTarget(udg_MS_SFX_Hit[i],udg_unit,"chest"))
endif
call UnitDamageTarget(udg_MS_Launcher[i], udg_unit, udg_MS_Dmg[i], true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, null)
if udg_MS_Suicide[i] then
call GroupClear(udg_UG)
set udg_MS_CurDist[i] = udg_MS_MaxDist[i]
endif
endif
endif
call GroupRemoveUnit(udg_UG, udg_unit)
endloop
endif
else
set udg_MS_CurDist[i] = udg_MS_MaxDist[i]
endif
endif
set i = i + 1
endloop
endfunction
//===========================================================================
function InitTrig_Missile_Timer takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterTimerEvent( t, 0.03, true)
call TriggerAddAction( t, function Trig_Missile_Timer )
endfunction
test trigger
JASS:
function Trig_Test_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000'
endfunction
function Trig_Test_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local player p = GetTriggerPlayer()
local real x1 = GetUnitX(u)
local real y1 = GetUnitY(u)
local real x2 = GetSpellTargetX()
local real y2 = GetSpellTargetY()
local real dx = x2 - x1
local real dy = y2 - y1
local real startheight = 0
local real maxheight = 500
local real arcdist = 100
local real dmg1 = 100
local real dmg2 = 100
local real dmgt = 100
local real aoe = 100
local real collision = 80
local real speed = 1
local real maxspeed = 20
local real accelerate = .1
local real arc = 90
local boolean parabola = true
local boolean lockedheight = false
local boolean homing = false
local string sfx1 = "Abilities\\Weapons\\Arrow\\ArrowMissile.mdl"
local string sfx2 = "Objects\\Spawnmodels\\Human\\HumanBlood\\HumanBloodPeasant.mdl"
local integer i
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc, arcdist, parabola, maxheight, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc, arcdist + 50, parabola,maxheight-20, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc, arcdist + 100, parabola, maxheight-40, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc, arcdist + 150, parabola, maxheight-60,dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc-180, arcdist, parabola, maxheight, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc-180, arcdist + 50, parabola,maxheight-20, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc-180, arcdist + 100, parabola, maxheight-40, dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, startheight, speed, maxspeed, accelerate, arc-180, arcdist + 150, parabola, maxheight-60,dmg1,dmg2, aoe, dmgt, homing, lockedheight)
call Missile (u, null, sfx1, sfx2, collision, x1,y1, x2, y2, 100, speed, maxspeed, accelerate, arc, arcdist + 300, false, 0,dmg1,dmg2, aoe, dmgt, homing, true)
call DisplayTextToForce( GetPlayersAll(), "angle " + R2S(udg_MS_Angle[i]) + " distance "+R2S(udg_MS_MaxDist[i]))
call IssueImmediateOrder(u,"stop")
endfunction
//===========================================================================
function InitTrig_Test takes nothing returns nothing
set gg_trg_Test = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Test, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Test, Condition( function Trig_Test_Conditions ) )
call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction
Attachments
Last edited: