Hello,
I have a little problem..
Can you help me with my entity ?
I build a Casino Server with tetris, slots, spinwheel.
Everything work for the tetris except the color of is always grey
To the guy who solve my problem, i will send you a [b]CS GO Case Key[/b]
Thanks you for your help.
[b]cl_init[/b]
[LUA]
local TETRISCOLORS = {
Color(255,255,255,255),
Color(0,255,255,255),
Color(255,0,255,255),
Color(255,255,0,255),
Color(255,0,0,255),
Color(0,0,255,255),
Color(0,255,0,255),
Color(50,50,50,50)
}
local function DrawBoard( self )
self.Entity:DrawModel()
local EntPos = self.Entity:GetPos()
local EyeForward = self.Entity:EyeAngles():Forward()
local ang = self.Entity:GetAngles()
ang:RotateAroundAxis(ang:Up(), 90 )
ang:RotateAroundAxis(ang:Forward(), 90 )
local pos = EntPos + EyeForward * 6.0
cam.Start3D2D( pos, ang, self.ImageZoom )
local x,y,w,h = self.NegativeStartX / self.ImageZoom,
self.NegativeStartY / self.ImageZoom,
self.DoorWidth / self.ImageZoom,
self.DoorHeight / self.ImageZoom
surface.SetDrawColor( 0,0,0, 255 )
surface.DrawRect( x, y, w, h )
x,y,w,h = x+2, y+2, w-4, h-4
surface.SetDrawColor( 95, 171, 223, 255 )
surface.DrawOutlinedRect( x, y, w, h )
x,y,w,h = x+1, y+1, w-2, h-2
local NumBlocks = self.WidthSize
local EachBlockX = math.floor( w / NumBlocks )
local EachBlockY = math.floor( h / (NumBlocks * 2) )
for k, v in pairs( self.Blocks ) do
local Posx,Posy = self:NumToXY( k )
_G.MsgN("Posx = ".. tostring(Posx))
_G.MsgN("Posy = ".. tostring(Posy))
if Posy > 0 then
local col = TETRISCOLORS[ v ]
_G.MsgN("TETRISCOLORS R = ".. tostring(col.r))
_G.MsgN("TETRISCOLORS G = ".. tostring(col.g))
_G.MsgN("TETRISCOLORS B = ".. tostring(col.b))
surface.SetDrawColor( col.r, col.g, col.b, 255)
surface.DrawRect( x + EachBlockX * Posx, y + EachBlockY * (Posy-1) + 1, EachBlockX - 1, EachBlockY - 1 )
end
end
surface.SetTextColor( 55, 139, 207, 127 )
surface.SetTextPos( x + 3 ,y )
surface.DrawText( self.Points )
surface.SetTextColor( 95, 171, 223, 127 )
surface.SetTextPos( x + 2 ,y - 1 )
surface.DrawText( self.Points )
cam.End3D2D()
end
[/LUA]
[b]shared_lua[/b]
[lua]
ENT.TETRISBLOCKS = {
{{0,0},{1,0},{0,1},{1,1}}, //square
{{0,0},{0,1},{0,2},{0,3}}, //long piece
{{0,0},{0,1},{0,2},{1,2}}, //right L
{{1,0},{1,1},{1,2},{0,2}}, //left L
{{0,0},{0,1},{1,1},{1,2}},
{{1,0},{1,1},{0,1},{0,2}},
{{0,1},{1,0},{1,1},{1,2}}, //montain
}
function ENT:NumToXY( num )
local NumBlocks = 10 //self:WidthSize()
local x = num % NumBlocks
local y = (num - x) / NumBlocks
return x,y
end
function ENT:XYToNum( x, y )
local NumBlocks = 10 //self:WidthSize()
return y * NumBlocks + x
end
function ENT:CreateNewBlock()
self:EraseFullRows()
math.randomseed( CurTime() )
self.CurBlock = math.random( 1, #self.TETRISBLOCKS )
self.CurBlockX = math.floor( self.WidthSize / 2 )
self.CurBlockY = 0
self.BlockArea = self.TETRISBLOCKS[ self.CurBlock ]
if self:CheckBlocks( self.CurBlockX, self.CurBlockY , self.BlockArea ) == false then
self:EndGame()
end
self:ResetSendTable()
end
function ENT:CheckNextPos( xchange, ychange, checkitself )
local GlobalPos = {}
local MaxSide = self.WidthSize
local MaxDown = MaxSide * 2
for _, v in pairs( self.BlockArea ) do
local NewPosY = self.CurBlockY + v[2] + ychange
local NewPosX = self.CurBlockX + v[1] + xchange
if NewPosY > MaxDown then
return false
end
if NewPosX < 0 || NewPosX >= MaxSide then
return false
end
table.insert( GlobalPos, self:XYToNum( NewPosX, NewPosY ) )
end
for k, color in pairs( self.Blocks ) do
for _, pos in pairs( GlobalPos ) do
if k == pos then
if checkitself != true && !self:IsItSelf( pos ) then
return false
end
end
end
end
return true
end
[/lua]
[b]some output in console for debugging[b]
[lua]Posx = 6
Posy = 4
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
Posx = 6
Posy = 6
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
Posx = 5
Posy = 3
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
Posx = 6
Posy = 9
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
Posx = 5
Posy = 15
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
Posx = 6
Posy = 10
TETRISCOLORS R = 50
TETRISCOLORS G = 50
TETRISCOLORS B = 50
[/lua]
EDIT: Post was useless, sorry :)
[QUOTE=Matt09546;52264813]Try: [url]https://wiki.garrysmod.com/page/Entity/SetColor[/url] instead of drawcolor[/QUOTE]
the Tetris blocks aren't entites but 3d2d drawn blocks.
Mate don't do this.
[QUOTE=Matt09546;52264813]Try: [url]https://wiki.garrysmod.com/page/Entity/SetColor[/url] instead of drawcolor[/QUOTE]
don't work and is not good ^^
[code]local col = TETRISCOLORS[k % #TETRISCOLORS][/code]
You are trying to get colors by table value which is location of each block, so it doesnt make sense. Try to get it with tables key.
How to getting it working it's seem to be half working / half color on a block but problem with the world going to invisible bug
many sure it's not a problem with color line but this :
[lua]
ENT.TETRISBLOCKS = {
{{0,0},{1,0},{0,1},{1,1}}, //square
{{0,0},{0,1},{0,2},{0,3}}, //long piece
{{0,0},{0,1},{0,2},{1,2}}, //right L
{{1,0},{1,1},{1,2},{0,2}}, //left L
{{0,0},{0,1},{1,1},{1,2}},
{{1,0},{1,1},{0,1},{0,2}},
{{0,1},{1,0},{1,1},{1,2}}, //montain
}
[/lua]
Sorry, you need to Log In to post a reply to this thread.