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

[JASS] JASS Will Not Work

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
Is there something wrong with this? The five peasants spawn at the middle of the map which is no where near where they're supposed to spawn

JASS:
function GetMidPointX takes real Px, real Qx returns real
    return (1/2)*(Px + Qx)
endfunction

function GetMidPointY takes real Py, real Qy returns real
    return (1/2)*(Py + Qy)
endfunction

function Melee_Init_Actions takes nothing returns nothing
    local real humanMidPointX = GetMidPointX(GetUnitX(gg_unit_ngol_0006), GetStartLocationX(GetPlayerStartLocation(Player(1))))
    local real humanMidPointY = GetMidPointY(GetUnitY(gg_unit_ngol_0006), GetStartLocationY(GetPlayerStartLocation(Player(1))))
    
    call CreateUnit(Player(1), 'hpea', humanMidPointX, humanMidPointY + 64.00, 270.00)
    call CreateUnit(Player(1), 'hpea', humanMidPointX - 64.00, humanMidPointY, 270.00)
    call CreateUnit(Player(1), 'hpea', humanMidPointX - 32.00, humanMidPointY - 64.00, 270.00)
    call CreateUnit(Player(1), 'hpea', humanMidPointX + 32.00, humanMidPointY + 64.00, 270.00)
    call CreateUnit(Player(1), 'hpea', humanMidPointX + 64.00, humanMidPointY, 270.00)
endfunction

//===========================================================================
function InitTrig_Melee_Init takes nothing returns nothing
    set gg_trg_Melee_Init = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Melee_Init, function Melee_Init_Actions )
endfunction
 
Change the (1/2) to (1/2.). 1 and 2 are integers, so when you do 1/2, it spits out an integer result. The real result would be 0.5, but truncated it is 0. Therefore, anything * 0 = 0 so that is why they went to the center.

Adding the little decimal in 1/2. will consider it to be an integer divided by a real, and thus it will return the real result of 0.5. This is a nice tip to know for graphing calculators too (it can determine whether the result is returned as a fraction or a decimal, because 2. is the equivalent of 2.0)
 
Status
Not open for further replies.
Top