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

Need help making a trigger

Status
Not open for further replies.
Level 2
Joined
Dec 25, 2008
Messages
18
Im making a mario kart map and the only thing I don't really know how to do the best way is to make a trigger to constantly check whos in first place, second place, etc. I checked out the map blizzard made, azeroth grand prix, and I can't figure out what they did because they didn't use the regular war3 triggers and that's the only thing I know how to do. I know they put little arrow markers on the map each time the road curves but I don't know how they used them. Here is the script they used.

Code:
function GetLeadingCart takes nothing returns integer
    local integer nPlace = 0

    loop
        exitwhen nPlace >= udg_PlaceNum
        if ( udg_GameGoingStatus[udg_Places[nPlace]] == udg_GAME_DRIVING or udg_GameGoingStatus[udg_Places[nPlace]] == udg_GAME_REPAIRING ) then
            return udg_Places[nPlace]
        endif
        set nPlace = nPlace + 1
    endloop

    return -1
endfunction

function GetPlayerPlace takes integer nPlayerIndex returns integer
    local integer nIndex = 0
    loop
        exitwhen nIndex >= udg_PlaceNum
        if ( udg_Places[nIndex] == nPlayerIndex ) then
            return nIndex
        endif
        set nIndex = nIndex + 1
    endloop

    return -1
endfunction

function GameOverPlayer takes integer nPlayerIndex returns nothing
    local location loc = null
    local effect eff = null

    set udg_GameGoingStatus[nPlayerIndex] = udg_GAME_OVER

    if ( udg_Carts[nPlayerIndex] == null ) then
        return
    endif

    set loc = GetUnitLoc( udg_Carts[nPlayerIndex] )
    set eff = AddSpecialEffectLoc( "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl", loc)
    call RemoveLocation( loc )
    call RemoveUnit( udg_Carts[nPlayerIndex] )
    set udg_Carts[nPlayerIndex] = null
    call DestroyEffect( eff )
endfunction

function GameOver takes nothing returns nothing
    local integer nPlayerIndex = 0
    call PolledWait( 2 )

    if ( udg_GameOver ) then
        return
    endif

    set udg_GameOver = true
    loop
        exitwhen nPlayerIndex >= udg_PLAYER_MAXNUM
        set udg_GameGoingStatus[nPlayerIndex] = udg_GAME_OVER
        set nPlayerIndex = nPlayerIndex + 1
    endloop
    
    call ConditionalTriggerExecute( gg_trg_Ending )
    call ConditionalTriggerExecute( gg_trg_Ending_Flares )
endfunction

function EnterNextLap takes integer nPlayerIndex returns nothing
    if ( udg_PlaceChkPtLap[nPlayerIndex] == udg_LapNumber - 1 ) then
        call ShowDrivingMsgPlayer( Player(nPlayerIndex), "Last lap" )
        call PlaySoundPlayer( Player(nPlayerIndex), gg_snd_AnnouncerFinalLap01 )
    else
        call ShowDrivingMsgPlayer( Player(nPlayerIndex), "Lap " + I2S(udg_PlaceChkPtLap[nPlayerIndex] + 1) )
    endif
endfunction

function CompletedAllLaps takes integer nPlayerIndex returns nothing
    local string str
    local string str1 = "|cff00ff00 Please wait for the race to end and the award ceremony.|r"
    local integer nPlace
    local string array strNum

    set strNum[0] = "FIRST"
    set strNum[1] = "SECOND"
    set strNum[2] = "THIRD"
    set strNum[3] = "FOURTH"
    set strNum[4] = "FIFTH"
    set strNum[5] = "SIXTH"
    set strNum[6] = "SEVENTH"
    set strNum[7] = "EIGHTH"

    call SetCartInvulnerable( udg_Carts[nPlayerIndex], true )
    call SetUnitOwner( udg_Carts[nPlayerIndex], udg_NPC, false )
    set udg_GameGoingStatus[ nPlayerIndex ] = udg_GAME_FINISHING
    set udg_TimeUsed[ nPlayerIndex ] = TimerGetElapsed( udg_GameTimer )
    set udg_NormalCamera[nPlayerIndex] = true
    call SetUnitAnimationByIndex( udg_Carts[nPlayerIndex], GetModelAnimVictoryID( udg_PlayerModels[nPlayerIndex] ) )
    call CameraSetupApplyForPlayer( true, gg_cam_GameEndCamera, Player(nPlayerIndex), 5.00 )
    call ResetToGameCameraForPlayer( Player(nPlayerIndex), 2.00 )

    set nPlace = GetPlayerPlace( nPlayerIndex )
    if ( nPlace == 0 ) then
        set str = "\r|cff00ff00Congratulations for finishing in |r|cffff0000" + strNum[nPlace] + "|r|cff00ff00 place.|r" + str1
    elseif ( nPlace > 0 ) then
        set str = "\r|cff00ff00You finish in |r|cffff0000" + strNum[nPlace] + "|r|cff00ff00 place.|r" + str1
    else
        return
    endif

    set str = str + "\r|cff00ff00Your total racing time is |r|cffffcc00" + Second2String( R2I(udg_TimeUsed[nPlayerIndex]), false ) + "|r|cff00ff00.|r"

    if ( GetLocalPlayer() == Player(nPlayerIndex) ) then
        call ClearTextMessages()
        call PlaySoundBJ( gg_snd_Hint )
        call DisplayTimedTextToPlayer( Player(nPlayerIndex), 0, 0, 10, str )
    endif
endfunction

function ReachedCheckPoint takes location locCart, integer nChkPtIndex returns boolean
    local real rDir = AngleBetweenPoints( udg_PlaceCheckPtPos[nChkPtIndex], locCart )
    return CosBJ( rDir - udg_PlaceCheckPtDir[nChkPtIndex] ) >= 0
endfunction

function DistanceFromCheckPoint takes location locCart, integer nChkPtIndex returns real
    local real rDir = AngleBetweenPoints( udg_PlaceCheckPtPos[nChkPtIndex], locCart )
    local real rDis = DistanceBetweenPoints( locCart, udg_PlaceCheckPtPos[nChkPtIndex] )

    return rDis * CosBJ( rDir - udg_PlaceCheckPtDir[nChkPtIndex] )
endfunction

function RefreshPlayerCheckPoint takes integer nPlayerIndex returns nothing
    local location loc = null
    local integer nLapPre
    local integer nChkPre
    local integer nLapNext
    local integer nChkNext
    local real rDis

    if ( udg_Carts[nPlayerIndex] == null ) then
        return
    endif

    set loc = GetUnitLoc( udg_Carts[nPlayerIndex] )

    if ( RectContainsLoc( gg_rct_CrossArea1, loc ) ) then
        set udg_PlaceChkPtCur[nPlayerIndex] = udg_PlaceChkPtCross1
        set udg_PlaceChkPtHowFar[nPlayerIndex] = 900
        call RemoveLocation( loc )
        return
    elseif ( RectContainsLoc( gg_rct_CrossArea2, loc ) ) then
        set udg_PlaceChkPtCur[nPlayerIndex] = udg_PlaceChkPtCross2
        set udg_PlaceChkPtHowFar[nPlayerIndex] = 0
        call RemoveLocation( loc )
        return
    endif

    //First check whether cart reaches next point
    if ( udg_PlaceChkPtLap[nPlayerIndex] < 0 ) then
        set nChkNext = 0
        set nLapNext = 0
    elseif ( udg_PlaceChkPtCur[nPlayerIndex] == udg_PlaceCheckPtNum - 1 ) then
        set nChkNext = 0
        set nLapNext = udg_PlaceChkPtLap[nPlayerIndex] + 1
    else
        set nChkNext = udg_PlaceChkPtCur[nPlayerIndex] + 1
        set nLapNext = udg_PlaceChkPtLap[nPlayerIndex]
    endif

    //If reached next check point
    if ( nChkNext >= 0 ) then
        if ( ReachedCheckPoint( loc, nChkNext ) ) then
            set udg_PlaceChkPtLap[nPlayerIndex] = nLapNext
            set udg_PlaceChkPtCur[nPlayerIndex] = nChkNext
            set udg_PlaceChkPtHowFar[nPlayerIndex] = DistanceFromCheckPoint(loc, udg_PlaceChkPtCur[nPlayerIndex] )

            call RemoveLocation( loc )

            //If this is the start point            
            if ( udg_PlaceChkPtCur[nPlayerIndex] == 0 ) then
                if ( udg_PlaceChkPtLap[nPlayerIndex] >= udg_LapNumber ) then
                    call CompletedAllLaps( nPlayerIndex )
                else
                    call EnterNextLap( nPlayerIndex )
                endif
            endif
            return
        endif
    endif

    //If player is moving forward
    if ( udg_PlaceChkPtCur[nPlayerIndex] >= 0 ) then
        if ( ReachedCheckPoint( loc, udg_PlaceChkPtCur[nPlayerIndex] ) ) then
            set udg_PlaceChkPtHowFar[nPlayerIndex] = DistanceFromCheckPoint(loc, udg_PlaceChkPtCur[nPlayerIndex] )
            call RemoveLocation( loc )
            return
        endif
    endif

    //Player move backward
    if ( udg_PlaceChkPtLap[nPlayerIndex] < 0 ) then
        set nChkPre = -1
        set nLapPre = -1
    elseif ( udg_PlaceChkPtCur[nPlayerIndex] == 0 ) then
        if ( udg_PlaceChkPtLap[nPlayerIndex] == 0 ) then
            set nChkPre = -1
            set nLapPre = -1
        else
            set nChkPre = udg_PlaceCheckPtNum - 1
            set nLapPre = udg_PlaceChkPtLap[nPlayerIndex] - 1
        endif
    else
        set nChkPre = udg_PlaceChkPtCur[nPlayerIndex] - 1
        set nLapPre = udg_PlaceChkPtLap[nPlayerIndex]
    endif
    
    if ( nChkPre >= 0 ) then
        set udg_PlaceChkPtLap[nPlayerIndex] = nLapPre
        set udg_PlaceChkPtCur[nPlayerIndex] = nChkPre
        set udg_PlaceChkPtHowFar[nPlayerIndex] = DistanceFromCheckPoint(loc, udg_PlaceChkPtCur[nPlayerIndex] )

        call RemoveLocation( loc )
        return
    endif

    set udg_PlaceChkPtLap[nPlayerIndex] = -1
    set udg_PlaceChkPtCur[nPlayerIndex] = -1
    set udg_PlaceChkPtHowFar[nPlayerIndex] = 0

    call RemoveLocation( loc )
endfunction

function ComparePlace takes integer nLap1, integer nPos1, real rHowFar1, integer nLap2, integer nPos2, real rHowFar2 returns integer
    if ( nLap1 > nLap2 ) then
        return 1
    elseif ( nLap1 < nLap2 ) then
        return -1
    endif

    if ( nPos1 > nPos2 ) then
        return 1
    elseif ( nPos1 < nPos2 ) then
        return -1
    endif

    if ( rHowFar1 > rHowFar2 ) then
        return 1
    elseif ( rHowFar1 < rHowFar2 ) then
        return -1
    endif

    return 0
endfunction

function ComparePlaceIndex takes integer nPlayerIndex1, integer nPlayerIndex2 returns integer
    local integer n
    local boolean b1 = udg_GameGoingStatus[ nPlayerIndex1 ] == udg_GAME_FINISHING or udg_GameGoingStatus[ nPlayerIndex1 ] == udg_GAME_OVER
    local boolean b2 = udg_GameGoingStatus[ nPlayerIndex2 ] == udg_GAME_FINISHING or udg_GameGoingStatus[ nPlayerIndex2 ] == udg_GAME_OVER

    if ( b1 and b2 ) then
        if ( udg_TimeUsed[nPlayerIndex1] < udg_TimeUsed[nPlayerIndex2] ) then
            return 1
        elseif ( udg_TimeUsed[nPlayerIndex1] > udg_TimeUsed[nPlayerIndex2] ) then
            return -1
        endif
    elseif ( b1 ) then
        return 1
    elseif ( b2 ) then
        return -1
    else
        set n = ComparePlace( udg_PlaceChkPtLap[nPlayerIndex1], udg_PlaceChkPtCur[nPlayerIndex1], udg_PlaceChkPtHowFar[nPlayerIndex1], udg_PlaceChkPtLap[nPlayerIndex2], udg_PlaceChkPtCur[nPlayerIndex2], udg_PlaceChkPtHowFar[nPlayerIndex2] )
        if ( n != 0 ) then
            return n
        endif
    endif

    if ( nPlayerIndex1 < nPlayerIndex2 ) then
        return 1
    elseif ( nPlayerIndex1 > nPlayerIndex2 ) then
        return -1
    endif

    return 0
endfunction

function SortPlace takes nothing returns nothing
    local integer nPlayerIndex
    local integer nIndex
    local integer nTemp

    set nPlayerIndex = 0
    set udg_PlaceNum = 0
    loop
        exitwhen nPlayerIndex >= udg_PLAYER_MAXNUM
        if ( GetPlayerController(Player(nPlayerIndex)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(nPlayerIndex)) == PLAYER_SLOT_STATE_PLAYING ) then
            set udg_Places[udg_PlaceNum] = nPlayerIndex
            set udg_PlaceNum = udg_PlaceNum + 1
        endif
        set nPlayerIndex = nPlayerIndex + 1
    endloop

    set nPlayerIndex = 0
    loop
        exitwhen nPlayerIndex >= udg_PlaceNum - 1

        set nIndex = 0
        loop
            exitwhen nIndex >= udg_PlaceNum - 1 - nPlayerIndex
        
            if ( ComparePlaceIndex( udg_Places[nIndex], udg_Places[nIndex + 1] ) < 0 ) then
                set nTemp = udg_Places[nIndex]
                set udg_Places[nIndex] = udg_Places[nIndex + 1]
                set udg_Places[nIndex + 1] = nTemp
            endif

            set nIndex = nIndex + 1
        endloop

        set nPlayerIndex = nPlayerIndex + 1
    endloop
endfunction

function CheckWrongDirection takes integer nPlayerIndex returns nothing
    local boolean bWrong = true

    if ( udg_Speed[nPlayerIndex] <= 20 ) then
        set bWrong = false
    elseif ( ComparePlace( udg_PlaceChkPtLapBak[nPlayerIndex], udg_PlaceChkPtCurBak[nPlayerIndex], udg_PlaceChkPtHowFarBak[nPlayerIndex], udg_PlaceChkPtLap[nPlayerIndex], udg_PlaceChkPtCur[nPlayerIndex], udg_PlaceChkPtHowFar[nPlayerIndex] ) <= 0 ) then
        set bWrong = false
    endif

    if ( not bWrong ) then    
        if ( udg_EffectWrongDir[nPlayerIndex] != null ) then
            call DestroyEffect( udg_EffectWrongDir[nPlayerIndex] )
            set udg_EffectWrongDir[nPlayerIndex] = null
        endif
        return
    endif

    if ( udg_EffectWrongDir[nPlayerIndex] == null ) then
        set udg_EffectWrongDir[nPlayerIndex] = AddSpecialEffectTarget( "Abilities\\Spells\\Other\\TalkToMe\\TalkToMe.mdl", udg_Carts[nPlayerIndex], "overhead" )
    endif

    if ( udg_WarningWrongDir[nPlayerIndex] ) then
        return
    endif

    set udg_WarningWrongDir[nPlayerIndex] = true
    call ShowWarningMsg( Player(nPlayerIndex), "You are going wrong direction." )

    call PolledWait(15)
    set udg_WarningWrongDir[nPlayerIndex] = false
endfunction

function RefreshPlayerCheckPoints takes nothing returns nothing
    local integer nPlayerIndex
    local integer nNum = 0
    local integer nIndex

    set nPlayerIndex = 0
    loop
        exitwhen nPlayerIndex >= udg_PLAYER_MAXNUM

        if ( GetPlayerController(Player(nPlayerIndex)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(nPlayerIndex)) == PLAYER_SLOT_STATE_PLAYING ) then
            if ( udg_GameGoingStatus[nPlayerIndex] == udg_GAME_DRIVING ) then
                //Save backup to check whether player is going wrong direction
                set udg_PlaceChkPtLapBak[nPlayerIndex] = udg_PlaceChkPtLap[nPlayerIndex]
                set udg_PlaceChkPtCurBak[nPlayerIndex] = udg_PlaceChkPtCur[nPlayerIndex]
                set udg_PlaceChkPtHowFarBak[nPlayerIndex] = udg_PlaceChkPtHowFar[nPlayerIndex]

                call RefreshPlayerCheckPoint( nPlayerIndex )
            endif
        endif

        set nPlayerIndex = nPlayerIndex + 1
    endloop

    set nPlayerIndex = 0
    loop
        exitwhen nPlayerIndex >= udg_PLAYER_MAXNUM

        if ( GetPlayerController(Player(nPlayerIndex)) == MAP_CONTROL_USER and GetPlayerSlotState(Player(nPlayerIndex)) == PLAYER_SLOT_STATE_PLAYING ) then
            if ( udg_GameGoingStatus[nPlayerIndex] == udg_GAME_DRIVING ) then
                call CheckWrongDirection( nPlayerIndex )
            endif
        endif

        set nPlayerIndex = nPlayerIndex + 1
    endloop

    call SortPlace()

    set nNum = udg_PlaceNum
    if ( nNum > udg_PlaceNum ) then
        set nNum = udg_PlaceNum
    endif

    set nIndex = 0
    loop
        exitwhen nIndex >= nNum

        set nPlayerIndex = udg_Places[nIndex]
        if ( udg_GameGoingStatus[nPlayerIndex] != udg_GAME_OVER and udg_GameGoingStatus[nPlayerIndex] != udg_GAME_FINISHING ) then
            return
        endif

        set nIndex = nIndex + 1
    endloop

    call GameOver()
endfunction

//===========================================================================
function InitTrig_Place_Functions takes nothing returns nothing
endfunction
 
Level 11
Joined
Jan 17, 2009
Messages
790
itz not a few region, a hella lot small regions all over the track!
put numberz as their names
and do it like this, e.g
Event- a unit enters 5.gen
Condition-
Action-set x(x is an array)[(here you put the number of the player owning this unit)] = x[]+1
Than make a multiboard hows first 2nd till last based on the variable "x"

This is what I think will work.
 
Level 2
Joined
Dec 25, 2008
Messages
18
ive already done something like that but i was just wondering if anyone could translate whatever blizzard did because theirs seems to work really nicely. what I did is put up a bunch of arrows and set their custom value to a certain number. 0 for the first one 1 for the second one etc..

each player has a variable for what place they are in. when they reach a checkpoint their place variable equals whatever custom value the arrow was.

and it adds 1 minus the distance between the location of the cart and the next checkpoint so that you know whos in first, second, etc when more than 1 player is at the same checkpoint.
 
Status
Not open for further replies.
Top