pastebin
| #1 paste tool since 2002
create new paste
tools
api
archive
real-time
faq
pastebin
Follow @pastebin
create new paste
trending pastes
sign up
login
my settings
my profile
My Pastes
Public Pastes
Untitled
1 sec ago
theme38_por_thoughtandsoul
13 sec ago
Girlwriteswhat
16 sec ago
Untitled
13 sec ago
Untitled
14 sec ago
Untitled
21 sec ago
Untitled
21 sec ago
Untitled
24 sec ago
Layout Width
Share Pastebin
Energy
By: a guest | Mar 21st, 2010 | Syntax:
Lua
| Size: 5.21 KB | Hits: 48 | Expires: Never
Download
|
Raw
|
Embed
|
Report abuse
include
(
'shared.lua'
)
function
_R.Vector:IsInRange
(
v1, v2
)
return
self.x
>=
v1.x
and
self.x
<=
v2.x
and
self.y
>=
v1.y
and
self.y
<=
v2.y
and
self.z
>=
v1.z
and
self.z
<=
v2.z
;
-- Thanks MakeR
end
Buttons
=
{
}
Ytempz
=
{
}
ClickCol
=
Color
(
255
,
200
,
100
,
255
)
MouseOverCol
=
Color
(
0
,
255
,
0
,
255
)
Moade
=
"MainMenu"
CanClick
=
true
ClickTime
=
1
function
AddButton
(
x,y,w,h,txtcol,backcol,txt,font,id
)
Temp
=
{
}
Temp
[
"Pos"
]
=
{
}
Temp
[
"Pos"
]
[
"x"
]
=
x
Temp
[
"Pos"
]
[
"y"
]
=
y
Temp
[
"Size"
]
=
{
}
Temp
[
"Size"
]
[
"w"
]
=
w
Temp
[
"Size"
]
[
"h"
]
=
h
Temp
[
"TextColor"
]
=
txtcol
Temp
[
"BackColor"
]
=
backcol
Temp
[
"Text"
]
=
txt
Temp
[
"Font"
]
=
font
Buttons
[
id
]
=
Temp
Ytempz
[
id
]
=
Temp
Temp
=
{
}
end
//
AddButton
(
-
(
275
/
2
)
+
60
,-
(
200
/
2
)
+
30
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Test Button."
,
"TabLarge"
)
//
AddButton
(
-
(
275
/
2
)
+
10
,-
(
200
/
2
)
+
60
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Test Button2"
,
"TabLarge"
)
AddButton
(
-
(
275
/
2
)
+
60
,
90
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Sub-Menu"
,
"TabLarge"
,
9001
)
--[[
AddButton(-(275/2)+150,30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.x: "..Inter.x,"TabLarge",10)
AddButton(-(275/2)+150,50,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.y: "..Inter.y,"TabLarge",11)
AddButton(-(275/2)+150,70,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.x: "..A.x,"TabLarge",12)
AddButton(-(275/2)+150,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.y: "..A.y,"TabLarge",13)
AddButton(-(275/2)+150,110,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.x: "..B.x,"TabLarge",14)
AddButton(-(275/2)+150,130,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.y: "..B.y,"TabLarge",15)
]]
--
TitleText
=
"Welcome to my humble little menu system."
function
ENT:Draw
(
)
cam.Start3D2D
(
self.Entity:GetPos
(
)
, self.Entity:GetForward
(
)
,
1
)
surface.SetDrawColor
(
0
,
0
,
0
,
255
)
--Red
surface.DrawRect
(
-
(
275
/
2
)
,
0
,
275
,
200
)
surface.SetDrawColor
(
100
,
200
,
255
,
255
)
surface.DrawRect
(
-
(
275
/
2
)
,
0
,
275
,
20
)
surface.SetTextColor
(
0
,
255
,
0
,
255
)
surface.SetTextPos
(
-
(
275
/
2
)
+
5
,
0
)
surface.SetFont
(
"TabLarge"
)
surface.DrawText
(
TitleText
)
for
k,v
in
pairs
(
Buttons
)
do
surface.SetDrawColor
(
v
[
"BackColor"
]
.r,v
[
"BackColor"
]
.g,v
[
"BackColor"
]
.b,v
[
"BackColor"
]
.a
)
surface.DrawRect
(
v
[
"Pos"
]
[
"x"
]
,v
[
"Pos"
]
[
"y"
]
,v
[
"Size"
]
[
"w"
]
,v
[
"Size"
]
[
"h"
]
)
surface.SetTextColor
(
v
[
"TextColor"
]
.r,v
[
"TextColor"
]
.g,v
[
"TextColor"
]
.b,v
[
"TextColor"
]
.a
)
surface.SetTextPos
(
v
[
"Pos"
]
[
"x"
]
+
5
,v
[
"Pos"
]
[
"y"
]
+
3.5
)
surface.SetFont
(
v
[
"Font"
]
)
surface.DrawText
(
v
[
"Text"
]
)
end
PlanePos
=
self.Entity:GetPos
(
)
Normal
=
self.Entity:GetUp
(
)
ShootPos
=
LocalPlayer
(
)
:EyePos
(
)
Eye
=
LocalPlayer
(
)
:GetEyeTraceNoCursor
(
)
.Normal
Inter
=
ShootPos-
(
Normal:DotProduct
(
ShootPos-PlanePos
)
)
/
(
Normal:DotProduct
(
Eye
)
)
*
Eye
--:3 Lutin thanks a bunch for this part
Inter
=
self.Entity:WorldToLocal
(
Inter
)
Inter.x
=
math
.Clamp
(
Inter.x, -
(
275
/
2
)
,
(
275
/
2
)
)
Inter.y
=
math
.Clamp
(
Inter.y, -200,0
)
surface.SetDrawColor
(
152,251,152,255
)
surface.DrawRect
(
Inter.x-1,-Inter.y-1,2,2
)
for
k,v
in
pairs
(
Buttons
)
do
local
A
=
(
Vector
(
v
[
"Pos"
]
[
"x"
]
,v
[
"Pos"
]
[
"y"
]
,
0
)
+
(
Vector
(
v
[
"Size"
]
[
"w"
]
,v
[
"Size"
]
[
"h"
]
,0
)
)
)
A.x
=
A.x-2
A.y
=
A.y-2
local
B
=
Vector
(
v
[
"Pos"
]
[
"x"
]
,v
[
"Pos"
]
[
"y"
]
,0
)
print
(
"Button Text: "
..v
[
"Text"
]
..
" A: "
..
tostring
(
A
)
..
" B: "
..
tostring
(
B
)
..
" Inter: "
..
tostring
(
Inter
)
)
--surface.SetDrawColor(152,251,152,255)
surface.SetDrawColor
(
255,0,0,255
)
surface.DrawRect
(
A.x,A.y,2,2
)
surface.SetDrawColor
(
0,255,0,255
)
surface.DrawRect
(
B.x,B.y,2,2
)
InterSub
=
Inter
InterSub.y
=
-InterSub.y
if
(
InterSub:IsInRange
(
B,A
)
)
then
if
(
LocalPlayer
(
)
:KeyDown
(
IN_ATTACK
)
)
then
v
[
"BackColor"
]
=
ClickCol
Clicked
(
k
)
else
v
[
"BackColor"
]
=
MouseOverCol
end
else
v
[
"BackColor"
]
=
Color
(
0,0,255,255
)
end
end
cam.End3D2D
(
)
end
function
ClearButtons
(
)
Buttons
=
{
}
Ytempz
=
{
}
end
function
Clicked
(
Id
)
if
(
CanClick
)
then
CanClick
=
false
timer.Create
(
"ClickAllow"
,ClickTime,1,
function
(
)
CanClick
=
true
end
)
if
(
Id
==
9001
and
Moade
==
"MainMenu"
)
then
Moade
=
"SubMenu"
ClearButtons
(
)
AddButton
(
-
(
275
/
2
)
+
60
,
90
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Back"
,
"TabLarge"
,
9000
)
AddButton
(
-
(
275
/
2
)
+
10
,
30
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Action 1"
,
"TabLarge"
,
1
)
AddButton
(
-
(
275
/
2
)
+
10
,
150
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Action 2"
,
"TabLarge"
,2
)
end
if
(
Id
==
9000
and
Moade
==
"SubMenu"
)
then
ClearButtons
(
)
Moade
=
"MainMenu"
AddButton
(
-
(
275
/
2
)
+
60
,
90
,
100
,
20
,Color
(
255
,
0
,
0
,
255
)
,Color
(
0
,
0
,
255
,
255
)
,
"Sub-Menu"
,
"TabLarge"
,
9001
)
--[[
AddButton(-(275/2)+150,30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.x: "..Inter.x,"TabLarge",10)
AddButton(-(275/2)+150,50,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.y: "..Inter.y,"TabLarge",11)
AddButton(-(275/2)+150,70,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.x: "..A.x,"TabLarge",12)
AddButton(-(275/2)+150,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.y: "..A.y,"TabLarge",13)
AddButton(-(275/2)+150,110,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.x: "..B.x,"TabLarge",14)
AddButton(-(275/2)+150,130,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.y: "..B.y,"TabLarge",15)
]]
--
end
end
end
create new paste
|
create new version of this paste
RAW Paste Data
include('shared.lua') function _R.Vector:IsInRange(v1, v2) return self.x >= v1.x and self.x <= v2.x and self.y >= v1.y and self.y <= v2.y and self.z >= v1.z and self.z <= v2.z; -- Thanks MakeR end Buttons = {} Ytempz = {} ClickCol = Color(255,200,100,255) MouseOverCol = Color(0,255,0,255) Moade = "MainMenu" CanClick = true ClickTime = 1 function AddButton(x,y,w,h,txtcol,backcol,txt,font,id) Temp = {} Temp["Pos"] = {} Temp["Pos"]["x"] = x Temp["Pos"]["y"] = y Temp["Size"] = {} Temp["Size"]["w"] = w Temp["Size"]["h"] = h Temp["TextColor"] = txtcol Temp["BackColor"] = backcol Temp["Text"] = txt Temp["Font"] = font Buttons[id] = Temp Ytempz[id] = Temp Temp = {} end //AddButton(-(275/2)+60,-(200/2)+30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Test Button.","TabLarge") //AddButton(-(275/2)+10,-(200/2)+60,100,20,Color(255,0,0,255),Color(0,0,255,255),"Test Button2","TabLarge") AddButton(-(275/2)+60,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"Sub-Menu","TabLarge",9001) --[[ AddButton(-(275/2)+150,30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.x: "..Inter.x,"TabLarge",10) AddButton(-(275/2)+150,50,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.y: "..Inter.y,"TabLarge",11) AddButton(-(275/2)+150,70,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.x: "..A.x,"TabLarge",12) AddButton(-(275/2)+150,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.y: "..A.y,"TabLarge",13) AddButton(-(275/2)+150,110,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.x: "..B.x,"TabLarge",14) AddButton(-(275/2)+150,130,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.y: "..B.y,"TabLarge",15) ]]-- TitleText = "Welcome to my humble little menu system." function ENT:Draw() cam.Start3D2D(self.Entity:GetPos(), self.Entity:GetForward(),1) surface.SetDrawColor( 0, 0, 0, 255) --Red surface.DrawRect(-(275/2),0, 275, 200 ) surface.SetDrawColor( 100,200,255,255) surface.DrawRect(-(275/2),0,275,20) surface.SetTextColor(0,255,0,255) surface.SetTextPos(-(275/2)+5,0) surface.SetFont("TabLarge") surface.DrawText(TitleText) for k,v in pairs(Buttons) do surface.SetDrawColor(v["BackColor"].r,v["BackColor"].g,v["BackColor"].b,v["BackColor"].a) surface.DrawRect(v["Pos"]["x"],v["Pos"]["y"],v["Size"]["w"],v["Size"]["h"]) surface.SetTextColor(v["TextColor"].r,v["TextColor"].g,v["TextColor"].b,v["TextColor"].a) surface.SetTextPos(v["Pos"]["x"]+5,v["Pos"]["y"]+3.5) surface.SetFont(v["Font"]) surface.DrawText(v["Text"]) end PlanePos = self.Entity:GetPos() Normal = self.Entity:GetUp() ShootPos = LocalPlayer():EyePos() Eye = LocalPlayer():GetEyeTraceNoCursor().Normal Inter = ShootPos-(Normal:DotProduct(ShootPos-PlanePos))/(Normal:DotProduct(Eye))*Eye --:3 Lutin thanks a bunch for this part Inter = self.Entity:WorldToLocal(Inter) Inter.x = math.Clamp(Inter.x, -(275/2),(275/2)) Inter.y = math.Clamp(Inter.y, -200,0) surface.SetDrawColor(152,251,152,255) surface.DrawRect(Inter.x-1,-Inter.y-1,2,2) for k,v in pairs(Buttons) do local A = (Vector(v["Pos"]["x"],v["Pos"]["y"],0)+(Vector(v["Size"]["w"],v["Size"]["h"],0))) A.x = A.x-2 A.y = A.y-2 local B = Vector(v["Pos"]["x"],v["Pos"]["y"],0) print("Button Text: "..v["Text"].." A: "..tostring(A).." B: "..tostring(B).." Inter: "..tostring(Inter)) --surface.SetDrawColor(152,251,152,255) surface.SetDrawColor(255,0,0,255) surface.DrawRect(A.x,A.y,2,2) surface.SetDrawColor(0,255,0,255) surface.DrawRect(B.x,B.y,2,2) InterSub = Inter InterSub.y = -InterSub.y if(InterSub:IsInRange(B,A)) then if(LocalPlayer():KeyDown( IN_ATTACK )) then v["BackColor"] = ClickCol Clicked(k) else v["BackColor"] = MouseOverCol end else v["BackColor"] = Color(0,0,255,255) end end cam.End3D2D() end function ClearButtons() Buttons = {} Ytempz = {} end function Clicked(Id) if(CanClick) then CanClick = false timer.Create("ClickAllow",ClickTime,1,function() CanClick = true end) if(Id == 9001 and Moade == "MainMenu") then Moade = "SubMenu" ClearButtons() AddButton(-(275/2)+60,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"Back","TabLarge",9000) AddButton(-(275/2)+10,30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Action 1","TabLarge",1) AddButton(-(275/2)+10,150,100,20,Color(255,0,0,255),Color(0,0,255,255),"Action 2","TabLarge",2) end if(Id == 9000 and Moade == "SubMenu") then ClearButtons() Moade = "MainMenu" AddButton(-(275/2)+60,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"Sub-Menu","TabLarge",9001) --[[ AddButton(-(275/2)+150,30,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.x: "..Inter.x,"TabLarge",10) AddButton(-(275/2)+150,50,100,20,Color(255,0,0,255),Color(0,0,255,255),"Inter.y: "..Inter.y,"TabLarge",11) AddButton(-(275/2)+150,70,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.x: "..A.x,"TabLarge",12) AddButton(-(275/2)+150,90,100,20,Color(255,0,0,255),Color(0,0,255,255),"A.y: "..A.y,"TabLarge",13) AddButton(-(275/2)+150,110,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.x: "..B.x,"TabLarge",14) AddButton(-(275/2)+150,130,100,20,Color(255,0,0,255),Color(0,0,255,255),"B.y: "..B.y,"TabLarge",15) ]]-- end end end