• Print

Author Topic: UBowl v1.0  (Read 13054 times)

0 Members and 1 Guest are viewing this topic.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
UBowl v1.0
« on: September 12, 2006, 10:25:41 pm »
Code: Lua
  1. --[[
  2. UBowl v1.0
  3. by Brett "Megiddo" Smith
  4. Part of the Spirit of UGM collection.
  5.  
  6. This script spawns a lane of bowling pins.
  7.  
  8. Requirements:
  9. This script requires ULib version 1 or higher. You can download ULib from ulyssesmod.net
  10.  
  11. Usage:
  12. Use the command "makelane" to create a bowling lane, use "cleanlanes" to clean up previous lanes.
  13.  
  14. Changelog:
  15. v1.0 *(09/12/06)*
  16.         * Initial version.
  17. ]]
  18.  
  19. assert( _file.Exists( "lua/ULib/init.lua" ), "UBowl needs ULib to run!" )
  20. _OpenScript( "ULib/init.lua" )
  21. assert( ULib.ULIB_VERSION >= 1, "UBowl requires ULib version 1 or higher to run!" )
  22.  
  23. local pin = "models/mixerman3d/bowling/bowling_pin.mdl"
  24. local ball = "models/mixerman3d/bowling/bowling_ball.mdl"
  25. local spacing = 25
  26. local rows = 4 -- Standard pin setup has 4 rows
  27.  
  28. local ents = {}
  29.  
  30. local function cc_makeLane( userid )
  31.         ents[ userid ] = ents[ userid ] or {}
  32.         PlayerLookTrace( userid, 4096 )
  33.         if not _TraceHit() then
  34.                 ULib.tsay( userid, "Please look at where you want to spawn the lane!" )
  35.                 return
  36.         end
  37.  
  38.         local start = _TraceEndPos()
  39.  
  40.         local back = _EntGetForwardVector( userid )
  41.         local right = _EntGetRightVector( userid )
  42.  
  43.         back.z = 0 -- We don't care about the third dimension
  44.         right.z = 0
  45.  
  46.         local ang = vector3( 0, 90, 0 ) -- Used for angles
  47.  
  48.         for y=1, rows do
  49.                 local odd = (math.mod( y, 2 ) ~= 0)
  50.                 offy = vecMul( back, spacing * (y-1) )
  51.  
  52.                 for x=1, y do
  53.                         local offx
  54.                         if x == 1 and odd then -- We just go straight back
  55.                                 offx = vector3( 0, 0, 0 )
  56.                                 --ULib.print( "easy way out" )
  57.                                 --ULib.print( "x =", x, "y =", y, "offx =", offx, "offy =", offy )
  58.                         else
  59.                                 local direction = math.mod( x, 2 ) * 2 - 1 -- Go right on odd numbers, left on even, timesing by two makes it 1 or -1
  60.                                 local offnum
  61.                                 if not odd then -- We need to add one to account for the middle pin
  62.                                         offnum = x + 1 - math.mod( x + 1, 2 ) -- This rounds down to the nearest multiple of 2
  63.                                 else
  64.                                         offnum = x - math.mod( x, 2 ) -- This rounds down to the nearest multiple of 2
  65.                                 end
  66.                                 offnum = offnum / 2 -- And this gives us the number we want
  67.                                 if not odd then offnum = offnum - 0.5 end -- For those odd rows!
  68.  
  69.                                 offx = vecMul( right, spacing * offnum * direction )
  70.                                 --ULib.print( "x =", x, "y =", y, "offx =", offx, "offy =", offy )
  71.                                 --ULib.print( "odd =", odd, "direction =", direction, "offnum =", offnum )
  72.                         end
  73.  
  74.                         local pos = vecAdd( start, vecAdd( offx, offy ) )
  75.                         table.insert( ents[ userid ], ULib.makeProp( pin, pos, ang ) )
  76.                         --ULib.print( pos, "\n\n\n" )
  77.                 end
  78.         end
  79. end
  80. ULib.CONCOMMAND( "makelane", cc_makeLane )
  81.  
  82. local function cc_cleanLanes( userid )
  83.         if not ents[ userid ] then return end -- Nothing to do
  84.         for _, entid in ipairs( ents[ userid ] ) do
  85.                 if _EntExists( entid ) and (_EntGetModel( entid ) == pin or _EntGetModel( entid ) == ball) then -- No exploiting here!
  86.                         _EntRemove( entid )
  87.                 end
  88.         end
  89. end
  90. ULib.CONCOMMAND( "cleanlanes", cc_cleanLanes )

UBowl v1.0
by Brett "Megiddo" Smith
Part of the Spirit of UGM collection.

This script spawns a lane of bowling pins.

Requirements:
This script requires ULib version 1 or higher. You can download ULib from ulyssesmod.net

Usage:
Use the command "makelane" to create a bowling lane, use "cleanlanes" to clean up previous lanes.

Download from: http://ulyssesmod.net/archive/UBowl-v1_0.zip
Experiencing God's grace one day at a time.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: UBowl v1.0
« Reply #1 on: September 14, 2006, 12:57:44 pm »
Cool!

Testing now :)

  • Print