Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Knockback Engine for Pool

Events


Time - Every 0.02 seconds of game time

Conditions

Actions


Set TempInteger1 = (TempInteger1 + 1)


Blah blah blah, my trigger


Set TempPoint1 = (Position of Cue)


Set TempInteger2 = (TempInteger2 + 1)


Floating Text - Create floating text that reads (String((TempInteger1 - TempInteger2))) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency


Floating Text - Change (Last created floating text): Disable permanence


Floating Text - Change the lifespan of (Last created floating text) to 0.10 seconds


Custom script: call RemoveLocation(udg_TempPoint1)
Show the full triggers please.
Knockback Engine for Pool Copy

Events


Time - Every 0.02 seconds of game time

Conditions

Actions


-------- At first every unit being knockbacked is picked --------


Unit Group - Pick every unit in UnitsBeingKnockbacked and do (Actions)



Loop - Actions




-------- This is used to lower the bounce delay (the time until the unit can be bounced by another unit) --------




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






(Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) Greater than 0





Then - Actions






Hashtable - Save ((Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) - 1) as BounceDelay_Hashtable of (Key (Picked unit)) in Properties





Else - Actions




-------- End of bounc deley decraesement --------




-------- --------




-------- Now the length of the next move is loaded and the point to which the unit should move is determinated --------




Set NewCurrentLenghtOfJump = (2.00 x (Square root(((2.00 x (Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties)) / (Load Mass_Hashtable of (Key (Picked unit)) from Properties)))))




Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)




-------- If the move should be less than 0.1 long, the knockback of the unit is terminated --------




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






NewCurrentLenghtOfJump Greater than 0.05





Then - Actions






-------- If the jump is longer than 0.05, now it is the time to check for collisions --------






-------- The first unit is saved, as a new unit is about to be picked --------






Set FirstUnit = (Picked unit)






Set FirstUnitHandle = (Picked unit)






-------- I had to determine somehow which units should be taken into consideration, so these are all units in 400 distance from the point of the unit, whose knockback is being calculated --------






Set TempGroup2 = (Units within 400.00 of NextPosition)






-------- The range should egual to at least two times the largest unit collision size --------






Unit Group - Pick every unit in TempGroup2 and do (Actions)







Loop - Actions








-------- IMPORTANT!!! Now a new unit is picked. So lets call the firstly pickedunit the first unit and the newly picked unit the second unit --------








Set TempPoint1 = (Position of (Picked unit))








-------- Now it is checked, whether the unit fulfils some conditions. The long one isto compare the unit custom collision size, otherwise the conditions are selfexplenatory --------








If (All Conditions are True) then do (Then Actions) else do (Else Actions)









If - Conditions










(Distance between TempPoint1 and NextPosition) Less than or equal to ((Load CollisionSize_Hashtable of (Key (Picked unit)) from Properties) + ((Load CollisionSize_Hashtable of (Key FirstUnitHandle) from Properties) + 0.00))










(Picked unit) Not equal to FirstUnit










(Unit-type of (Picked unit)) Equal to Ball









Then - Actions










-------- Something for Pool (THE PART NOT WORKING) --------










-------- This should set the boolean AlreadyHitAUnit to true always when the White Ball collides with another ball --------










-------- The problem is that sometimes it simply doesnt work, although the White ball has surly bounced --------










If (All Conditions are True) then do (Then Actions) else do (Else Actions)











If - Conditions












AlreadyHitAUnit Equal to False












Or - Any (Conditions) are true













Conditions














FirstUnit Equal to WhiteBall














(Picked unit) Equal to WhiteBall











Then - Actions












Set AlreadyHitAUnit = True











Else - Actions










For each (Integer A) from 1 to 7, do (Actions)











Loop - Actions












If (All Conditions are True) then do (Then Actions) else do (Else Actions)













If - Conditions














AlreadyHitAUnit Equal to False














FirstUnit Equal to WhiteBall














(Owner of Cue) Not equal to (Owner of (Picked unit))














Or - Any (Conditions) are true















Conditions
















(Picked unit) Equal to BlueBall[(Integer A)]
















(Picked unit) Equal to RedBall[(Integer A)]













Then - Actions














Set NumberOfRemainigStrikes = 2














If (All Conditions are True) then do (Then Actions) else do (Else Actions)















If - Conditions
















(Owner of Cue) Equal to Player 1 (Red)















Then - Actions
















Set NextPlayer = Player 2 (Blue)















Else - Actions
















Set NextPlayer = Player 1 (Red)














Floating Text - Create floating text that reads (Foul!!! Opponents ball was hit first. + ((Name of (Owner of Cue)) + plays two times)) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency














Floating Text - Change (Last created floating text): Disable permanence














Floating Text - Change the lifespan of (Last created floating text) to 2.00 seconds














Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds













Else - Actions










-------- The end of the Pool part --------










-------- Now, if the second unit cannot be knockbacked, the first unit will simply bounce off and no energy will be exchanged --------










-------- IMPORTANT!!! Imagine that the energy is a vector with lenght of current energy, direction of the angle of knockback and position of the position of the unit --------










-------- But if both first unit and second unit can be knockbacked, there will surely be some energy exchange --------










If (All Conditions are True) then do (Then Actions) else do (Else Actions)











If - Conditions












((Picked unit) is in UnitsBeingKnockbacked) Equal to True











Then - Actions












-------- If the second unit is also being knockbacked, it is checked whether the second unit hasn't bounced recently --------












If (All Conditions are True) then do (Then Actions) else do (Else Actions)













If - Conditions














(Load BounceDelay_Hashtable of (Key (Picked unit)) from Properties) Less than or equal to 0













Then - Actions














-------- If the second unit hasn't bounced recently, the angle of the collision (from first to second unit) is compared with the angle of knockback of the first unit --------














If (All Conditions are True) then do (Then Actions) else do (Else Actions)















If - Conditions
















(Abs(((Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))) Greater than or equal to 90.00















Then - Actions
















-------- If the absolute value of the of angles diffrence is lower than 90, both units will exchange part of their knockback --------
















-------- Now lets divide knockback of both units into two parts, One paralell to the direction from the first to the second unit, one tangent to this direction. --------
















-------- Both units will now exchange their part of the knockback paralell to the direction from the first one to the second one. --------
















Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))))))
















Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))
















Set KnockbackTarget = (Picked unit)
















Trigger - Run Adding New Knockback <gen> (checking conditions)
















Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
















Set KnockbackTarget = FirstUnit
















Trigger - Run Adding New Knockback <gen> (checking conditions)
















Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) - (Angle from (Position of (Picked unit)) to (Position of FirstUnit))))))))
















Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
















Set KnockbackTarget = FirstUnit
















Trigger - Run Adding New Knockback <gen> (checking conditions)
















Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
















Set KnockbackTarget = (Picked unit)
















Trigger - Run Adding New Knockback <gen> (checking conditions)
















-------- And to protect the system from one bug, some bouncing delay is saved to both of the units --------
















Hashtable - Save BasicBounceDelay as BounceDelay_Hashtable of (Key FirstUnitHandle) in Properties
















Hashtable - Save BasicBounceDelay as BounceDelay_Hashtable of (Key (Picked unit)) in Properties
















Custom script: call RemoveLocation(udg_TempPoint1)
















Custom script: call RemoveLocation(udg_TempPoint2)















Else - Actions
















-------- If the angle diffrence is bigger, it means the second unit was hit "from behind" (compared to the angle of knockback of the second unit) --------
















-------- And so the first unit will give the second unit part of its knockback, but the scond unit won't give anything to the first one --------
















Set KnockbackBeingAdded = ((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin((Abs(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (Angle from (Position of FirstUnit) to (Position of (Picked unit)))))))))
















Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))
















Set KnockbackTarget = (Picked unit)
















Trigger - Run Adding New Knockback <gen> (checking conditions)
















Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)
















Set KnockbackTarget = FirstUnit
















Trigger - Run Adding New Knockback <gen> (checking conditions)













Else - Actions














-------- If the second unit has bounced recently, it will behave as if it was unable to bounce. --------














Set AngleOfKnockbackBeingAdded = (180.00 + ((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) - (2.00 x (Angle from (Position of FirstUnit) to (Position of (Picked unit))))))














Hashtable - Save AngleOfKnockbackBeingAdded as AngelOfKnockback_Hashtable of (Key FirstUnitHandle) in Properties











Else - Actions












-------- If the second unit wasn't knockbacked, it will get the paralell (paralell to the direction from the first to the second unit) part of the first units knockback --------












Set AngleOfKnockbackBeingAdded = (Angle from (Position of FirstUnit) to (Position of (Picked unit)))












Set KnockbackBeingAdded = (Abs(((Load CurrentEnergy_Hashtable of (Key FirstUnitHandle) from Properties) x (Sin(((Load AngelOfKnockback_Hashtable of (Key FirstUnitHandle) from Properties) + (90.00 - AngleOfKnockbackBeingAdded)))))))












Set KnockbackSource = (Position of FirstUnit)












Set KnockbackTarget = (Picked unit)












Trigger - Run Adding New Knockback <gen> (checking conditions)












Set AngleOfKnockbackBeingAdded = (AngleOfKnockbackBeingAdded + 180.00)












Set KnockbackTarget = FirstUnit












Trigger - Run Adding New Knockback <gen> (checking conditions)









Else - Actions






-------- Now, after the bouncing calculations, the new position is counted once more, coz it might have changed --------






Set NewCurrentLenghtOfJump = (2.00 x (Square root(((2.00 x (Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties)) / (Load Mass_Hashtable of (Key (Picked unit)) from Properties)))))






Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)






-------- Now the hindering trees are destroyed --------






Destructible - Pick every destructible within TreeDestroyingRange of NextPosition and do (Actions)







Loop - Actions








Destructible - Kill (Picked destructible)






-------- And the unit is finally moved to the new position. Hurray!!! --------






Set NextPositionX = (X of NextPosition)






Set NextPositionY = (Y of NextPosition)






Custom script: call SetUnitX(GetEnumUnit() , udg_NextPositionX)






Custom script: call SetUnitY(GetEnumUnit() , udg_NextPositionY)






-------- And the last step, some value is subtracted from the units knockback, the value depend on many factors, such as the units mass, friction and so on --------






Hashtable - Save ((Load CurrentEnergy_Hashtable of (Key (Picked unit)) from Properties) - ((Load Mass_Hashtable of (Key (Picked unit)) from Properties) x ((Load Friction_Hashtable of (Key (Picked unit)) from Properties) x NewCurrentLenghtOfJump))) as CurrentEnergy_Hashtable of (Key (Picked unit)) in Properties





Else - Actions






-------- If the jump lenght should be less than 0.05, via theese lines the kockback is terminated --------






Unit Group - Remove (Picked unit) from UnitsBeingKnockbacked






Unit - Turn collision for (Picked unit) On
Cue Changing

Events


Time - NextStrikeTimer expires

Conditions

Actions


Set TempGroup1 = (Units in (Playable map area) matching ((Unit-type of (Matching unit)) Equal to Ball))


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




(Number of units in TempGroup1) Less than 16




AlreadyHitAUnit Equal to False



Then - Actions




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






(Owner of Cue) Equal to Player 1 (Red)





Then - Actions






Set NextPlayer = Player 2 (Blue)





Else - Actions






Set NextPlayer = Player 1 (Red)




Set TempPoint1 = (Position of WhiteBall)




Floating Text - Create floating text that reads (Foul!!! No ball was hit. + ((Name of NextPlayer) + plays two times)) at TempPoint1 with Z offset 120.00, using font size 10.00, color (100.00%, 0.00%, 0.00%), and 0.00% transparency




Floating Text - Change (Last created floating text): Disable permanence




Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds




Floating Text - Change the fading age of (Last created floating text) to 1.00 seconds




Custom script: call RemoveLocation(udg_TempPoint1)




Set NumberOfRemainigStrikes = 2



Else - Actions




If (All Conditions are True) then do (Then Actions) else do (Else Actions)





If - Conditions






NumberOfRemainigStrikes Equal to 0





Then - Actions






If (All Conditions are True) then do (Then Actions) else do (Else Actions)







If - Conditions








(Owner of Cue) Equal to Player 1 (Red)







Then - Actions








Set NextPlayer = Player 2 (Blue)







Else - Actions








Set NextPlayer = Player 1 (Red)






Set NumberOfRemainigStrikes = 1





Else - Actions


Custom script: call DestroyGroup(udg_TempGroup1)


Unit - Change ownership of Cue to NextPlayer and Change color


Set AlreadyHitAUnit = False


If (All Conditions are True) then do (Then Actions) else do (Else Actions)



If - Conditions




CanPlaceWhiteBall Equal to True



Then - Actions




Unit - Add White Ball Placing to Cue



Else - Actions
FirstUnit Equal to WhiteBall
(Picked unit) Equal to WhiteBall
, especially). It's also slower in term of operation.
I would use KB3D or KB2D by Jad and Bribe respectively.
It's much simpler and should cease the issue quickly.
Is it necessary?
FirstUnit Equal to WhiteBall
(Picked unit) Equal to WhiteBall
Integer A/B can collide in some occasion (if it's used in multiple thread
, especially). It's also slower in term of operation.[/QUOTE]
Should I use "for each my variable" instaed of the "for each integer A"?
Should I use "for each my variable" instaed of the "for each integer A"?
Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
You also have a ton of leaks.
This leaks a location
This leaks two locations.
Set NextPosition = ((Position of (Picked unit)) offset by NewCurrentLenghtOfJump towards (Load AngelOfKnockback_Hashtable of (Key (Picked unit)) from Properties) degrees)
You also leak unit groups.
Set AngleOfKnockbackBeingAdded = (Angle from (Position of (Picked unit)) to (Position of FirstUnit))
)
