• LuaCraft | Minecraft with a taste of Lua
    383 replies, posted
[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:
LocalPlayer()
-snip-
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=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 use player:SendLua[[]] upto something like 4mb of data. Sending files to the client will come after the ad dons system is fully implanted.
[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] In init.lua simply call include("arena.lua")
Working on Multi-Chat allowing servers chat to be seen across servers that use the addon. The system i have isn't perfect, it updates every second or so and because it overwrites the message already on the webpage, messages might not get received before they are overwritten. I'm going to work on a different way of doing this.
Can someone explain how player.command works? Specifically, what the command prefix is? I assume it's something like /command arg1 arg2, but that doesn't seem to call the player.command hook...
[QUOTE=LuaStoned;34556805]In init.lua simply call include("arena.lua")[/QUOTE] Experimented a bit and realized it was returning a java error because I tried calling include() after the server had initialized. [editline]5th February 2012[/editline] [QUOTE=bobthe2lol;34557822]Can someone explain how player.command works? Specifically, what the command prefix is? I assume it's something like /command arg1 arg2, but that doesn't seem to call the player.command hook...[/QUOTE] Anything with the prefix of "/" ( without quotes ) will call the hook. With the first arg being the command ( example: "/command" ).
[QUOTE=Bambo.;34556943]Working on Multi-Chat allowing servers chat to be seen across servers that use the addon. The system i have isn't perfect, it updates every second or so and because it overwrites the message already on the webpage, messages might not get received before they are overwritten. I'm going to work on a different way of doing this.[/QUOTE] Having already made a multi-server chat script, you are much better off using minecrafts built in rcon to run a command.
Does this work on Linux? I am trying it and it is saying my JSON is wrong, when it isn't. [code] { "addon": { "name": "test", "author": "toaster468", "enabled": true } } [/code] (the server applet) The error: 2012-02-05 18:55:21 [WARNING] The info.txt of 'plyList' contains invalid JSON! JSONObject["name"] not found. [WARNING] The info.txt of 'plyList' contains invalid JSON! JSONObject["name"] not found.
You're using the old info.txt format. Use the new format. [code]{ "enabled": true, "author": "", "help": "", "name": "", "version": "1", "info": "" }[/code]
[QUOTE=BlackAwps;34566587]You're using the old info.txt format. Use the new format. [code]{ "enabled": true, "author": "", "help": "", "name": "", "version": "1", "info": "" }[/code][/QUOTE] Gotcha, and I see the folder set up was changed, too.
Maybe I'm doing it wrong but the Give method isn't working for me. Can somebody post an absolutely working example?
Sorry, you need to Log In to post a reply to this thread.