• LuaCraft | Minecraft with a taste of Lua
    383 replies, posted
Oh. You should add some sort of checks in there for checking if there is any block there at all. I was on a superflat world, and it was trying to use a block that was in the Void.
How would I go about finding the block that the player is looking at ( serverside )?
[QUOTE=nick10510;34546053]How would I go about finding the block that the player is looking at ( serverside )?[/QUOTE] [lua] player.GetByName("yourname"):Trace(distance).HitPos --or player.GetByName("yourname"):Trace(distance).HitBlock [/lua]
[QUOTE=bobthe2lol;34546137][lua] player.GetByName("yourname"):Trace(distance).HitPos --or player.GetByName("yourname"):Trace(distance).HitBlock [/lua][/QUOTE] Thanks, I had the trace in my code, just didn't specify the .HitBlock.
Does this mean that you can send lua files from the server, to the client now?
[QUOTE=Anderen2;34547504]Does this mean that you can send lua files from the server, to the client now?[/QUOTE] To Clients using LuaCraft, yes!
[QUOTE=Anderen2;34547504]Does this mean that you can send lua files from the server, to the client now?[/QUOTE] Ignore ^'s post. You can't do this yet. :P You can however use Player:SendLua() serverside. [lua] hook.Add("PlayerSpawn", "SendLua", function(ply) ply:SendLua[[ print("Hello there " .. LocalPlayer():Name() .. "! :)") ]] end) [/lua]
[QUOTE=@@;34547815]Ignore ^'s post. You can't do this yet. :P You can however use Player:SendLua() serverside. [lua] hook.Add("PlayerSpawn", "SendLua", function(ply) ply:SendLua[[ print("Hello there " .. LocalPlayer():Name() .. "! :)") ]] end) [/lua][/QUOTE] Ahh, well, better than nothing :) Is a solution similar to GMod's way planned?
[QUOTE=Anderen2;34547849]Is a solution similar to GMod's way planned?[/QUOTE] Yes it is.
[QUOTE=@@;34547977]Yes it is.[/QUOTE] Take my babies.
Wait, the client simply tells the server that it's broken a block? Couldn't you knock out the entire map with that?
Luckily no. The server has checks to prevent that. :v:
How do i simply get the local player in a client script?
LocalPlayer()
-snip-
[code]local font = surface.GetFont() local name = LocalPlayer() hook.Add("render.gameoverlay", "Game - Render Overlay", function() if doscan == true then for _, ent in pairs(ents.GetByClass("Wolf")) do if (ent ~= LocalPlayer()) then local pos = ent:EyePos() local x, y, vis = pos:ToScreen() local dist = pos:Distance(LocalPlayer():EyePos()) if dist < 62 and vis then local alpha = math.Clamp( 1 - (dist/64), 0, 1 ) * 255 if (ent:IsMob()) then surface.SetDrawColor(255, 0, 0, alpha) elseif (ent:IsAnimal()) then surface.SetDrawColor(0, 255, 0, alpha) else surface.SetDrawColor(0, 0, 255, alpha) end surface.DrawRect(x, y, 1, 1) surface.SetDrawColor(255, 255, 255, alpha) local w, h = font:GetTextSize(ent:GetClass()) font:DrawText(ent:GetClass(), x - w / 2, y - 16) if (ent:IsLiving()) then local healthPerc = ent:GetHealth() / ent:GetMaxHealth() surface.SetDrawColor(0, 0, 0, alpha) surface.DrawRect(x - 8, y - 8, 16, 2) surface.SetDrawColor( (1 - healthPerc) * 255, healthPerc * 255, 0, alpha) surface.DrawRect(x - 8, y - 8, 16 * healthPerc, 2) end end end end end -- 10 y spacing in text font:DrawText("Running Rdebug. Type rhelp in console for more info.",5, 5) if rdebug == true then font:DrawText("Health: " .. name:GetHealth() .. "/20",5, 15) font:DrawText("Armor: " .. name:GetArmor() .. "/20",5, 25) font:DrawText("Air: " .. name:GetAir() .. "/300",5, 35) font:DrawText("X:" .. round(name:GetPos().x) .. " Y:" .. round(name:GetPos().y) .. " Z:" .. round(name:GetPos().z),5, 45) font:DrawText("XP: " .. name:GetExperience() ,5, 55) end end) function round(num) return math.floor(num+.5) end hook.Add("console.command", "LuaCraft - Command", function(tbl, strCommand) print("Console: " .. strCommand) if rpdebug == true then for key,value in pairs(tbl) do print(key,value) end end if tbl[1] == "rpdebug" then if tbl[2] == '1' then rpdebug = true elseif tbl[2] == '0' then rpdebug = false end end if tbl[1] == "rdebug" then if tbl[2] == '1' then rdebug = true elseif tbl[2] == '0' then rdebug = false end end if tbl[1] == rgive then name:Give(ItemStack(tbl[2], tbl[3])) end if tbl[1] == "rhelp" then print("Rdebug script commands:") print("Type name [your username] in console to begin.") print("rpdebug with arg 1/0 for toggle. Enables console command debugging.") print("rdebug with arg 1/0 for toggle. Enables simple GUI debugging helper.") print("rgive with arg id and arg amount. Gives you the item specified.") end end)[/code] None of the functions that use the localplayer name work. No errors come up. [editline]5th February 2012[/editline] Actually, wait I get a single java error when I load the world. [url]http://i.cubeupload.com/WtAI8q.png[/url]
Define name at the start of the hook: [lua] hook.Add("render.gameoverlay", "Game - Render Overlay", function() local font = surface.GetFont() local name = LocalPlayer() if doscan == true then for _, ent in pairs(ents.GetByClass("Wolf")) do if (ent ~= LocalPlayer()) then local pos = ent:EyePos() local x, y, vis = pos:ToScreen() local dist = pos:Distance(LocalPlayer():EyePos()) if dist < 62 and vis then local alpha = math.Clamp( 1 - (dist/64), 0, 1 ) * 255 if (ent:IsMob()) then surface.SetDrawColor(255, 0, 0, alpha) elseif (ent:IsAnimal()) then surface.SetDrawColor(0, 255, 0, alpha) else surface.SetDrawColor(0, 0, 255, alpha) end surface.DrawRect(x, y, 1, 1) surface.SetDrawColor(255, 255, 255, alpha) local w, h = font:GetTextSize(ent:GetClass()) font:DrawText(ent:GetClass(), x - w / 2, y - 16) if (ent:IsLiving()) then local healthPerc = ent:GetHealth() / ent:GetMaxHealth() surface.SetDrawColor(0, 0, 0, alpha) surface.DrawRect(x - 8, y - 8, 16, 2) surface.SetDrawColor( (1 - healthPerc) * 255, healthPerc * 255, 0, alpha) surface.DrawRect(x - 8, y - 8, 16 * healthPerc, 2) end end end end end -- 10 y spacing in text font:DrawText("Running Rdebug. Type rhelp in console for more info.",5, 5) if rdebug == true then font:DrawText("Health: " .. name:GetHealth() .. "/20",5, 15) font:DrawText("Armor: " .. name:GetArmor() .. "/20",5, 25) font:DrawText("Air: " .. name:GetAir() .. "/300",5, 35) font:DrawText("X:" .. round(name:GetPos().x) .. " Y:" .. round(name:GetPos().y) .. " Z:" .. round(name:GetPos().z),5, 45) font:DrawText("XP: " .. name:GetExperience() ,5, 55) end end) function round(num) return math.floor(num+.5) end hook.Add("console.command", "LuaCraft - Command", function(tbl, strCommand) print("Console: " .. strCommand) if rpdebug == true then for key,value in pairs(tbl) do print(key,value) end end if tbl[1] == "rpdebug" then if tbl[2] == '1' then rpdebug = true elseif tbl[2] == '0' then rpdebug = false end end if tbl[1] == "rdebug" then if tbl[2] == '1' then rdebug = true elseif tbl[2] == '0' then rdebug = false end end if tbl[1] == rgive then name:Give(ItemStack(tbl[2], tbl[3])) end if tbl[1] == "rhelp" then print("Rdebug script commands:") print("Type name [your username] in console to begin.") print("rpdebug with arg 1/0 for toggle. Enables console command debugging.") print("rdebug with arg 1/0 for toggle. Enables simple GUI debugging helper.") print("rgive with arg id and arg amount. Gives you the item specified.") end end)[/lua] [editline]5th February 2012[/editline] [QUOTE=ruarai;34549401]Actually, wait I get a single java error when I load the world. [url]http://i.cubeupload.com/WtAI8q.png[/url][/QUOTE] You get that error because the player isn't initialized when the script loads. ( Same as in Garry's Mod. )
I suddenly want to write a game mode like thing. Hmm...
[code] for _, ent in pairs(ents.GetByClass("Wolf")) do if (ent ~= LocalPlayer()) then [/code] When is local player ever a wolf?
Is there some way to include other lua files? For example, I have a lua file named arena.lua in the same folder as my init.lua. Inside arena.lua I stuck module(..., package.seeall) at the top, but on requiring 'arena', I get a lua error telling me that arena.lua does not exist, even though I can obviously see it right there. Is there some sort of directory structure or include directory that I should use?
hmm, is trace.Entity broken? something like this always returns nil for me: [code] local me = LocalPlayer() for k, v in pairs(ents.GetAll()) do if v:IsValid() and (v:IsPlayer() or v:IsMob() or v:IsLiving()) and v ~= me then local tr = TraceLine( { start = me:EyePos(), endpos = v:EyePos(), world = me:GetWorld(), dimension= me:Dimension(), } ) print(tr.Entity) end end [/code]
[QUOTE=bobthe2lol;34550157]Is there some way to include other lua files? For example, I have a lua file named arena.lua in the same folder as my init.lua. Inside arena.lua I stuck module(..., package.seeall) at the top, but on requiring 'arena', I get a lua error telling me that arena.lua does not exist, even though I can obviously see it right there. Is there some sort of directory structure or include directory that I should use?[/QUOTE] Use the include function? :v: [editline]5th February 2012[/editline] [QUOTE=victormeriqui_1;34550188]hmm, is trace.Entity broken?[/QUOTE] Try using table.Print on the entire tr table. Make sure me isn't nil, print eyepos of both me and v, etc.. Pretty much any debugging information would help.
[QUOTE=miceiken;34549665][code] for _, ent in pairs(ents.GetByClass("Wolf")) do if (ent ~= LocalPlayer()) then [/code] When is local player ever a wolf?[/QUOTE] My bad coding copied everything from ESP :v:
[QUOTE=victormeriqui_1;34550188]hmm, is trace.Entity broken? something like this always returns nil for me: [code] local me = LocalPlayer() for k, v in pairs(ents.GetAll()) do if v:IsValid() and (v:IsPlayer() or v:IsMob() or v:IsLiving()) and v ~= me then local tr = TraceLine( { start = me:EyePos(), endpos = v:EyePos(), world = me:GetWorld(), dimension= me:Dimension(), } ) print(tr.Entity) end end [/code][/QUOTE] Just an FYI. The world and dimension index does nothing on the client. The only world the player knows about is the world they are currently in, so TraceLine on the client automatically uses the current world. Same with the World() global on the client. It will only ever return the world the client is currently in. Anyway, I'll look and see if it ever returns a hit entity on the client.
[QUOTE=bobthe2lol;34550157]Is there some way to include other lua files? For example, I have a lua file named arena.lua in the same folder as my init.lua. Inside arena.lua I stuck module(..., package.seeall) at the top, but on requiring 'arena', I get a lua error telling me that arena.lua does not exist, even though I can obviously see it right there. Is there some sort of directory structure or include directory that I should use?[/QUOTE] I had the same problem just a few hours ago. I honestly couldn't find a simple solution so I just used loadstring() on the files I wanted to include. And to @@s comment, unless I was using it incorrectly the include() function doesn't do shit for me.
Is there documentation for the surface and other drawing libraries?
[QUOTE=somescripter;34551544]Is there documentation for the surface and other drawing libraries?[/QUOTE] [quote] surface.CreateFont( "texture.png" ) returns a Font meta object Font:DrawText( text, x, y ) Font:DrawTextShadow( text, x, y ) Font:DrawTextWrapped( text, x, y, maxWidth ) Font:GetTextSize( text ) returns width, height surface.SetFont( fontobg ) surface.GetFont() returns the current working font surface.GetTextureID( "texture.png" ) returns a texture ID surface.SetTexture( textureID ) surface.GetTextureSize( "texture.png" ) returns width, height surface.DrawTexturedRect( x, y, width, height ) surface.DrawTexturedRectUV( x, y, width, height, u, v ) surface.SetDrawColor( r, g, b, a ) surface.SetDrawColor( Color ) surface.GetDrawColor() returns the current set draw color as a color object surface.DrawRect( x, y, width, height ) surface.DrawGradientRect( x, y, width, height, Color:fadeto ) surface.DrawText( x, y, Boolean:drawshadow ) [/quote] Documentation will be sorted out properly on the wiki soon enough.
[QUOTE=@@;34551751]Documentation will be sorted out properly on the wiki soon enough.[/QUOTE] Is there some kind of "AddCSLuaFile" for servers, and if not, will there ever be? That would complete the awesomness for me. And does the server list when you click Multiplayer only pick up servers running LuaCraft? If so, that's awesome too.
[QUOTE=somescripter;34552067]Is there some kind of "AddCSLuaFile" for servers, and if not, will there ever be? That would complete the awesomness for me. And does the server list when you click Multiplayer only pick up servers running LuaCraft? If so, that's awesome too.[/QUOTE] You can join all types of servers, even with lua addons installed (which is great).
[QUOTE=somescripter;34552067]Is there some kind of "AddCSLuaFile" for servers, and if not, will there ever be? That would complete the awesomness for me. And does the server list when you click Multiplayer only pick up servers running LuaCraft? If so, that's awesome too.[/QUOTE] You can use player:SendLua[[]] upto something like 4mb of data. Sending files to the client will come after the ad dons system is fully implanted.
Sorry, you need to Log In to post a reply to this thread.