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

Trying to figure out what's different per player...

Status
Not open for further replies.
Level 8
Joined
Aug 2, 2006
Messages
346
I have the movement code done for my Soldiers-like map, and it works fine for player 1, but for all the other players it doesn't work right even though I'm never explicitly saying "player 1" but rather I'm saying "player i" and looping through every player.

The problem is that the collision detection is working for player 1 (so they stay on top of platforms and don't go through them in any direction), but for all the other players they just keep on going right through the platforms as if they aren't even there. I know the loop is checking these players because if it wasn't, they wouldn't move at all.

To check for cliff level (the platforms are cliffs) I'm using GetLocationZ (Get terrain height wasn't precise enough and was making me angry) and looking at the Z coordinates of points around the player's unit (if the point above the unit is higher than the point below the unit, then the cliff is above the unit, and the unit needs to be moved downwards).

Is there something screwey going on with GetLocationZ or is it something else? I've gone over the code dozens of times and I have yet to think of any other cause. Of course, now that I have created this thread, I'm sure I"ll figure it out within the hour like I always do :)

EDIT: Oh and eventually, they fall to the edge of the map (I assume, I can't see them) and the game crashes.
 
Level 8
Joined
Aug 2, 2006
Messages
346
Hehehe... yea I'll post my trigger alright... you'll be sorry.

EDIT: Ok here's the trigger:

Code:
function Trig_MainGameLoop_Actions takes nothing returns nothing
    // Movement Functionality
    local location point
    local integer index = 0
    local integer jndex = 0
    local real x = 0
    local real y = 0
    local real angle = 0
    local real angle2 = 0
    local real speed = 0
    local real posX
    local real posY
    local location pointL
    local location pointR
    local location pointD
    local location pointU
    local boolean burning = false

    local boolean loopDone = false
    local integer iterations = 0

    if (udg_mainGameLoop) then //do ALL THAT CODE, I don't feel like indenting it all

    loop
        exitwhen index >= 12

        if ( udg_playerPlaying[index] ) then    //don't loop if the player isn't even playing!
            set posX = GetUnitX( udg_visibleBastards[index] )
            set posY = GetUnitY( udg_visibleBastards[index] )

            if ( udg_upArrow[index] ) then
                set udg_yVelocity[index] = udg_yVelocity[index] + udg_UPACCEL
            endif

            set udg_yVelocity[index] = udg_yVelocity[index] - udg_GRAVITY

            if ( udg_yVelocity[index] > udg_MAXSPEED ) then
                set udg_yVelocity[index] = udg_MAXSPEED
            elseif ( udg_yVelocity[index] < ( udg_MAXSPEED * -1 ) ) then
                set udg_yVelocity[index] = ( udg_MAXSPEED * -1 )
            endif

            if ( udg_leftArrow[index] and not( udg_rightArrow[index] ) ) then
                set posX = posX - udg_MOVESPEED
            elseif ( udg_rightArrow[index] and not( udg_leftArrow[index] ) ) then
                set posX = posX + udg_MOVESPEED
            endif

            set posY = posY + udg_yVelocity[index]


            loop
                exitwhen (loopDone or iterations > 8)
                set point = Location(posX,posY)
                if ( GetLocationZ( point ) > udg_zOfGround ) then
                    set pointL = Location( posX - 1 , posY )
                    set pointR = Location( posX + 1 , posY )
                    set pointD = Location( posX , posY - 1 )
                    set pointU = Location( posX , posY + 1 )
                    if ( GetLocationZ( pointL ) > GetLocationZ( pointR ) ) then //cliff is to the left
                        set posX = posX + 2
                    elseif ( GetLocationZ( pointL ) < GetLocationZ( pointR ) ) then //cliff is to the right
                        set posX = posX - 2
                    endif
    
                    if ( GetLocationZ( pointD ) > GetLocationZ( pointU ) ) then //cliff is downwards
                        set posY = posY + 2
                        if ( udg_yVelocity[index] < 0 ) then
                            set udg_yVelocity[index] = 0
                        endif
                    elseif ( GetLocationZ( pointD ) < GetLocationZ( pointU ) ) then //cliff is upwards
                        set posY = posY - 2
                        if ( udg_yVelocity[index] > 0 ) then
                            set udg_yVelocity[index] = 0
                        endif
                    endif
                    call RemoveLocation(pointL)
                    call RemoveLocation(pointR)
                    call RemoveLocation(pointU)
                    call RemoveLocation(pointD)
                else
                    set loopDone = true
                endif
                set iterations = iterations + 1
                call RemoveLocation(point)
            endloop

            call SetUnitX( udg_visibleBastards[index] , posX )
            call SetUnitY( udg_visibleBastards[index] , posY )

            call SetUnitX( udg_healthBar[index] , posX )
            call SetUnitY( udg_healthBar[index] , posY + 128.00 )

            call SetUnitAnimationByIndex( udg_healthBar[index] , R2I(GetUnitState(udg_controllers[index] , UNIT_STATE_LIFE) / 10.00) )

            if (udg_walkAnimating[index] == false) and (udg_rightArrow[index] or udg_leftArrow[index]) and (TimerGetRemaining(udg_fireAnimTimer[index]) == 0) then
                set udg_walkAnimating[index] = true
                call SetUnitAnimationByIndex(udg_visibleBastards[index] , 6 )
            elseif (udg_walkAnimating[index] and (udg_leftArrow[index] == false) and (udg_rightArrow[index] == false)) and (TimerGetRemaining(udg_fireAnimTimer[index]) == 0) then
                set udg_walkAnimating[index] = false
                call SetUnitAnimation(udg_visibleBastards[index] , "stand" )
            endif

            if (udg_flameSquirt[index] >= 1) then
                set udg_flameSquirt[index] = udg_flameSquirt[index] - 1
                set jndex = 0
                loop
                    exitwhen jndex >= udg_flameSize
                    if (udg_fireball_INPLAY[jndex] == false) then
                        set x = GetUnitX(udg_visibleBastards[index])
                        set y = GetUnitY(udg_visibleBastards[index])
                        set angle = Atan2( udg_flameTargetY[index] - y , udg_flameTargetX[index] - x )
                        set angle2 = angle + GetRandomReal(-0.087,0.087)
                        call SetUnitFacing(udg_fireball[index] , angle2)
                        set udg_fireball_XVEL[jndex] = Cos(angle2) * 50.00
                        set udg_fireball_YVEL[jndex] = Sin(angle2) * 50.00
                        set udg_fireball_compressXVEL[jndex] = (Cos(angle) + Cos(angle2))
                        set udg_fireball_compressYVEL[jndex] = (Sin(angle) + Sin(angle2))
                        call SetUnitX( udg_fireball[jndex] , GetUnitX(udg_visibleBastards[index]) )
                        call SetUnitY( udg_fireball[jndex] , GetUnitY(udg_visibleBastards[index]) )
                        set udg_fireball_INPLAY[jndex] = true
                        set udg_fireball_LIFE[jndex] = 50
                        call ShowUnit( udg_fireball[jndex] , true )
                        set jndex = udg_flameSize
                    endif
                    set jndex = jndex + 1
                endloop
            endif

            set burning = false
            set jndex = 25 * udg_numPlayers - 1
            loop
                exitwhen jndex < 0
                if (udg_fireball_LIFE[index] <=40) and ( (Pow(GetUnitX(udg_visibleBastards[index]) - GetUnitX(udg_fireball[jndex]),2) + Pow(GetUnitY(udg_visibleBastards[index]) - GetUnitY(udg_fireball[jndex]),2)) <= Pow( 60 - udg_fireball_LIFE[index] , 2 )) then
                    set burning = true
                    set jndex = -1
                endif
                set jndex = jndex - 1
            endloop
            if (burning) then
                call SetUnitState(udg_visibleBastards[index] , UNIT_STATE_LIFE, GetUnitState(udg_visibleBastards[index] , UNIT_STATE_LIFE) - 3 )
                call SetUnitState(udg_controllers[index] , UNIT_STATE_LIFE, GetUnitState(udg_visibleBastards[index] , UNIT_STATE_LIFE) )
            endif

            if ( udg_sniperTrail[index] != null ) and ( udg_sniperTrailVis[index] > 0 ) then
                set udg_sniperTrailVis[index] = udg_sniperTrailVis[index] - 1
                call SetLightningColor( udg_sniperTrail[index] , 1 , 1 , 1 , I2R(udg_sniperTrailVis[index]) / 25 )
            endif


            //Setup camera
            if ( GetLocalPlayer() == Player(index) ) then
                call PanCameraToTimed( posX , posY , 0.05)
                call SetCameraField( CAMERA_FIELD_TARGET_DISTANCE, udg_cameraDistance[index], udg_panSpeed )
                call SetCameraField( CAMERA_FIELD_FARZ, 5000.00, 0.05 )
                call SetCameraField( CAMERA_FIELD_ANGLE_OF_ATTACK, 270.00, 0.05 )
                call SetCameraField( CAMERA_FIELD_FIELD_OF_VIEW, 120.00, 0.05 )
                call SetCameraField( CAMERA_FIELD_ROLL, 0.00, 0.05 )
                call SetCameraField( CAMERA_FIELD_ROTATION, 90.00, 0.05 )
            endif
        endif
        set index = index + 1
    endloop
    endif
endfunction

//===========================================================================
function InitTrig_MainGameLoop_Copy takes nothing returns nothing
    set gg_trg_MainGameLoop_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_MainGameLoop_Copy, 0.02, true )
    call TriggerAddAction( gg_trg_MainGameLoop_Copy, function Trig_MainGameLoop_Actions )
endfunction

AHHH!!! Poop... stupid error. I never in the code reset the "iterations" variable to 0, so once it hits 8 with the first player, it skips over the whole step for all 11 other players.

I don't want to jump to conclusions, but I THINK this is the whole cause for the bug.
 
Last edited:
Status
Not open for further replies.
Top