//==================================================================================================================\\
// ____ ______ _____ _ \\
// / __ \ | ___ \ | __ \ _ | | \\
// /__/ \ \ | | \ \ | | \ | | | | | \\
// | | | | \ || |__/ | _ _ ___ _ ___ _____ __| |__ _ | | ___ \\
// / / | | | || ____/ | |/ __\ / _ \ |_| / __ \ / __/ |__ __| |_| | | / __ \ \\
// / / | | | || | | / | / \ | _ | / _| | | / | | _ | | | / _| | \\
// / / | | / || | | | | | | | | | | |/_ / | | | | | | | | | |/_ / \\
// / /_____ | |___/ / | | | | | \_/ | | | | \___ | \____ | | | | | | | \___ \\
// |_________| |______/ |_| |_| \ ___ / | | \ ____| \ ___ / |_| |_| |_| \ ____| \\
// ____ _ / | \\
// / __ \ \ _ / _ \\
// | / \__| | | \\
// \ \ __ __ __ __| |__ ___ __ __ \\
// \ \ \ \ / / / _ \ |__ __| / __ \ | \/ | \\
// \ \ \ / | / \ | | | / _| | | |\ /| | \\
// __ \ \ | | \ \ | | | |/_ / | | \/ | | \\
// | \_/ | | | _/ | | | | \___ | | | | \\
// \ ___ / |_| \ __ / |_| \ ____| |_| |_| \\
// \\
// ______ \\
// | __ \ \\
// | | | | __ __ \\
// | | / / \ \ / / \\
// | | \ \ \ / \\
// | | | | | | \\
// | |__| | | | \\
// |_____ / |_| \\
// _ _ \\
// | \ | | \\
// | \ | | \\
// | |\ \ | | ____ _ _ ___ ____ ___ ____ \\
// | | \ \ | | |___ \ | |/ __\ / _ \ / ___ | / _ \ / ___ | \\
// | | \ \ | | ___| | | / | / \ | | | | | | / \ || | | | \\
// | | \ \| | / _ | | | | | | | | | | | | | | || | | | \\
// | | \ | | (_) | | | | \ _ / | | |___| | | \ _ / || |___| | \\
// |_| \__| \ ___/ |_| \ ___ / \ ___ | \ ___ / \ ___ | \\
// | | | | \\
// ___ / / __ / / \\
// |____/ |___/ \\
// \\
//====================================================================================================================
//2d projectile system By Narogog,
//=======================================================
//
//version 0.1b
//
//importing
// copy and paste the trigger entiled "Variables" after doing so you can delete it.
// copy and paste this to the maps header
// copy and paste MS to your map
// Give Credits
// if you want to modify this go ahead. but Give credits.
//
//
//
//User variables
//
//=============================================================================
// udg_Proj_CollisionEvent (real) *
//is used to trigger collision events *
// when its =0.00 a projectile has collided with a unit collision has occured *
// when its = 1.00 a projectile collision occured *
// when its = 2.00 a unit has collided with a unit *
// when its = 3.00 a projectile has ran out of fuel, *
// when its = 3.50 its target has died *
// when its = 4.00 a unit has left the playable map *
//=============================================================================
//
//====================================================================
// udg_Proj_CollisionUnit (unit) *
// is the unit that is being hit *
// used in all collisions *
//====================================================================
//
//====================================================================
// udg_Proj_CollidingU (unit) *
// is the projectile that is colliding *
// used in 1,2 *
//====================================================================
//
//====================================================================
// udg_Proj_CollisionIndex (int) *
// the index of the projectile, used with 1,3,3.5,4 *
// used with call Proj_deallocate(udg_Proj_CollisionIndex) to "kill" *
// the projectile *
//====================================================================
//
//====================================================================
// udg_Proj_CollisionIndex2 (int) *
// used only in projectile collisions ie 2 *
//====================================================================
//
//====================================================================
// Proj_deallocate (function) *
// how to use just call Proj_deallocate(projindex) *
// where projindx is LoadInteger(udg_Proj,GetHandleId(someProj),1) *
// what does this do? well it "destroys" the projectile *
// make sure you nullify all data connected to the projectile *
//====================================================================
//
//====================================================================
// CreateProjectile (function) *
// to use *
// set udg_I CreateProjectile(owner,x,y,facing,speed,life,attach, *
// modelpath, 0,null) *
// then you can use udg_I as the index of an array, import get rid of*
// all data connected to the projectile. before deallocating it *
//====================================================================
//
//====================================================================
// udg_Proj_Target[array] (unit) *
// use this when setting a new target for a projectile *
// CAUTION only use udg_CollisionIndex for changing this *
// to prevent interfering with another projectile *
//====================================================================
// end of user vars begining of system variables *
//
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_Group (group) *
// this is the lazy projectile group *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_Leave_Map (group) *
// this is a group that contains all units who have left the map *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_Proj_NotCollidable (group) *
// this contains units that cannot be collided with *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//end of system vars(for now)
//
//do NOT modify the following values
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// udg_Proj_Group_Count (integer) *
// this is just the number of lazy projectiles *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//udg_ProjMax (integer) *
//number of active projectiles *
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//
//
//
//Currently there is only one global collision size.
//
//
//currently does NOT support Terrain wall collisions.
//currently does Not support Destructible collisions.
//
// Allocate
function Proj_allocate takes nothing returns integer
// allocate it
local integer this
if udg_Proj_instanceRecycle == 0 then
set udg_Proj_instanceCount = udg_Proj_instanceCount + 1
set this = udg_Proj_instanceCount
else
set this = udg_Proj_instanceRecycle
set udg_Proj_instanceRecycle = udg_Proj_recycleNext[this]
endif
// add it to the list
set udg_Proj_next[this] = 0
set udg_Proj_prev[this] = udg_Proj_prev[0]
set udg_Proj_next[udg_Proj_prev[0]] = this
set udg_Proj_prev[0] = this
// return the new instance
return this
endfunction
// deallocate:
function Proj_deallocate takes integer this returns nothing
// deallocate it
if this == 0 then
else
set udg_Proj_recycleNext[this] = udg_Proj_instanceRecycle
set udg_Proj_instanceRecycle = this
// remove it from the list
set udg_Proj_next[udg_Proj_prev[this]] = udg_Proj_next[this]
set udg_Proj_prev[udg_Proj_next[this]] = udg_Proj_prev[this]
set udg_Proj_Max = udg_Proj_Max - 1
call ShowUnit(udg_Proj_U[this],false)// making it visible
set udg_Proj_Group_Count= udg_Proj_Group_Count +1
call GroupAddUnit(udg_Proj_Group,udg_Proj_U[this])
call GroupAddUnit(udg_Proj_NotCollidable,udg_Proj_U[this])
call SaveInteger(udg_Proj,GetHandleId(udg_Proj_U[this]),1,0)
call DestroyEffect(udg_Proj_E[this])
call DisableTrigger(LoadTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[this]),0))
endif
endfunction
function Proj_Collision takes nothing returns boolean//this triggers the collision event
local unit u = GetTriggerUnit()
set udg_Proj_CollisionUnit = LoadUnitHandle(udg_Proj,GetHandleId(GetTriggeringTrigger()),0)
if IsUnitInGroup(u,udg_Proj_NotCollidable)==false and GetUnitState(u, UNIT_STATE_LIFE) > 0 and GetUnitState(udg_Proj_CollisionUnit, UNIT_STATE_LIFE) > 0 then
//this checks to see if it is a projectile collision, ie only projectiles are involved.
if GetUnitTypeId(udg_Proj_CollisionUnit) == udg_Proj_UnitId then
if GetUnitTypeId(u) == udg_Proj_UnitId then
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollisionUnit),1)
set udg_Proj_CollisionIndex2=LoadInteger(udg_Proj,GetHandleId(u),1)
set udg_Proj_CollidingU = u
set udg_Proj_CollisionEvent = 1
else
set udg_Proj_CollidingU = udg_Proj_CollisionUnit
set udg_Proj_CollisionUnit=u
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollidingU),1)
set udg_Proj_CollisionEvent = 0
endif
else
set udg_Proj_CollidingU=u
if GetUnitTypeId(udg_Proj_CollidingU) != udg_Proj_UnitId then
set udg_Proj_CollisionEvent = 2
else
set udg_Proj_CollisionIndex=LoadInteger(udg_Proj,GetHandleId(udg_Proj_CollidingU),1)
set udg_Proj_CollisionEvent = 0
endif
endif
set udg_Proj_CollisionEvent = -1
endif
set u = null
return false
endfunction
// CreateProjectile takes player owner of projectile, real x coord, real y coord, real facing, real speed, real how long the projectile lasts, string attachement string ie "origin", string model
function CreateProjectile takes player p, real x, real y, real f, real s, real l, string a, string e,unit target, real rate returns integer
local integer i = Proj_allocate()
if udg_Proj_Max == 0 then
call EnableTrigger(gg_trg_MS)
endif
set udg_Proj_Max = udg_Proj_Max +1
if udg_Proj_Group_Count==0 then// if there are no enough projectiles that are idle it creates one
set udg_Proj_U[i] = CreateUnit(p,udg_Proj_UnitId,x,y,f)
call PauseUnit(udg_Proj_U[i],true)// pausing unit so user can't issue it orders, Unit in range does not detect units with 'aloc' so i am not giving the units 'aloc'
set udg_Proj_T = CreateTrigger()
call TriggerRegisterUnitInRange( udg_Proj_T, udg_Proj_U[i],60, null)// you can modify collision size here
call TriggerAddCondition(udg_Proj_T, Condition(function Proj_Collision))
call SaveTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[i]),0,udg_Proj_T) // saving trigger etc...
call SaveUnitHandle(udg_Proj,GetHandleId(udg_Proj_T),0,udg_Proj_U[i])
else
loop
set udg_Proj_U[i] = FirstOfGroup(udg_Proj_Group) // other wise it just gets one from Missle group
call GroupRemoveUnit(udg_Proj_Group, udg_Proj_U[i])
exitwhen udg_Proj_U[i] != null
endloop
set udg_Proj_Group_Count = udg_Proj_Group_Count - 1
call SetUnitX(udg_Proj_U[i],x)// seting projectiles position
call SetUnitY(udg_Proj_U[i],y)
call SetUnitFacing(udg_Proj_U[i],f)//setting its facing
call SetUnitOwner(udg_Proj_U[i],p,true)//setting owner
call ShowUnit(udg_Proj_U[i],true)// making it visible
call EnableTrigger(LoadTriggerHandle(udg_Proj,GetHandleId(udg_Proj_U[i]),0))
call GroupRemoveUnit(udg_Proj_NotCollidable,udg_Proj_U[i])
endif
call SaveInteger(udg_Proj,GetHandleId(udg_Proj_U[i]),1,i)
set udg_Proj_Y[i] =((Sin(f*bj_DEGTORAD))*s)// setting Y coordinate speed
set udg_Proj_X[i] =((Cos(f*bj_DEGTORAD))*s)// setting X coordinate speed
set udg_Proj_Life[i] = l//setting "timed" life if you want it to travel a certain distance then the furmula would be distance/speed per second or distance/(speed/.03)
set udg_Proj_E[i] = AddSpecialEffectTarget(e,udg_Proj_U[i],a)
set udg_Proj_Target[i] = target
set udg_Proj_TurnSpeed[i] = rate
set udg_Proj_Speed[i] = s
return i
endfunction
//=======================================================
//End of Narogog's 2d Projectile System v 0.4.0.0
//=======================================================