• 🏆 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] Can anyone translate this VJASS script into normal JASS?

Status
Not open for further replies.
Level 11
Joined
Oct 9, 2015
Messages
721
I need it so I can use it with normal world editor

JASS:
//TESH.scrollpos=0
//TESH.alwaysfold=0
library TerrainPathability initializer Initialization

globals
    private constant real    MAX_RANGE     = 10.
    private constant integer DUMMY_ITEM_ID = 'wolg'
endglobals

globals    
    private item       Item   = null
    private rect       Find   = null
    private item array Hid
    private integer    HidMax = 0
    public  real       X      = 0.
    public  real       Y      = 0.
endglobals

function IsTerrainDeepWater takes real x, real y returns boolean
    return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction
function IsTerrainShallowWater takes real x, real y returns boolean
    return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction
function IsTerrainLand takes real x, real y returns boolean
    return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)
endfunction
function IsTerrainPlatform takes real x, real y returns boolean
    return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
endfunction

private function HideItem takes nothing returns nothing
    if IsItemVisible(GetEnumItem()) then
        set Hid[HidMax] = GetEnumItem()
        call SetItemVisible(Hid[HidMax], false)
        set HidMax = HidMax + 1
    endif
endfunction
function IsTerrainWalkable takes real x, real y returns boolean
    call MoveRectTo(Find, x, y)
    call EnumItemsInRect(Find ,null, function HideItem)
    call SetItemPosition(Item, x, y)
    set X = GetItemX(Item)
    set Y = GetItemY(Item)
    call SetItemVisible(Item, false)
    loop
        exitwhen HidMax <= 0
        set HidMax = HidMax - 1
        call SetItemVisible(Hid[HidMax], true)
        set Hid[HidMax] = null
    endloop
    return (X-x)*(X-x)+(Y-y)*(Y-y) <= MAX_RANGE*MAX_RANGE and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
endfunction

private function Initialization takes nothing returns nothing
    set Find = Rect(0., 0., 128., 128.)
    set Item = CreateItem(DUMMY_ITEM_ID, 0, 0)
    call SetItemVisible(Item, false)
endfunction
endlibrary

JASS:
//TESH.scrollpos=24
//TESH.alwaysfold=0
function Trig_Multiplayer_Camera_Actions takes nothing returns nothing

    local boolean b                     //The pathing boolean
    local integer i = 1                 //The player index counter
    local location l = Location(0,0)    //A point used to detect height
    local real v                        //The distance of the camera
    local real x                        //Coordinates x,y,z of two points
    local real y
    local real z
    local real x1
    local real y1
    local real z1

    loop
         if udg_camera_target_unit[i] != null and (GetWidgetLife(udg_camera_target_unit[i]) > 0.405) then 
            set v = 25 //We set the minimum distance to 25
            set x = GetUnitX(udg_camera_target_unit[i]) //Get the x coordinate of the unit wich has the camera on it
            set y = GetUnitY(udg_camera_target_unit[i]) //Get the y coordinate of the unit wich has the camera on it
            call MoveLocation(l,x,y) //We move the l point to the units coordinates
            set z = GetLocationZ(l) // store the heignt as z
            set x1 = x + 64 * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            set y1 = y + 64 * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            call MoveLocation(l,x1,y1) 
            set z1 = GetLocationZ(l) //We find the point right in front of the unit's camera and get its height
            loop //Here begins the main loop for all players
                set x1 = x - v * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set y1 = y - v * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set b = IsTerrainWalkable(x1, y1) // This part uses the library I implemented to see is the point behind the unit in distance v is pathable
                if (b == false) then
                    set b = IsTerrainDeepWater(x1, y1) // We dont want to avoid water right...
                endif
                if (GetUnitFlyHeight(udg_camera_target_unit[i]) > 0) then
                    set b = true
                endif // This is just to avoid distance changes if the unit is in the air
                if ((b == true) and (v < 250)) then
                    set v = v + 25
                    elseif ((b == false) or (v == 250)) then
                    exitwhen true // This increases the camera distance until the system detects a non-pathable point.
                                  // Max distance can be changed, its the 450 integer
                endif
            endloop
            if GetLocalPlayer() == Player(i - 1) then //Make the system do the folowing stuff only for one player at the time
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i], 0.5) //Set the rotation of the cam to the units+our rotation wish
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, v, 0.2) //Set the distance to v
            call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 335 + ((z1 - z) * 0.5), 0.32) //This is meant for the player to be able to see the "top of the mountain"
            call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
            call SetCameraField(CAMERA_FIELD_FARZ, 5000, 5) //How far the player will be able to see
            call SetCameraTargetController(udg_camera_target_unit[i], 0, 0, false) //Locks the camera to the unit
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, -0.06) 
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.06) //Height of the camera is adjusted here
          endif
        endif  
    exitwhen i == 12 // Change the value here for more players eg: i==9 for nine players
    set i = i + 1 //Next player is set
    call RemoveLocation(l) //We dont want leaks of points
    endloop //Loop ends for one player and starts for another
    set l = null //We remove the previous l
endfunction
function InitTrig_Multiplayer_Camera takes nothing returns nothing
    set gg_trg_Multiplayer_Camera = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Multiplayer_Camera,0.06,true) //You can change the time if you want the cam to be faster
    call TriggerAddAction( gg_trg_Multiplayer_Camera, function Trig_Multiplayer_Camera_Actions )
endfunction
 
Last edited by a moderator:
  • First you'll have to create some global variables in the variable editor:
    • udg_PathFind -> GUI "region"
    • udg_PathItem -> item
    • udg_PathHid -> item array
    • udg_PathHidMax -> integer
  • Create a trigger named Pathability, go to Edit > Convert to Custom Text, and paste this code there:
    JASS:
    // Pathability trigger
    function InitTrig_Pathability takes nothing returns nothing
    	set udg_PathFind = Rect(0., 0., 128., 128.)
    	set udg_PathItem = CreateItem('wolg', 0, 0)
    	call SetItemVisible(udg_PathItem, false)
    endfunction
  • Then copy and paste the following code into the map header. To find the map header, open the trigger editor, click on the map's name (above all the triggers), and then paste the code there. I didn't check for syntax errors/whether it works, but hopefully it works just fine:
    JASS:
    function IsTerrainDeepWater takes real x, real y returns boolean
        return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
    endfunction
    function IsTerrainShallowWater takes real x, real y returns boolean
        return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
    endfunction
    function IsTerrainLand takes real x, real y returns boolean
        return IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY)
    endfunction
    function IsTerrainPlatform takes real x, real y returns boolean
        return not IsTerrainPathable(x, y, PATHING_TYPE_FLOATABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY) and not IsTerrainPathable(x, y, PATHING_TYPE_BUILDABILITY)
    endfunction
    
    function PathHideItems takes nothing returns nothing
        if IsItemVisible(GetEnumItem()) then
            set udg_PathHid[udg_PathHidMax] = GetEnumItem()
            call SetItemVisible(udg_PathHid[udg_PathHidMax], false)
            set udg_PathHidMax = udg_PathHidMax + 1
        endif
    endfunction
    function IsTerrainWalkable takes real x, real y returns boolean
    	local real X 
    	local real Y
        call MoveRectTo(udg_PathFind, x, y)
        call EnumItemsInRect(udg_PathFind ,null, function PathHideItems)
        call SetItemPosition(udg_PathItem, x, y)
        set X = GetItemX(udg_PathItem)
        set Y = GetItemY(udg_PathItem)
        call SetItemVisible(udg_PathItem, false)
        loop
            exitwhen udg_PathHidMax <= 0
            set udg_PathHidMax = udg_PathHidMax - 1
            call SetItemVisible(udg_PathHid[udg_PathHidMax], true)
            set udg_PathHid[udg_PathHidMax] = null
        endloop
        return (X-x)*(X-x)+(Y-y)*(Y-y) <= 100 and not IsTerrainPathable(x, y, PATHING_TYPE_WALKABILITY)
    endfunction

Let me know if you get any syntax errors/issues importing it.
 
Level 11
Joined
Oct 9, 2015
Messages
721
No syntax error are showing, but the library isn't working. It's an third person camera library that detects doodlads blocking the view and approch the camera to the unit when that happens, any tips ?

EDIT: It's working just fine, I forgot to add an event to the trigger that would begin the camera change, thanks very much for the help!

One more question: I already have an libray in the map header, puting this one there would't cause any conflict, would it ?
 
Level 11
Joined
Oct 9, 2015
Messages
721
Purge, do you see any motives for this scripts to be causing bugs? When in multiplayer the abilities suddenly stops working, the game stops to respond. I click the abilities but they don't make any effect (the abilities are not related to the scripts), it's causing some sort of bug, here are the whole category:

(SOME FUCITIONS IN THIS FIRST TRIGGER ARE DEACTIVATED, THEY ARE RELATED TO THE DEACTIVATED TRIGGERS IN THE END
  • Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- We add each user to the triggers listed below --------
      • Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
        • Loop - Actions
          • Trigger - Add to Camera Swich Units <gen> the event (Player - (Picked player) Selects a unit)
          • Trigger - Add to TurnLEFT ON <gen> the event (Player - (Picked player) Presses the Left Arrow key) ====DEACTIVATED
          • Trigger - Add to TurnRIGHT ON <gen> the event (Player - (Picked player) Presses the Right Arrow key) ====DEACTIVATED
          • Trigger - Add to TurnLEFT OFF <gen> the event (Player - (Picked player) Releases the Left Arrow key) ====DEACTIVATED
          • Trigger - Add to TurnRIGHT OFF <gen> the event (Player - (Picked player) Releases the Right Arrow key) ====DEACTIVATED
      • -------- We set the main unit and the cam unit --------
      • Set camera_main_unit[1] = gg_unit_Hblm_0004 ====DEACTIVATED
      • Set camera_target_unit[1] = gg_unit_Hblm_0004 ====DEACTIVATED
  • Camera Swich Units
    • Events
    • Conditions
      • (Owner of (Triggering unit)) Equal to (Triggering player)
      • ((Triggering unit) is A structure) Equal to False
    • Actions
      • -------- we set the camera unit to no unit --------
      • Set camera_target_unit[(Player number of (Triggering player))] = No unit
      • -------- to prevent leaks we create a temp unit group --------
      • Set tempunitgroup = (Units currently selected by (Triggering player))
      • -------- we search for the main unit in selected units --------
      • Unit Group - Pick every unit in tempunitgroup and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Picked unit) Equal to camera_main_unit[(Player number of (Owner of (Triggering unit)))]
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Leve
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Medio
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Pesado
            • Then - Actions
              • Set camera_target_unit[(Player number of (Triggering player))] = (Picked unit)
            • Else - Actions
              • Do nothing
          • -------- we destroy the temp unit group --------
          • Custom script: call DestroyGroup (udg_tempunitgroup)
          • -------- if there was no main unit in the selected units we set the camera to any selected unit --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • camera_target_unit[(Player number of (Triggering player))] Equal to No unit
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Leve
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Medio
              • (Unit-type of (Triggering unit)) Not equal to Cavalo Pesado
            • Then - Actions
              • Set camera_target_unit[(Player number of (Triggering player))] = (Triggering unit)
            • Else - Actions
              • Do nothing
Code:
//TESH.scrollpos=24
//TESH.alwaysfold=0
function Trig_Multiplayer_Camera_Actions takes nothing returns nothing

    local boolean b                     //The pathing boolean
    local integer i = 1                 //The player index counter
    local location l = Location(0,0)    //A point used to detect height
    local real v                        //The distance of the camera
    local real x                        //Coordinates x,y,z of two points
    local real y
    local real z
    local real x1
    local real y1
    local real z1

    loop
         if udg_camera_target_unit[i] != null and (GetWidgetLife(udg_camera_target_unit[i]) > 0.405) then 
            set v = 25 //We set the minimum distance to 25
            set x = GetUnitX(udg_camera_target_unit[i]) //Get the x coordinate of the unit wich has the camera on it
            set y = GetUnitY(udg_camera_target_unit[i]) //Get the y coordinate of the unit wich has the camera on it
            call MoveLocation(l,x,y) //We move the l point to the units coordinates
            set z = GetLocationZ(l) // store the heignt as z
            set x1 = x + 64 * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            set y1 = y + 64 * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            call MoveLocation(l,x1,y1) 
            set z1 = GetLocationZ(l) //We find the point right in front of the unit's camera and get its height
            loop //Here begins the main loop for all players
                set x1 = x - v * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set y1 = y - v * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set b = IsTerrainWalkable(x1, y1) // This part uses the library I implemented to see is the point behind the unit in distance v is pathable
                if (b == false) then
                    set b = IsTerrainDeepWater(x1, y1) // We dont want to avoid water right...
                endif
                if (GetUnitFlyHeight(udg_camera_target_unit[i]) > 0) then
                    set b = true
                endif // This is just to avoid distance changes if the unit is in the air
                if ((b == true) and (v < 250)) then
                    set v = v + 25
                    elseif ((b == false) or (v == 250)) then
                    exitwhen true // This increases the camera distance until the system detects a non-pathable point.
                                  // Max distance can be changed, its the 450 integer
                endif
            endloop
            if GetLocalPlayer() == Player(i - 1) then //Make the system do the folowing stuff only for one player at the time
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i], 0.5) //Set the rotation of the cam to the units+our rotation wish
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, v, 0.2) //Set the distance to v
            call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 335 + ((z1 - z) * 0.5), 0.32) //This is meant for the player to be able to see the "top of the mountain"
            call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
            call SetCameraField(CAMERA_FIELD_FARZ, 5000, 5) //How far the player will be able to see
            call SetCameraTargetController(udg_camera_target_unit[i], 0, 0, false) //Locks the camera to the unit
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, -0.06) 
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.06) //Height of the camera is adjusted here
          endif
        endif  
    exitwhen i == 12 // Change the value here for more players eg: i==9 for nine players
    set i = i + 1 //Next player is set
    call RemoveLocation(l) //We dont want leaks of points
    endloop //Loop ends for one player and starts for another
    set l = null //We remove the previous l
endfunction
function InitTrig_Multiplayer_Camera takes nothing returns nothing
    set gg_trg_Multiplayer_Camera = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Multiplayer_Camera,0.06,true) //You can change the time if you want the cam to be faster
    call TriggerAddAction( gg_trg_Multiplayer_Camera, function Trig_Multiplayer_Camera_Actions )
endfunction

The rest is the scripts we already discussed, which are connected to these ones, can you identify the possible cause of the problems ?

There are these triggers too, which came with the script, I deactivated since I don't need them:
=====================DEACTIVATED================
  • TurnLEFT ON
    • Events
    • Conditions
      • camera_turnR[(Player number of (Triggering player))] Equal to False
    • Actions
      • Set camera_turnL[(Player number of (Triggering player))] = True
  • TurnRIGHT ON
    • Events
    • Conditions
      • camera_turnL[(Player number of (Triggering player))] Equal to False
    • Actions
      • Set camera_turnR[(Player number of (Triggering player))] = True
  • TurnLEFT OFF
    • Events
    • Conditions
    • Actions
      • Set camera_turnL[(Player number of (Triggering player))] = False
  • TurnRIGHT OFF
    • Events
    • Conditions
    • Actions
      • Set camera_turnR[(Player number of (Triggering player))] = False
  • Turn System
    • Events
      • Time - Every 0.10 seconds of game time
    • Conditions
    • Actions
      • -------- This searches for player wich are turning --------
      • Player Group - Pick every player in (All players controlled by a User player) and do (Actions)
        • Loop - Actions
          • -------- Player turning left turn the camera left --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • camera_turnL[(Player number of (Picked player))] Equal to True
            • Then - Actions
              • Set camera_turn_degree[(Player number of (Picked player))] = (camera_turn_degree[(Player number of (Picked player))] + 10.00)
              • -------- we want to avoid the spin effect --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • camera_turn_degree[(Player number of (Picked player))] Greater than or equal to 360.00
                • Then - Actions
                  • Set camera_turn_degree[(Player number of (Picked player))] = (camera_turn_degree[(Player number of (Picked player))] - 360.00)
                • Else - Actions
                  • Do nothing
            • Else - Actions
              • Do nothing
          • -------- Player turning right turn the camera right --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • camera_turnR[(Player number of (Picked player))] Equal to True
            • Then - Actions
              • Set camera_turn_degree[(Player number of (Picked player))] = (camera_turn_degree[(Player number of (Picked player))] - 10.00)
              • -------- we want to avoid the spin effect --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • camera_turn_degree[(Player number of (Picked player))] Less than or equal to -360.00
                • Then - Actions
                  • Set camera_turn_degree[(Player number of (Picked player))] = (camera_turn_degree[(Player number of (Picked player))] + 360.00)
                • Else - Actions
                  • Do nothing
            • Else - Actions
              • Do nothing
 
Who made the JASS script you posted? After looking at it, there are a couple of potential problems:
(1) The call RemoveLocation(l) should be placed after the endloop, otherwise you end up removing the location prematurely.
e.g.
JASS:
endloop //Loop ends for one player and starts for another
call RemoveLocation(l) //We dont want leaks of points
set l = null //We remove the previous l
(2) The inner loop looks problematic (where it says "Here begins the main loop for all players"). If the terrain is not walkable, and the terrain is not deep water, and the unit's fly height is not > 0, then it will infinitely loop.

I can't give much advice on how to approach #2 since I don't know the details of the system/what it is trying to do. :p
 
Level 11
Joined
Oct 9, 2015
Messages
721
I'll post a test map as soon as I can, I think there are the author name in the notes! I think it's "By TheLegend aka Codenamed". What should be changed in the code to make it work so the game doesn't glitch ?
I see you have an terrain pathability of your own, is it better than the one I'm using? I'm needing these script for a third person camera mode on my project
 
Last edited:
Try this:
JASS:
//TESH.scrollpos=24
//TESH.alwaysfold=0
function Trig_Multiplayer_Camera_Actions takes nothing returns nothing

    local boolean b                     //The pathing boolean
    local integer i = 1                 //The player index counter
    local location l = Location(0,0)    //A point used to detect height
    local real v                        //The distance of the camera
    local real x                        //Coordinates x,y,z of two points
    local real y
    local real z
    local real x1
    local real y1
    local real z1
    local integer iterations = 0

    loop
         if udg_camera_target_unit[i] != null and (GetWidgetLife(udg_camera_target_unit[i]) > 0.405) then 
            set v = 25 //We set the minimum distance to 25
            set x = GetUnitX(udg_camera_target_unit[i]) //Get the x coordinate of the unit wich has the camera on it
            set y = GetUnitY(udg_camera_target_unit[i]) //Get the y coordinate of the unit wich has the camera on it
            call MoveLocation(l,x,y) //We move the l point to the units coordinates
            set z = GetLocationZ(l) // store the heignt as z
            set x1 = x + 64 * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            set y1 = y + 64 * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
            call MoveLocation(l,x1,y1) 
            set z1 = GetLocationZ(l) //We find the point right in front of the unit's camera and get its height
            loop //Here begins the main loop for all players
                exitwhen iterations == 10
                set x1 = x - v * Cos((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set y1 = y - v * Sin((GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i]) * bj_DEGTORAD)
                set b = IsTerrainWalkable(x1, y1) // This part uses the library I implemented to see is the point behind the unit in distance v is pathable
                if (b == false) then
                    set b = IsTerrainDeepWater(x1, y1) // We dont want to avoid water right...
                endif
                if (GetUnitFlyHeight(udg_camera_target_unit[i]) > 0) then
                    set b = true
                endif // This is just to avoid distance changes if the unit is in the air
                if ((b == true) and (v < 250)) then
                    set v = v + 25
                    elseif ((b == false) or (v == 250)) then
                    exitwhen true // This increases the camera distance until the system detects a non-pathable point.
                                  // Max distance can be changed, its the 450 integer
                endif
                set iterations = iterations + 1
            endloop
            if GetLocalPlayer() == Player(i - 1) then //Make the system do the folowing stuff only for one player at the time
            call SetCameraField(CAMERA_FIELD_ROTATION, GetUnitFacing(udg_camera_target_unit[i]) + udg_camera_turn_degree[i], 0.5) //Set the rotation of the cam to the units+our rotation wish
            call SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, v, 0.2) //Set the distance to v
            call SetCameraField(CAMERA_FIELD_ANGLE_OF_ATTACK, 335 + ((z1 - z) * 0.5), 0.32) //This is meant for the player to be able to see the "top of the mountain"
            call SetCameraField(CAMERA_FIELD_FIELD_OF_VIEW, 120, 0)
            call SetCameraField(CAMERA_FIELD_FARZ, 5000, 5) //How far the player will be able to see
            call SetCameraTargetController(udg_camera_target_unit[i], 0, 0, false) //Locks the camera to the unit
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, -0.06) 
            call SetCameraField(CAMERA_FIELD_ZOFFSET, GetUnitFlyHeight(udg_camera_target_unit[i]) + GetCameraField(CAMERA_FIELD_ZOFFSET) + z - GetCameraTargetPositionZ() + 128, 0.06) //Height of the camera is adjusted here
          endif
        endif  
    exitwhen i == 12 // Change the value here for more players eg: i==9 for nine players
    set i = i + 1 //Next player is set
    endloop //Loop ends for one player and starts for another
    call RemoveLocation(l) //We dont want leaks of points
    set l = null //We remove the previous l
endfunction
function InitTrig_Multiplayer_Camera takes nothing returns nothing
    set gg_trg_Multiplayer_Camera = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Multiplayer_Camera,0.06,true) //You can change the time if you want the cam to be faster
    call TriggerAddAction( gg_trg_Multiplayer_Camera, function Trig_Multiplayer_Camera_Actions )
endfunction

I simply moved the RemoveLocation outside the loop (as I mentioned in the previous post) and then I added a cap to the number of times the inner loop can actually run. I didn't test it or even look into the code much, but it might get the job done (assuming it already worked the way you wanted in single player).

I did make a system that checks if a point is pathable, but it was mostly for GUI use. You can probably fit it to work in this code too, but it isn't necessary if you already got the script working.

However, in general I would recommend using some of the camera systems that people have made/coding it yourself using some of the tutorials on the site. It'll be easier for you to configure. :) I'm guessing the system that you posted was one made specifically for a map (and it was probably single player) so it is a bit more difficult to carry over/modify.
 
Level 11
Joined
Oct 9, 2015
Messages
721
It was from a third person camera mode I downloaded here in the hive, I think it's multiplayer as I came with a trigger called "Multiplayer Camera". I'll test the script you provided and see if it stop glitching! If not, then I may assume it is bacause of the unactivated triggers in the category, that may cause issues too, right ?

Anyway, thanks very much for providing me help! I'll be back with the answer for either or not it worked!

EDIT: After a while I discovered the problem was related to the selection trigger, which defined the unit the camera would be set on to, I've made the necessary modifications and it's working fine now! I'll let you know if I find any new issues regarding it. Thanks very much for your help, Purge, it is indeed really appreciated!
 
Last edited:
Status
Not open for further replies.
Top