Trollvottel
never aging title
- Reaction score
- 262
It's a Throw System, made by me using vJass.
No Screenshots to take, just have a look at it.
Have fun <3
If you have some suggestions to make it look nicer or to add new functions, just tell them please.
PS: sry for the horrible terrain
No Screenshots to take, just have a look at it.
JASS:
// Trollvottel's Projectile System v1.4b
// System made by Trollvottel
// Thanks to:
// The maker of vJass, Vexorian and the maker of TT and PUI, Cohadar
// Requirements:
// ++++++++++++++++++++++++
// +*vJass +
// +*TT +
// +*PUI +
// ++++++++++++++++++++++++
//
// The system:
// It's a quite realistic system because it uses real physics formulas but the gravitational
// acceleration is a bit high, like the speed, because in WC3 we don't use metres or inches but
// an own system of longimetry, just don't care about it and use these extra-high values
// PROS:
// ++ Quite realistic
// ++ Easy to use
// CONS:
// -- a little bit imprecise with lower angles with use of GetSpeedToDis(distance, angle)
//
//-----------------------------------------------------------------------------------
/////////////////////////////////////How to use:////////////////////////////////////////
// Decide if you want it to collide with units and how much damage it will do with which radius.
// the functions:
//
//// call TPS_Throw(UnitToThrow, RawCodeOfProjectile, DirectionToThrow, Speed, AngleToThrow, Damage, CollideWithUnits?, Radius)
// This throws a projectile
// It returns the dummy so if you want you can store it in a variable.
//
//// call TPS_ThrowUnit(UnitToThrow, UnitToThrow, DirectionToThrow, Speed, AngleToThrow, Damage, CollideWithUnits?, Radius)
// This throws a unit
// It returns the unit so if you want you can store it in a variable.
//
//// call TPS_ThrowUnitAndDo(thrower, unittothrow, DirectionToThrow, Speed, AngleToThrow, Collide, Radius, functiontocall)
//// call TPS_ThrowAndDo(thrower, unittothrow, DirectionToThrow, Speed, AngleToThrow, Collide, Radius, functiontocall)
// Throws a unit/projectile. If the unit/projectile collides or reaches its destination the function functiontocall will be runned.
// In this function, the Throwing unit will be THROWER, the Throwed unit will be THROWED. Throw Z-angle is
// THROWZ and the speed is THROWSPEED.
// You get The throw angle with THROWANGLE[INDEX]
// if you want other values in your userfunc create globals with array and use the index GetUnitIndex(unit). for this
// you'll have to use the returned bullet in all this functions. in your userfunc you can refer to the index
// with varname[INDEX]
// It may not contain any waits. This call also returns the throwed unit to store it in a variable.
//
//// TPS_GetSpeedToDis(distance, angle)
// Returns the necessary speed for the given angle to reach the given distance.
// Put it as argument for Speed.
//
//// call TPS_StopIt(whichbullet)
// This stops a projectile or unit.
//
// Look at the example trigger "Cast Test" to look how its done.
//-----------------------------------------------------------------------------------
// Final Words:
// I think GRAVIACCELERATION is best at 300 but try out how you want it to be, remember, the higher
// it is the lower is you parabola.
// It begins here:
library TPS uses TT, PUI
globals
private constant real GRAVIACCELERATION = 64*9.8*2 // The higher it is the higher is the gravity
private constant real NORMHEIGHT = 50 // Starts not from the ground
endglobals
//DONT EDIT BELOW:
//-----------------------------------------------------------------------------------
globals
private boolean array STOP
private integer DESTRNUM = 0
unit THROWER
unit THROWED
real THROWSPEED
real THROWZ
integer INDEX
real array THROWANGLE
endglobals
private struct Projectile
real startx
real starty
real disgone = 0
unit bullet
unit caster
real anglecos
real anglesin
real speed
real anglez
real time = 0
real startz = 0
real radius
real damage
integer index
boolean collide
boolean uni = false
boolean anddo = false
trigger trig = null
method onDestroy takes nothing returns nothing
if this.uni == false then
call KillUnit(this.bullet)
endif
call DestroyTrigger(this.trig)
endmethod
endstruct
private function alive takes nothing returns boolean
return GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0
endfunction
private function GetFlyHeight takes real disgone, real speed, real anglez returns real
local real number1 = Tan(anglez*bj_DEGTORAD)* disgone
local real number2 = (GRAVIACCELERATION / (2*Pow(speed,2)*Pow(Cos(anglez*bj_DEGTORAD),2))) * Pow(disgone,2)
local real height = number1-number2
return height
endfunction
private function GetTrue takes nothing returns boolean
return true
endfunction
public function GetSpeedToDis takes real distance, real angle returns real
local real number1 = distance * GRAVIACCELERATION
local real number2 = Sin(2*angle*bj_DEGTORAD)
return SquareRoot(number1 / number2)
endfunction
private function EnumEm takes nothing returns nothing
call KillDestructable(GetEnumDestructable())
set DESTRNUM = DESTRNUM + 1
endfunction
private function Throw_child takes nothing returns boolean
local Projectile dat = TT_GetData()
local real x
local real y
local unit u
local group g
local location loc = GetUnitLoc(dat.bullet)
local real nZ
local real atmZ = GetLocationZ(loc)
local integer count = 0
call RemoveLocation(loc)
set loc = null
set dat.time = dat.time + TT_PERIOD
set dat.disgone = dat.speed * dat.time * SquareRoot(Pow(Cos(dat.anglez*bj_DEGTORAD),2))
set x = dat.startx + dat.disgone * dat.anglecos
set y = dat.starty + dat.disgone * dat.anglesin
if x > GetRectMinX(bj_mapInitialPlayableArea) and x < GetRectMaxX(bj_mapInitialPlayableArea) and y < GetRectMaxY(bj_mapInitialPlayableArea) and y > GetRectMinY(bj_mapInitialPlayableArea) then
call SetUnitX(dat.bullet,x)
call SetUnitY(dat.bullet,y)
else
set STOP[dat.index] = true
endif
call SetUnitFlyHeight(dat.bullet, GetFlyHeight(dat.disgone, dat.speed, dat.anglez)+dat.startz+NORMHEIGHT-atmZ, 0)
if GetUnitFlyHeight(dat.bullet)- atmZ <= dat.radius and dat.collide == true then
call EnumDestructablesInRect(Rect(GetUnitX(dat.bullet)-dat.radius, GetUnitY(dat.bullet)-dat.radius,GetUnitX(dat.bullet)+dat.radius, GetUnitY(dat.bullet)+dat.radius), Condition(function GetTrue), function EnumEm)
if DESTRNUM > 0 then
set STOP[dat.index] = true
set DESTRNUM = 0
endif
if not dat.anddo then
set g = CreateGroup()
call GroupEnumUnitsInRange(g, GetUnitX(dat.bullet), GetUnitY(dat.bullet),dat.radius, Condition(function alive))
loop
set u = FirstOfGroup(g)
call GroupRemoveUnit(g,u)
exitwhen u == null
if IsUnitEnemy(u, GetOwningPlayer(dat.caster)) == true then
set count = count + 1
endif
endloop
call DestroyGroup(g)
set g = null
if count > 0 then
set STOP[dat.index] = true
endif
else
set g = CreateGroup()
call GroupEnumUnitsInRange(g, GetUnitX(dat.bullet), GetUnitY(dat.bullet),dat.radius, Condition(function alive))
loop
set u = FirstOfGroup(g)
call GroupRemoveUnit(g,u)
exitwhen u == null
if IsUnitEnemy(u, GetOwningPlayer(dat.caster)) == true then
set count = count + 1
endif
endloop
call DestroyGroup(g)
set g = null
if count > 0 then
set STOP[dat.index] = true
endif
endif
endif
if GetFlyHeight(dat.disgone, dat.speed, dat.anglez)+NORMHEIGHT+dat.startz-atmZ <= 2 or STOP[dat.index] == true then
if not dat.anddo then
set g = CreateGroup()
call GroupEnumUnitsInRange(g, GetUnitX(dat.bullet), GetUnitY(dat.bullet), dat.radius, Condition(function alive))
loop
set u = FirstOfGroup(g)
call GroupRemoveUnit(g,u)
exitwhen u == null
if IsUnitEnemy(u, GetOwningPlayer(dat.caster)) == true then
call UnitDamageTarget(dat.caster, u, dat.damage, true, false, ATTACK_TYPE_CHAOS, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
endif
endloop
call DestroyGroup(g)
set g = null
else
set THROWER = dat.caster
set THROWED = dat.bullet
set THROWSPEED = dat.speed
set THROWZ = dat.anglez
set INDEX = dat.index
call TriggerExecute(dat.trig)
endif
call dat.destroy()
return true
endif
return false
endfunction
public function Throw takes unit whichunit, integer tothrow, real angle, real speed, real anglez, real dmg, boolean collide, real radius returns unit
local Projectile dat = Projectile.create()
local location loc = GetUnitLoc(whichunit)
set dat.startz = GetLocationZ(loc)
call RemoveLocation(loc)
set loc = null
set dat.bullet = CreateUnit(GetOwningPlayer(whichunit), tothrow, GetUnitX(whichunit), GetUnitY(whichunit), GetUnitFacing(whichunit))
set dat.anglecos = Cos(angle * bj_DEGTORAD)
set dat.anglesin = Sin(angle * bj_DEGTORAD)
if anglez < 90 then
set dat.anglez = anglez
else
set dat.anglez = 89
endif
call UnitAddAbility(dat.bullet,039;Arav039;)
call UnitRemoveAbility(dat.bullet,039;Arav039;)
set dat.caster = whichunit
set dat.startx = GetUnitX(whichunit)
set dat.starty = GetUnitY(whichunit)
set dat.radius = radius
set dat.speed = speed
set dat.damage = dmg
set dat.collide = collide
set dat.index = GetUnitIndex(dat.bullet)
set STOP[dat.index] = false
set THROWANGLE[dat.index] = angle
call TT_Start(function Throw_child,dat)
call SetUnitFlyHeight(dat.bullet, NORMHEIGHT,0)
return dat.bullet
endfunction
public function ThrowUnit takes unit whichunit, unit tothrow, real angle, real speed, real anglez, real dmg, boolean collide, real radius returns unit
local Projectile dat = Projectile.create()
local location loc = GetUnitLoc(whichunit)
set dat.startz = GetLocationZ(loc)
call RemoveLocation(loc)
set loc = null
set dat.bullet = tothrow
set dat.anglecos = Cos(angle * bj_DEGTORAD)
set dat.anglesin = Sin(angle * bj_DEGTORAD)
if anglez < 90 then
set dat.anglez = anglez
else
set dat.anglez = 89
endif
set dat.caster = whichunit
set dat.startx = GetUnitX(tothrow)
set dat.starty = GetUnitY(tothrow)
set dat.radius = radius
set dat.speed = speed
set dat.damage = dmg
set dat.collide = collide
set dat.uni = true
call UnitAddAbility(tothrow,039;Arav039;)
call UnitRemoveAbility(tothrow,039;Arav039;)
set dat.index = GetUnitIndex(dat.bullet)
set STOP[dat.index] = false
set THROWANGLE[dat.index] = angle
call TT_Start(function Throw_child,dat)
call SetUnitFlyHeight(dat.bullet, NORMHEIGHT,0)
return dat.bullet
endfunction
public function ThrowUnitAndDo takes unit whichunit, unit tothrow, real angle, real speed, real anglez, boolean collide, real radius, code userfunc returns unit
local Projectile dat = Projectile.create()
local location loc = GetUnitLoc(whichunit)
set dat.startz = GetLocationZ(loc)
call RemoveLocation(loc)
set loc = null
set dat.trig = CreateTrigger()
call TriggerAddAction(dat.trig, userfunc)
set dat.bullet = tothrow
set dat.anglecos = Cos(angle * bj_DEGTORAD)
set dat.anglesin = Sin(angle * bj_DEGTORAD)
if anglez < 90 then
set dat.anglez = anglez
else
set dat.anglez = 89
endif
set dat.caster = whichunit
set dat.startx = GetUnitX(tothrow)
set dat.starty = GetUnitY(tothrow)
set dat.radius = radius
set dat.anddo = true
set dat.speed = speed
set dat.damage = 0
set dat.collide = collide
set dat.uni = true
call UnitAddAbility(tothrow,039;Arav039;)
call UnitRemoveAbility(tothrow,039;Arav039;)
set dat.index = GetUnitIndex(dat.bullet)
set STOP[dat.index] = false
set THROWANGLE[dat.index] = angle
call TT_Start(function Throw_child,dat)
call SetUnitFlyHeight(dat.bullet, NORMHEIGHT,0)
return dat.bullet
endfunction
public function ThrowAndDo takes unit whichunit, integer tothrow, real angle, real speed, real anglez, boolean collide, real radius, code userfunc returns unit
local Projectile dat = Projectile.create()
local location loc = GetUnitLoc(whichunit)
set dat.startz = GetLocationZ(loc)
call RemoveLocation(loc)
set loc = null
set dat.trig = CreateTrigger()
call TriggerAddAction(dat.trig,userfunc)
set dat.bullet = CreateUnit(GetOwningPlayer(whichunit), tothrow, GetUnitX(whichunit), GetUnitY(whichunit), GetUnitFacing(whichunit))
set dat.anglecos = Cos(angle * bj_DEGTORAD)
set dat.anglesin = Sin(angle * bj_DEGTORAD)
if anglez < 90 then
set dat.anglez = anglez
else
set dat.anglez = 89
endif
call UnitAddAbility(dat.bullet,039;Arav039;)
call UnitRemoveAbility(dat.bullet,039;Arav039;)
set dat.caster = whichunit
set dat.startx = GetUnitX(whichunit)
set dat.starty = GetUnitY(whichunit)
set dat.radius = radius
set dat.anddo = true
set dat.speed = speed
set dat.damage = 0
set dat.collide = collide
set dat.uni = false
set dat.index = GetUnitIndex(dat.bullet)
set STOP[dat.index] = false
set THROWANGLE[dat.index] = angle
call TT_Start(function Throw_child,dat)
call SetUnitFlyHeight(dat.bullet, NORMHEIGHT,0)
return dat.bullet
endfunction
public function StopIt takes unit projectile returns nothing
set STOP[GetUnitIndex(projectile)] = true
endfunction
endlibrary
Have fun <3
If you have some suggestions to make it look nicer or to add new functions, just tell them please.
PS: sry for the horrible terrain