Author Topic: UBowl 2  (Read 6340 times)

0 Members and 1 Guest are viewing this topic.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
UBowl 2
« on: September 17, 2006, 12:06:04 PM »
Well here is the code bugs are lower in the post.

Code: [Select]
force = 500

assert( _file.Exists( "lua/ULib/init.lua" ), "UBowl needs ULib to run!" )
_OpenScript( "ULib/init.lua" )
assert( ULib.ULIB_VERSION >= 1, "UBowl requires ULib version 1 or higher to run!" )

red = 255
blu = 255
gre = 255
alph = 255

bowl = {}
for i = 1, _MaxPlayers() do
    bowl[i] = {}
    bowl[i].isbowl = 0 -- Dont edit
    bowl[i].frame = 0 -- Dont edit
    bowl[i].pins = 0 -- Dont edit
    bowl[i].at = 1 -- Dont edit
    bowl[i].on = 0 -- Dont edit
    bowl[i].force = force -- Dont edit it is the amount of force only edit if you have a brain.
    bowl[i].omg = 0 -- Dont edit it at all
    bowl[i].lol = 0 -- Dont edit it at all
    bowl[i].back = 0 -- Dont edit
    bowl[i].start = nil; -- Try and guess
    bowl[i].timeitself = nil; -- Try and guess
end

local pin = "models/mixerman3d/bowling/bowling_pin.mdl"
local ball = "models/mixerman3d/bowling/bowling_ball.mdl"
local spacing = 20
local rows = 4 -- Standard pin setup has 4 rows

local ents = {}

local function cc_makeLane( userid )
bowl[userid].timeitself = AddTimer(0.1,0,bowlthink,userid)
ents[ userid ] = ents[ userid ] or {}
PlayerLookTrace( userid, 4096 )
if not _TraceHit() then
ULib.tsay( userid, "Please look at where you want to spawn the lane!" )
return
end

local start = _TraceEndPos()
ULib.freezePlayer( userid )

local back = _EntGetForwardVector( userid )
local right = _EntGetRightVector( userid )

back.z = 0 -- We don't care about the third dimension
right.z = 0

local ang = vector3( 0, 90, 0 ) -- Used for angles

for y=1, rows do
local odd = (math.mod( y, 2 ) ~= 0)
offy = vecMul( back, spacing * (y-1) )

for x=1, y do
local offx
if x == 1 and odd then -- We just go straight back
offx = vector3( 0, 0, 0 )
ULib.print( "easy way out" )
ULib.print( "x =", x, "y =", y, "offx =", offx, "offy =", offy )
else
local direction = math.mod( x, 2 ) * 2 - 1 -- Go right on odd numbers, left on even, timesing by two makes it 1 or -1
local offnum
if not odd then -- We need to add one to account for the middle pin
offnum = x + 1 - math.mod( x + 1, 2 ) -- This rounds down to the nearest multiple of 2
else
offnum = x - math.mod( x, 2 ) -- This rounds down to the nearest multiple of 2
end
offnum = offnum / 2 -- And this gives us the number we want
if not odd then offnum = offnum - 0.5 end -- For those odd rows!

offx = vecMul( right, spacing * offnum * direction )
ULib.print( "x =", x, "y =", y, "offx =", offx, "offy =", offy )
ULib.print( "odd =", odd, "direction =", direction, "offnum =", offnum )
end

local pos = vecAdd( start, vecAdd( offx, offy ) )
table.insert( ents[ userid ], ULib.makeProp( pin, pos, ang ) )
ULib.print( pos, "\n\n\n" )
bowl[userid].isbowl = 1

_GModRect_Start( "gmod/white" );
_GModRect_SetPos( 0.02, 0.26, 0.18, 0.02 );
_GModRect_SetColor( 120, 120, 120, 200 );
_GModRect_SetTime( 99999, 0, 0 );
_GModRect_SetDelay( 0 );
_GModRect_Send( userid, 21 );

_GModRect_Start( "gmod/white" );
_GModRect_SetPos( 0.01, 0.025, 0.2, 0.27 );
_GModRect_SetColor( 20, 20, 20, 200 );
_GModRect_SetTime( 99999, 0, 0 );
_GModRect_SetDelay( 0 );
_GModRect_Send( userid, 20 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.03 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "Name: " );
_GModText_Send( userid, 1 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.1, 0.03 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( _PlayerInfo(userid,"name") );
_GModText_Send( userid, 2 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.06 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "Frame: " );
_GModText_Send( userid, 3 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.1, 0.06 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "WTF" );
_GModText_Send( userid, 4 );


_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.09 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "Pins Out" );
_GModText_Send( userid, 5 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.1, 0.09 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "WTF" );
_GModText_Send( userid, 10 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.12 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "Pins Left" );
_GModText_Send( userid, 7 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.1, 0.12 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "WTF" );
_GModText_Send( userid, 8 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.15 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "Level at:" );
_GModText_Send( userid, 9 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.1, 0.15 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( "By: Terminal58" );
_GModText_Send( userid, 11 );

bowl[userid].lol = math.floor(bowl[userid].force * 2)
end
end
end
ULib.CONCOMMAND( "makelane", cc_makeLane )

function bowlingguithink(userid)

local pLen = math.abs(100/500*bowl[userid].at);
local aLen = math.abs(0.16*(pLen/100));
local rColor = math.floor(255 - (255*(pLen/100)));
local gColor = math.floor(255*(pLen/100));
local bColor = 0
local aColor = 255

_GModRect_Start( "gmod/white" );
_GModRect_SetPos( 0.03, 0.265, aLen, 0.01 );
_GModRect_SetColor( rColor, gColor, bColor, aColor );
_GModRect_SetTime( 99999, 0, 0 );
_GModRect_SetDelay( 0 );
_GModRect_Send( userid, 22 );

_GModText_Start( "ChatFont" );
_GModText_SetPos( 0.02, 0.18 );
_GModText_SetColor( red, gre, blu, alph );
_GModText_SetTime( 99999, 0, 0 );
    _GModText_SetText( bowl[userid].at );
_GModText_Send( userid, 12 );

end

function bowlthink(userid)
if bowl[userid].isbowl == 1 then
if bowl[userid].back == 0 then
bowl[userid].at = bowl[userid].at + 8
bowlingguithink(userid)
else
if bowl[userid].back == 1 then
bowl[userid].at = bowl[userid].at - 8
bowlingguithink(userid)
end
if bowl[userid].isbowl == 1 then
raisingthebar(userid)
end
end
end
end

function raisingthebar(userid)
if bowl[userid].at >= bowl[userid].force then
bowl[userid].back = 1
bowl[userid].at = bowl[userid].at - 8
bowlingguithink(userid)
ULib.print( "Back it up" )
else
if 0 >= bowl[userid].at then
undo(userid)
ULib.print( "A little bit ahead." )
end
end
end

function undo(userid)
if bowl[userid].isbowl == 1 then
    _GModRect_Hide(userid,21);
    _GModRect_Hide(userid,20);
    _GModText_Hide(userid,1);
    _GModText_Hide(userid,2);
    _GModText_Hide(userid,3);
    _GModText_Hide(userid,4);
    _GModText_Hide(userid,5);
    _GModText_Hide(userid,10);
    _GModText_Hide(userid,7);
    _GModText_Hide(userid,8);
    _GModText_Hide(userid,9);
    _GModText_Hide(userid,11);
    _GModText_Hide(userid,22);
    _GModText_Hide(userid,12);

    bowl[userid].isbowl = 0 -- Dont edit
    bowl[userid].frame = 0 -- Dont edit
    bowl[userid].pins = 0 -- Dont edit
    bowl[userid].at = 0 -- Dont edit
    bowl[userid].on = 0 -- Dont edit
    bowl[userid].force = force -- Dont edit it is the amount of force only edit if you have a brain.
    bowl[userid].omg = 0 -- Dont edit it at all
    bowl[userid].lol = 0 -- Dont edit it at all
    bowl[userid].back = 0 -- Dont edit
    bowl[userid].start = nil; -- Try and guess
HaltTimer(bowl[userid].timeitself)
ULib.unfreezePlayer( userid ) -- Unfreeze
if not ents[ userid ] then return end -- Nothing to do
for _, entid in ipairs( ents[ userid ] ) do
if _EntExists( entid ) and (_EntGetModel( entid ) == pin or _EntGetModel( entid ) == ball) then -- No exploiting here!
_EntRemove( entid )
end
end
end
end

ULib.CONCOMMAND( "undobowl", undo )

The problems I'm having are that half the time I start it it doesn't add or subtract the other half it doesn't go back also this isn't done yet I still have to add force and press space to  stop is easy so don't worry about anything else. Also that GUI is from my other PBN project.

Edit
Cleaned it a little. EDIT 2 Cleaned it a lil more.
« Last Edit: September 24, 2006, 07:18:49 PM by Terminal58 »

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: UBowl 2
« Reply #1 on: September 17, 2006, 03:09:31 PM »
Hey, good to see that you're taking UBowl and making it into something larger! Any chance you could change the name to something else, though?

I'll see if I can figure out your problem when I have some free time tomorrow. :P
Experiencing God's grace one day at a time.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: UBowl 2
« Reply #2 on: September 17, 2006, 05:06:07 PM »
UBowl Controlled good?

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: UBowl 2
« Reply #3 on: September 17, 2006, 06:04:12 PM »
Terminal,

 Using Ubowl in the name might not be a good idea, as Megiddo originally wrote it
Ubowl 2 is misleading, as you didn't have/get permission to make a sequel.

I'm pretty sure he's not upset you wanted to make it bigger and better.

It would just be nice if you used a different name,  and gave credit to Ubowl/Megiddo for whatever code is shared between your enhanced version and his in a code comment.

I personally thought he had released a new version when I saw the topic title.
Perhaps "Bowling Alley (based on UBowl)"?

Fun you've actually worked on enhancing it. I'm considering trying to make a contraption that returns the bowling ball, much like in a real bowling alley. Not lua of course, but would be fun.

"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: UBowl 2
« Reply #4 on: September 23, 2006, 11:08:49 AM »
I did UBowl so everyone knew t hat Mediggo did it. Also it's pretty obvious that Mediggo originally did it on these forums.

Also um anyone have any ideas?

Erg Im gonna continue even with this bugs maybe clean the code a lil.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: UBowl 2
« Reply #5 on: September 23, 2006, 11:29:16 AM »
You could uncomment those ULib.print() lines, that's what I was using to debug it when I couldn't get it working :P
Experiencing God's grace one day at a time.

Offline Terminal58

  • Newbie
  • *
  • Posts: 41
  • Karma: 1
Re: UBowl 2
« Reply #6 on: September 24, 2006, 07:07:57 PM »
That isn't the issue the issue is that it isn't going back.

EDIT

I tried the printing thing to see if it attempts to back it and no.
« Last Edit: September 24, 2006, 07:19:41 PM by Terminal58 »