Moderator
M
Moderator
12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.
IcemanBo: Too long as NeedsFix. Rejected.
About system
Allows units to sit on other units simulating a ride on horseback.
Instructions for use inside.
Functions
MSAddUnit(unit id,unit dummy id,animation id) - register unit in system
MSAddMount(mount id, sit height) - register mount in system
MountUnit(unit, target) - mount unit
UnMountUnit(unit) - unmount unit
/*
MOUNT SYSTEM v1.2 BY OXYGEND
Instruction:
--- Setting ---
MSAddUnit(unit id,unit dummy id) - register unit in system
MSAddMount(mount id, sit height) - register mount in system
--- Control ---
MountUnit(unit, target) - mount unit
UnMountUnit(unit) - unmount unit
This functions return true with success and false with fail.
P.S Write my nickname somewhere in credit if you will use this system:)
*/
library MountSys initializer InitSystem
globals
private constant integer Maxunit = 100
private constant real TIMER_PEREODIC = 0.025 // optimal
private constant boolean DEBUG_FLAG = false
endglobals
globals
// General
private timer UpTimer = CreateTimer()
private unit array MountedUnit [Maxunit]
private unit array UnitMounted [Maxunit]
private unit array InvisUnit [Maxunit]
private boolean array OnMOUNT [Maxunit]
private integer MaxUnit = 0
// For registration
integer NOW_MOUNTED = 0
integer REGISTRED_UNITS = 0
integer MOUNT_COUNT = 0
integer array GENERAL_ID [Maxunit]
integer array CLONE_ID [Maxunit]
integer array MOUNT_ID [Maxunit]
integer array MISSED_SLOT [Maxunit]
real array MOUNT_HIGHT [Maxunit]
endglobals
function MSAddUnit takes integer uid,integer cid returns nothing
set REGISTRED_UNITS = REGISTRED_UNITS + 1
set GENERAL_ID[REGISTRED_UNITS] = uid
set CLONE_ID[REGISTRED_UNITS] = cid
endfunction
function MSAddMount takes integer mid,real height returns nothing
set MOUNT_COUNT = MOUNT_COUNT + 1
set MOUNT_ID[MOUNT_COUNT] = mid
set MOUNT_HIGHT[MOUNT_COUNT] = height
endfunction
private function GetMountId takes integer m returns integer
local integer i=1
loop
exitwhen(i>MOUNT_COUNT)
if m == MOUNT_ID[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetMountedUnitId takes unit u returns integer
local integer i = 1
loop
exitwhen(i>MaxUnit)
if u == InvisUnit[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetMissSlot takes nothing returns integer
local integer i = 1
loop
exitwhen(i>MaxUnit)
if MISSED_SLOT[i]>0 then
return MISSED_SLOT[i]
endif
set i = i + 1
endloop
return 0
endfunction
function OnMount takes unit u returns boolean
return OnMOUNT[GetMountedUnitId(u)]
endfunction
function MountUnit takes unit u,unit t returns boolean
local integer id=GetPlayerId(GetOwningPlayer(u))
local integer i = 0
local integer j = 0
local integer ms
loop
exitwhen(i>REGISTRED_UNITS)
if GetUnitTypeId(u) == GENERAL_ID[i] and GetUnitTypeId(t) == MOUNT_ID[GetMountId(GetUnitTypeId(t))] then
loop
exitwhen(j > MaxUnit)
if t == UnitMounted[j] then
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: fail(no place to mount)!")
endif
return false // fail
endif
set j = j + 1
endloop
set ms = GetMissSlot()
if ms != 0 then
set NOW_MOUNTED = NOW_MOUNTED + 1
set InvisUnit[ms] = u
call ShowUnit(u,false)
call SetUnitOwner(t,Player(id),false)
set MountedUnit[ms] = CreateUnit(Player(id),CLONE_ID[i],GetUnitX(t),GetUnitY(t),GetUnitFacing(t))
set UnitMounted[ms] = t
call UnitAddAbility(MountedUnit[ms],'Aave')
call UnitRemoveAbility(MountedUnit[ms],'Aave')
call UnitAddAbility(MountedUnit[ms],'Aloc')
call UnitRemoveAbility(MountedUnit[ms],'Aloc')
set OnMOUNT[ms] = true
set MISSED_SLOT[ms] = 0
else
set NOW_MOUNTED = NOW_MOUNTED + 1
set MaxUnit = MaxUnit + 1
set InvisUnit[MaxUnit] = u
call ShowUnit(u,false)
call SetUnitOwner(t,Player(id),false)
set MountedUnit[MaxUnit] = CreateUnit(Player(id),CLONE_ID[i],GetUnitX(t),GetUnitY(t),GetUnitFacing(t))
set UnitMounted[MaxUnit] = t
call UnitAddAbility(MountedUnit[MaxUnit],'Aave')
call UnitRemoveAbility(MountedUnit[MaxUnit],'Aave')
call UnitAddAbility(MountedUnit[MaxUnit],'Aloc')
call UnitRemoveAbility(MountedUnit[MaxUnit],'Aloc')
set OnMOUNT[MaxUnit] = true
set MISSED_SLOT[MaxUnit] = 0
endif
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: success!")
endif
return true // success
endif
set i = i + 1
endloop
static if DEBUG_FLAG then
call BJDebugMsg("Mounted: fail(unregistred unit)!")
endif
return false // fail
endfunction
function UnMountUnit takes unit u returns boolean
local integer i=0
loop
exitwhen(i>MaxUnit)
if (u == MountedUnit[i]) or (u == InvisUnit[i]) or (u == UnitMounted[i]) then
set OnMOUNT[i] = false
set NOW_MOUNTED = NOW_MOUNTED - 1
call SetUnitFlyHeight(MountedUnit[i],0.0,300.0)
call SetUnitX(InvisUnit[i],GetUnitX(MountedUnit[i]))
call SetUnitY(InvisUnit[i],GetUnitY(MountedUnit[i]))
call SetUnitFacing(InvisUnit[i],GetUnitFacing(MountedUnit[i]))
call SetUnitOwner(UnitMounted[i],Player(15),false)
call RemoveUnit(MountedUnit[i])
call ShowUnit(InvisUnit[i],true)
set MountedUnit[i] = null
set UnitMounted[i] = null
set InvisUnit[i] = null
set MISSED_SLOT[i] = i
static if DEBUG_FLAG then
call BJDebugMsg("Unmounted: success!")
endif
return true // success
endif
set i = i + 1
endloop
static if DEBUG_FLAG then
call BJDebugMsg("Unmounted: fail!")
endif
return false // fail
endfunction
private function UnitPlusMaunt takes nothing returns nothing
local integer i=1
if NOW_MOUNTED > 0 then
loop
exitwhen(i>MaxUnit)
if OnMOUNT[i] then
call SetUnitFacing(MountedUnit[i],GetUnitFacing(UnitMounted[i]))
call SetUnitX(MountedUnit[i],GetUnitX(UnitMounted[i]))
call SetUnitY(MountedUnit[i],GetUnitY(UnitMounted[i]))
call SetUnitFlyHeight(MountedUnit[i],MOUNT_HIGHT[GetMountId(GetUnitTypeId(UnitMounted[i]))],0.0)
endif
set i = i + 1
endloop
endif
endfunction
private function InitSystem takes nothing returns nothing
call TimerStart(UpTimer,TIMER_PEREODIC,true,function UnitPlusMaunt)
endfunction
endlibrary