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

[Solved] [LUA] Ice Skating Code

Status
Not open for further replies.
Level 8
Joined
Jun 16, 2008
Messages
333
So I have gotten my guy to glide on the ice with some LUA but he can be moved. It would be cool if I could make that not possible.

Also my steering is broken. I can steer for the first 10 seconds, then it stops and I cant steer any more.

Lua:
function iceSlidecon()
    local iceConTurn = CreateTrigger()
    local iceConSteer = CreateTrigger()
    TriggerAddAction(iceConTurn, iceConTurns)
    TriggerAddAction(iceConSteer, iceConSteers)
    for i=0,12,1 do
    TriggerRegisterPlayerUnitEventSimple(iceConTurn, Player(i), EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
    TriggerRegisterPlayerUnitEventSimple(iceConSteer, Player(i), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
    print(i)
  
    end
end

function iceConTurns()
    local u = GetTriggerUnit()
    local x = GetUnitX(unit)
    local y = GetUnitY(unit)
    local p = GetUnitLoc(GetOrderTargetUnit())
    local slideTerrain = FourCC("Nice")
    if GetTerrainType(x,y) == slideTerrain then
        SetUnitFacing(u,57.295828*Atan2(GetLocationY(p)-y, GetLocationX(p)-x))
    end
    RemoveLocation(p)
    p= nil
    u= nil
end  

function iceConSteers()
    local u = GetTriggerUnit()
    local x = GetUnitX(unit)
    local y = GetUnitY(unit)
    local a = GetOrderPointX()
    local b = GetOrderPointY()
    local slideTerrain = FourCC("Nice")
    if(GetTerrainType(x,y) == slideTerrain) then
        SetUnitFacing(u, 57.295828*Atan2(b-y,a-x))
    end
    u = nil
end  

function iceSlideTrig()
    local slide = CreateTrigger()
    TriggerRegisterTimerEventPeriodic(slide, 0.02)
    TriggerAddAction(slide, iceSlide)
end

function iceSlide()
    local hero = GetUnitsOfTypeIdAll(FourCC("Edem"))
    ForGroup(hero, Slide)
    DestroyGroup(hero)
end  

function Slide()
    print("Slide should work")
    local unit = GetEnumUnit()
    local x = GetUnitX(unit)
    local y = GetUnitY(unit)
    local onTerrain = GetTerrainType(x, y)
    local slideTerrain = FourCC("Nice")
    local Speed = 12.00
    --local unitFacing = GetUnitFacing(unit)
    --local sux = x + Speed*Cos(0.017453278*unitFacing)
    --local suy = y + Speed*Sin(0.017453278*unitFacing)
    if onTerrain == slideTerrain then
        IssueImmediateOrder(unit, "stop")
        SetUnitPositionLoc(unit, PolarProjectionBJ(GetUnitLoc(unit),Speed,GetUnitFacing(unit)))
        -- IssueImmediateOrder(unit, "stop")
        -- SetUnitX(unit, sux)
        -- SetUnitY(unit, suy)
         IssueImmediateOrder(unit, "stop")
        print("slide")
    end
    unit = nil
end

Just to let you know I just have been taking other peoples stuff in jass and have been trying to convert it to LUA.

Any help would be greatly aprreciated!

PS: Call functions iceSlideTrig() / iceSlidecon()
 
Status
Not open for further replies.
Top