//TESH.scrollpos=0
//TESH.alwaysfold=0
Name | Type | is_array | initial_value |
MS_DummyUnit | unitcode | No | |
MS_Hash | hashtable | No | |
MS_KillMissle | boolean | No | |
MS_LeakPoint | location | Yes | |
MS_MaxHeight | real | No | |
MS_Missles | group | No | |
MS_PlayableMapArena | rect | No | |
MS_RefreshRate | real | No | |
MS_TempReal | real | Yes | |
MS_TempUnit | unit | Yes | |
MS_Timer | timer | No | |
MSI_Angle | real | No | |
MSI_Caster | unit | No | |
MSI_CollisionRadius | real | No | |
MSI_Damage | real | No | |
MSI_DamageRad | real | No | |
MSI_Distance | real | No | |
MSI_MissleDeadModel | string | No | |
MSI_MissleModel | string | No | |
MSI_Speed | real | No | |
MSI_SpeedIncraise | real | No | |
MSI_ZAngle | real | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
//made by hell gate
library UnitCollision initializer Init
globals
private hashtable UC_Hash
private constant integer Sphere = 1
private constant integer Cylinder = 2
private real MaxCollSize = 0.
private constant integer DummyId = 'h000' // your private dummy unit
endglobals
function GetUnitCollSizeSphere takes unit u returns real
return LoadReal( UC_Hash, GetUnitTypeId(u), 1)
endfunction
function GetUnitRadCylinder takes unit u returns real
return LoadReal( UC_Hash, GetUnitTypeId(u), 1)
endfunction
function GetUnitHeightCylinder takes unit u returns real
return LoadReal( UC_Hash, GetUnitTypeId(u), 2)
endfunction
function GetUnitType takes unit u returns integer
return LoadInteger(UC_Hash,GetUnitTypeId(u),0)
endfunction
function AddUnitCollisionSphere takes integer uID, real rad returns nothing
call SaveInteger(UC_Hash, uID, 0, Sphere)
call SaveReal(UC_Hash, uID, 1, rad)
if rad >= MaxCollSize then
set MaxCollSize =rad+.5
endif
endfunction
function AddUnitCollisionCylinder takes integer uID, real rad, real height returns nothing
local real x = SquareRoot((rad*rad)+(height*height))
call SaveInteger(UC_Hash, uID, 0, Cylinder)
call SaveReal(UC_Hash, uID, 1, rad)
call SaveReal(UC_Hash, uID, 2, height)
if x >= MaxCollSize then
set MaxCollSize = x+.5
endif
endfunction
function CheckForCollision takes real x, real y, real z, real size, player p returns boolean
local group g = CreateGroup()
local unit u = null
local real array r
local boolean b = false
local location p1
local location p2
call GroupEnumUnitsInRange( g, x, y, MaxCollSize, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null or b == true
if GetUnitTypeId(u)!= DummyId and GetUnitState(u,UNIT_STATE_LIFE) > 0.405 then
if GetUnitType(u) == Sphere then
set r[0] = x - GetUnitX(u)
set r[1] = y - GetUnitY(u)
set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
set p1 = GetUnitLoc(u)
set p2 = Location(x,y)
set r[3] = (GetUnitFlyHeight(u)+GetLocationZ(p1))-(z+GetLocationZ(p2))
set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
set b = ((r[4] <= GetUnitCollSizeSphere(u)+size) and GetOwningPlayer(u) != p)
call RemoveLocation(p1)
call RemoveLocation(p2)
elseif GetUnitType(u) == Cylinder then
set r[0] = x - GetUnitX(u)
set r[1] = y - GetUnitY(u)
set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
set p1 = GetUnitLoc(u)
set p2 = Location(x,y)
set r[3] = GetUnitFlyHeight(u)
set b = (r[2] <= GetUnitRadCylinder(u)+size and z+GetLocationZ(p2) > r[3]-size+GetLocationZ(p1) and z+GetLocationZ(p2) < r[3]+GetUnitHeightCylinder(u)+size+GetLocationZ(p1) and GetOwningPlayer(u) != p)
call RemoveLocation(p1)
call RemoveLocation(p2)
endif
endif
call GroupRemoveUnit(g,u)
set u = null
endloop
call DestroyGroup(g)
set g = null
set u = null
return b
endfunction
// extra function to damage units in range with the unit collision system
// (simpel edit from the check for collision function)
function DamageUnitInRange takes real x, real y, real z, real damage, real rad, unit damagedealer returns nothing
local group g = CreateGroup()
local unit u = null
local real array r
local location p1
local location p2
call GroupEnumUnitsInRange( g, x, y, MaxCollSize, null)
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetUnitTypeId(u)!= DummyId and GetUnitState(u,UNIT_STATE_LIFE) > 0.405 then
if GetUnitType(u) == Sphere then
set r[0] = x - GetUnitX(u)
set r[1] = y - GetUnitY(u)
set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
set p1 = GetUnitLoc(u)
set p2 = Location(x,y)
set r[3] = (GetUnitFlyHeight(u)+GetLocationZ(p1))-(z+GetLocationZ(p2))
set r[4] = SquareRoot(r[2] * r[2] + r[3] * r[3])
if (r[4] <= GetUnitCollSizeSphere(u)+rad) and GetOwningPlayer(u) != GetOwningPlayer(damagedealer) then
call UnitDamageTarget(damagedealer, u, damage, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
call RemoveLocation(p1)
call RemoveLocation(p2)
elseif GetUnitType(u) == Cylinder then
set r[0] = x - GetUnitX(u)
set r[1] = y - GetUnitY(u)
set r[2] = SquareRoot(r[0] * r[0] + r[1] * r[1])
set p1 = GetUnitLoc(u)
set p2 = Location(x,y)
set r[3] = GetUnitFlyHeight(u)
if r[2] <= GetUnitRadCylinder(u)+rad and z+GetLocationZ(p2) > r[3]-rad+GetLocationZ(p1) and z+GetLocationZ(p2) < r[3]+GetUnitHeightCylinder(u)+rad+GetLocationZ(p1) and GetOwningPlayer(u) != GetOwningPlayer(damagedealer) then
call UnitDamageTarget(damagedealer, u, damage, true, false, ATTACK_TYPE_MELEE, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
call RemoveLocation(p1)
call RemoveLocation(p2)
endif
endif
call GroupRemoveUnit(g,u)
set u = null
endloop
call DestroyGroup(g)
set g = null
set u = null
endfunction
private function Init takes nothing returns nothing
set UC_Hash = InitHashtable()
call AddUnitCollisionSphere('h004',100)
call AddUnitCollisionSphere('h001',30)
call AddUnitCollisionSphere('h005',50)
call AddUnitCollisionSphere('h007',90)
call AddUnitCollisionCylinder('h002',50,45)
call AddUnitCollisionCylinder('h008',45,100)
call AddUnitCollisionCylinder('h006',100,240)
call AddUnitCollisionCylinder('h003',60,280)
call AddUnitCollisionCylinder('h009',12.5,35)
call AddUnitCollisionCylinder('h00A',14,35)
endfunction
endlibrary
//TESH.scrollpos=0
//TESH.alwaysfold=0
//|=======================================================|
//| this system is made by The_Witcher |
//| all credits for this system goes to him |
//|=======================================================|
library CollisionSystem initializer Init
globals
private integer array class
private real array xx
private real array yy
private real array zz
private integer total = 0
private hashtable h = InitHashtable()
private real maxR = 0
private group g = CreateGroup()
private boolean Free = true
private real X
private real Y
private real Z
endglobals
function AddEnvironmentCollision takes integer rcode, real SizeX, real SizeY, real SizeZ returns nothing
if LoadInteger(h,rcode,0) == 0 then
set total = total + 1
set xx[total] = SizeX / 2
set yy[total] = SizeY / 2
set zz[total] = SizeZ
set class[total] = rcode
call SaveInteger(h, rcode, 0, total)
if SizeX > maxR then
set maxR = SizeX
endif
if SizeY > maxR then
set maxR = SizeY
endif
endif
endfunction
private function GetRectFromCircle takes real x, real y, real radius returns rect
return Rect(x - radius, y - radius, x + radius, y + radius)
endfunction
private function Destrloop takes nothing returns nothing
local integer i = LoadInteger(h,GetDestructableTypeId(GetEnumDestructable()),0)
local real x = GetDestructableX(GetEnumDestructable())
local real y = GetDestructableY(GetEnumDestructable())
if Free then
if i != 0 then
if (X > x - xx[i] and X < x + xx[i]) and (Y > y - yy[i] and Y < y + yy[i]) and (Z >= 0 and Z < zz[i]) then
set Free = false
endif
endif
endif
endfunction
private function AliveFilter takes nothing returns boolean
return not (IsUnitType(GetFilterUnit(),UNIT_TYPE_DEAD) or GetUnitTypeId(GetFilterUnit()) == 0 )
endfunction
function IsWayFree takes real x, real y, real z returns boolean
local location p = Location(x,y)
local unit u
local integer i
local real xxx
local real yyy
local real zzz
set X = x
set Y = y
set Z = z
set Free = true
call EnumDestructablesInCircleBJ(maxR,p,function Destrloop)
if Free then
call GroupEnumUnitsInRange(g,x,y,maxR,Condition(function AliveFilter))
loop
set u = FirstOfGroup(g)
exitwhen u == null or not Free
set i = LoadInteger(h,GetUnitTypeId(u),0)
if i != 0 then
set xxx = GetUnitX(u)
set yyy = GetUnitY(u)
set zzz = GetUnitFlyHeight(u)
set Free = (X > xxx - xx[i] and X < xxx + xx[i]) and (Y > yyy - yy[i] and Y < yyy + yy[i]) and(Z >= zzz and Z < zzz+ zz[i])
set Free = not Free
endif
call GroupRemoveUnit(g,u)
endloop
endif
return Free
endfunction
function IsWayFreeLoc takes location p, real z returns boolean
return IsWayFree(GetLocationX(p),GetLocationY(p),z)
endfunction
private function Init takes nothing returns nothing
call AddEnvironmentCollision(
endfunction
endlibrary
//TESH.scrollpos=32
//TESH.alwaysfold=0
library GetWeappon initializer Init
globals
private hashtable GW_Hash
private real rate
endglobals
//a very simple system to store the informations for this missile system
function GW_AddUnitInformation takes integer uID , real v, real a, real collrad, real dmg, real dmgrad, real dist, string deadsfx, string missilesfx, real Zoffset, real missilesize, real variation returns nothing
call SaveReal(GW_Hash, uID, 0, v)
call SaveReal(GW_Hash, uID, 1, a)
call SaveReal(GW_Hash, uID, 2, collrad)
call SaveReal(GW_Hash, uID, 3, dmg)
call SaveReal(GW_Hash, uID, 4, dmgrad)
call SaveReal(GW_Hash, uID, 5, dist)
call SaveReal(GW_Hash, uID, 6, Zoffset)
call SaveReal(GW_Hash, uID, 7, missilesize)
call SaveStringBJ( deadsfx, 8, uID, GW_Hash )
call SaveStringBJ( missilesfx, 9, uID, GW_Hash )
call SaveReal(GW_Hash, uID, 10, variation)
//i use SaveStringBJ because SaveString doesn't exist :(
endfunction
function GW_SetSettings takes integer uID returns nothing
set udg_MSI_Speed = LoadReal(GW_Hash, uID, 0)
set udg_MSI_SpeedIncraise = LoadReal(GW_Hash, uID, 1)
set udg_MSI_CollisionRadius = LoadReal(GW_Hash, uID, 2)
set udg_MSI_Damage = LoadReal(GW_Hash, uID, 3)
set udg_MSI_DamageRad = LoadReal(GW_Hash, uID, 4)
set udg_MSI_Distance = LoadReal(GW_Hash, uID, 5)
set udg_MS_TempReal[5] = LoadReal(GW_Hash, uID, 6)
set udg_MS_TempReal[2] = LoadReal(GW_Hash, uID, 7)
set udg_MSI_MissleDeadModel = LoadStringBJ(8, uID, GW_Hash)
set udg_MSI_MissleModel = LoadStringBJ(9, uID, GW_Hash)
set udg_MS_TempReal[7] = LoadReal(GW_Hash, uID, 10)
// same reason for the BJ
endfunction
// GW tigger ends
private function Init takes nothing returns nothing
set GW_Hash = InitHashtable()
set rate = udg_MS_RefreshRate
//=================================================================================================== GW Set Settings =========================================================================================================================================================
//!-----------------------|--------|------------|---------|-------|------|--------|---------|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------|---------|-------|---------|
//! call function | ID | v | a |collrad| dmg | dmgrad | maxdist | dead sfx | missile sfx | Zoffset | scale |variation|
//!-----------------------|--------|------------|---------|-------|------|--------|---------|---------------------------------------------------------------------------------------|--------------------------------------------------------------------------|---------|-------|---------|
call GW_AddUnitInformation('h001', 2000.0*rate, 0.0, 60.0, 20.0, 75.0, 2000.0, "Abilities\\Weapons\\GyroCopter\\GyroCopterImpact.mdl", "Abilities\\Weapons\\WardenMissile\\WardenMissile.mdl", 5.0, 0.6, 3.0)
call GW_AddUnitInformation('h004', 10.0*rate, 10.0*rate, 60.0, 130.0, 110.0, 2000.0, "Abilities\\Weapons\\GyroCopter\\GyroCopterMissile.mdl", "Abilities\\Weapons\\GyroCopter\\GyroCopterMissile.mdl", 5.0, 0.85, 2.0)
call GW_AddUnitInformation('h002', 2000.0*rate, 0.0, 60.0, 50.0, 110.0, 2000.0, "Abilities\\Weapons\\RocketMissile\\RocketMissile.mdl", "Abilities\\Weapons\\RocketMissile\\RocketMissile.mdl", 45.0, 0.8, 0.5)
call GW_AddUnitInformation('h003', 2000.0*rate, 0.0, 60.0, 30.0, 80.0, 2000.0, "Abilities\\Weapons\\FaerieDragonMissile\\FaerieDragonMissile.mdl", "Abilities\\Weapons\\FaerieDragonMissile\\FaerieDragonMissile.mdl", 265.0, 0.8, 0.5)
call GW_AddUnitInformation('h005', 1500.0*rate, 0.0, 60.0, 25.0, 240.0, 2000.0, "Objects\\Spawnmodels\\Other\\NeutralBuildingExplosion\\NeutralBuildingExplosion.mdl", "Abilities\\Weapons\\LordofFlameMissile\\LordofFlameMissile.mdl", 45.0, 0.8, 0.75)
call GW_AddUnitInformation('h00A', 2250.0*rate, 0.0, 67.5, 15.0, 80.0, 2000.0, "war3mapImported\\LaserRed.mdx", "war3mapImported\\LaserRed.mdx", 15.0, 0.4, 0.5)
call GW_AddUnitInformation('h006', 10.0*rate, 7.5*rate, 60.0, 40.0, 80.0, 3000.0, "Abilities\\Weapons\\ZigguratMissile\\ZigguratMissile.mdl", "Abilities\\Weapons\\ZigguratMissile\\ZigguratMissile.mdl", 180.0, 0.8, 0.5)
call GW_AddUnitInformation('h007', 1500.0*rate, 0.0, 60.0, 90.0, 120.0, 2500.0, "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl", "Abilities\\Weapons\\PhoenixMissile\\Phoenix_Missile.mdl", 65.0, 0.8, 0.75)
call GW_AddUnitInformation('h008', 500.0*rate, 5.0*rate, 60.0, 100.0, 200.0, 1500.0, "Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.mdl", "Abilities\\Spells\\Orc\\LightningBolt\\LightningBoltMissile.mdl", 80.0, 0.8, 0.25)
call GW_AddUnitInformation('h009', 2250.0*rate, 0.0, 67.5, 5.0, 70.0, 2000.0, "Abilities\\Weapons\\WardenMissile\\WardenMissile.mdl", "Abilities\\Weapons\\WardenMissile\\WardenMissile.mdl", 10.0, 0.4, 1.25)
// =======================================
endfunction
endlibrary