Necrolytie
Member
Code:
//TESH.scrollpos=15
//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)
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)
if (b == false) then
set b = IsTerrainDeepWater(x1,y1)
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 < 450)) then
set v = v + 25
elseif ((b == false) or (v == 450)) then
exitwhen true // This increases the camera distance until the system detects a nonpathable 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 == 11 // 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
Attachments

104.5 KB Views: 321