December 04, 2020, 11:49:04 AM

Author Topic: [bb] Generic Functions by K [ 1+ years ago ]  (Read 409 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Generic Functions by K [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Generic Functions
Author : K
Posted : 1+ years ago

Description : Over time, code that will be repeated I collapse into very flexible functions designed to work in various situations.
I may soon be leaving the forums for the most part, so I thought I'd make these public. Maybe some are useful to you.
Maybe some you already made...
Just giving back to the community, I hope.

ALERT: HAT func() doesn't work. will repair. Never actually used that one.


Code :
Code: BlitzBasic
  1. Function InBox(entity,x1,y1,z1,Call=0,x2=0,y2=0,z2=0)
  2. ;NOTE:  x1 and z1 must ALWAYS be smaller
  3. ;      and y1 must ALWAYS be on top.
  4. ;(The next line is for if you don't pass the _2's in.
  5. ; If you want to read these at 0, pass Call=2)
  6. If Call=1 x2=x1+15 : y2=y1+10 : z2=z1+10
  7. x = (EntityX(entity,1)<=x2)And(EntityX(entity,1)>=x1)
  8. y = (EntityY(entity,1)>=y2)And(EntityY(entity,1)<=y1)
  9. z = (EntityZ(entity,1)<=z2)And(EntityZ(entity,1)>=z1)
  10. If(x And y And z) Return True Else Return False
  11. End Function
  12.  
  13.  
  14. Function Clone(k,t,method=0)
  15. ;0=repos
  16. ;1=rot
  17. ;2=pos with collisions
  18. ;3=<void>
  19. ;4=repos and rot
  20. ;5=pos and rot with collisions
  21.  Select method
  22.  Case 0 Repos(k,EntityX(t,1),EntityY(t,1),EntityZ(t,1))
  23.  Case 1 RotateEntity k,EntityPitch(t,1),EntityYaw(t,1),EntityRoll(t,1),1
  24.  Case 2 PositionEntity k,EntityX(t,1),EntityY(t,1),EntityZ(t,1),1
  25.  Case 4 Repos(k,EntityX(t,1),EntityY(t,1),EntityZ(t,1)):RotateEntity k,EntityPitch(t,1),EntityYaw(t,1),EntityRoll(t,1),1
  26.  Case 5 PositionEntity k,EntityX(t,1),EntityY(t,1),EntityZ(t,1),1 : RotateEntity k,EntityPitch(t,1),EntityYaw(t,1),EntityRoll(t,1),1
  27.  End Select
  28. End Function
  29.  
  30.  
  31. Function Swap%(entity,Parent=-1)
  32. If Parent=-1 Parent=GetParent(entity)
  33. FreeEntity entity
  34. Return CreatePivot(Parent)
  35. End Function
  36.  
  37.  
  38. Function Repos(entity,fx#,fy#,fz#,Yaw=-500)
  39.  t=GetEntityType(entity)
  40.   EntityType entity,0
  41.    PositionEntity entity,fx,fy,fz,1
  42.   If Yaw<>-500RotateEntity entity,EntityPitch(entity,1),Yaw,EntityRoll(entity,1),1
  43.  EntityType entity,t
  44. End Function
  45.  
  46.  
  47. Function ReleaseChildren(entity)
  48. ;I give props: Kryzon just now fixed this one for
  49. ;me. Thanks Rafael!
  50. t=CountChildren(entity)
  51.  For k=1To t
  52.   EntityParent GetChild(entity,1),0
  53.  Next
  54. End Function
  55.  
  56.  
  57. Function Hat(x,y)
  58. x=x+1y=y+1
  59. a=ATan(y/x)
  60. Return a
  61. End Function
  62.  
  63.  
  64. Function divis(a#,b)
  65. ;this func tells you if a number is divisible by another
  66. If Int(a/b)<>(a/b) Return False Else Return True
  67. End Function
  68.  
  69.  
  70. ;Method param for future expansion,
  71. ;method>0 will return 0.
  72. Function Distance#(x,y,z,entity,method=0)
  73. Local a#
  74. If method=0
  75. a = Sqr((x-EntityX(entity,1))^2) +Sqr((y-EntityY(entity,1))^2)+Sqr((z-EntityZ(entity,1))^2)
  76. EndIf
  77. Return a
  78. End Function
  79.  
  80.  
  81. Function Direct(src,des,Call=0)
  82. PointEntity src,des
  83. If Call=1 Call=EntityRoll(src,0)
  84. RotateEntity src,0,EntityYaw(src,0),Call,0
  85. End Function
  86.  
  87.  
  88. Function Point(x,y,z,entity,method=0)
  89. k=CreatePivot()
  90. PositionEntity k,x,y,z
  91. If(Method=0)
  92. PointEntity entity,k
  93. ElseIf(method>0)And(method<2)
  94. Direct entity,k,method-1
  95. EndIf
  96. FreeEntity k
  97. End Function
  98.  
  99.  
  100. Function LoadMD22%(Path$,Call=0);If you use MD2s... (:P)
  101. If Call=1 k=13Else k=9
  102. tex=LoadTexture(Path$+".BMP",k)
  103. t=LoadMD2(Path$+".MD2")
  104. EntityTexture t,tex : FreeTexture tex
  105. Return t
  106. End Function
  107.  
  108. ;These use the power-of-two flags
  109. ;on whatever value you feed it.
  110. Function CheckBinFlag(k,offset=0)
  111. s=Int(Mid(Bin(k),32-offset,1))
  112. If s=1Return True Else Return False
  113. End Function
  114.  
  115. ;Note: BinFlag() funcs must be called as follows...
  116. ;
  117. ;n=Pu__BinFlag%(n,offset)
  118. ;(otherwise you will get no result).
  119. Function PushBinFlag%(k,offset=0)
  120. k=k+(1Shl offset)
  121. Return k%
  122. End Function
  123.  
  124.  
  125. Function PullBinFlag%(k,offset=0)
  126. k=k-(1Shl offset)
  127. Return k%
  128. End Function


Comments :


virtlands(Posted 1+ years ago)

 Thanks for the genericode.


Darkseid2.0(Posted 1+ years ago)

 Thanks, I'll be using most if not all of these.Great work. Keep it up.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal