• LuaServer
    467 replies, posted
Ive put up a new version that: -fixed the functions that use the coloured text system. Im going to look for an easier way for people to update their server.
[QUOTE=Genesis999;31426747]Ive put up a new version that: -fixed the functions that use the coloured text system. Im going to look for an easier way for people to update their server.[/QUOTE] The new version is suppoed to be build 18_02? The download is for 18_01... And for the updating, i would suggest a batch file that will download the required files and replace them with the old files.
Damn facepunch formatting. Fixed up the link.
[QUOTE=Genesis999;31428657]Damn facepunch formatting. Fixed up the link.[/QUOTE] Cool thanks :) I also noticed one thing. When i start the server, on the very top of the console is this: [code][INFO] Starting Minecraft LuaServer Build 17_02 for Beta 1.7.3[/code] That is kinda late. Dont need to fix it now, but in the next version.
I couldn't figure out how to make a nice and tidy string.explode function in Java for Lua, so I did this instead [code] class split extends ThreeArgFunction { public LuaValue call( LuaValue arg1, LuaValue arg2, LuaValue arg3 ) { String str = arg1.checkjstring(); String sep = arg2.optjstring(" " ); if (!arg3.optboolean( false )) { sep = "\\Q"+sep+"\\E"; } String[] retstr = str.split( sep ); LuaTable ret = new LuaTable(retstr.length,0); for( int I=0;I<retstr.length;I++) { ret.set( I+1, valueOf( retstr[I] )); } return ret; } } string.set( "split", new split() );[/code] This means you [i]could[/i] use Java patterns (instead of Lua patterns) in this function (set the third argument to 'true'), but it defaults to not use them. Maybe I should keep the Lua string.explode function as well in case someone wants to use Lua patterns? Or what do you guys think? EDIT: Also maybe I should post my own thread instead of posting in yours, Genesis, or is that OK? Mine isn't nearly finished enough for a release yet, so there is no point in starting my own thread yet, though.
The chat isnt showing. When i say something, it doesnt show it as a normal chat message. Also, when i do this: [code]local PropFile = Files.CreateProp("lua/users/USERNAME") local Nickname = PropFile:SetString("Money", 50)[/code] I get this error in the console: [code][WARNING] Lua: Error running function. [WARNING] lua/PlayerCom/PlayerCom.lua:3: attempt to index ? (a nil value)[/code] Heres the PlayerCom script: [code]function OnPlayerConnect(Player) local PropFile = Files.CreateProp("lua/users/USERNAME") local Nickname = PropFile:SetString("Money", 50) if Player:IsOp() then Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all") return false else Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all") return false end end Hooks.Add("player.connect", "PlayerCom", OnPlayerConnect) [/code]
[QUOTE=Funley;31432538]The chat isnt showing. When i say something, it doesnt show it as a normal chat message. Also, when i do this: [code]local PropFile = Files.CreateProp("lua/users/USERNAME") local Nickname = PropFile:SetString("Money", 50)[/code] I get this error in the console: [code][WARNING] Lua: Error running function. [WARNING] lua/PlayerCom/PlayerCom.lua:3: attempt to index ? (a nil value)[/code] Heres the PlayerCom script: [code]function OnPlayerConnect(Player) local PropFile = Files.CreateProp("lua/users/USERNAME") local Nickname = PropFile:SetString("Money", 50) if Player:IsOp() then Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all") return false else Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all") return false end end Hooks.Add("player.connect", "PlayerCom", OnPlayerConnect) [/code][/QUOTE] i fixed up the chat issue. had an if equals false do such and such instead of if not equals false do such and such. one thing i should mention is that Files.CreateProp will return nil if the file already exists. And the SetString method doesnt return a value. you should use GetString instead. [code]function OnPlayerConnect(Player) local PropFile = Files.LoadProp("lua/users/USERNAME") local Nickname if PropFile then Nickname = PropFile:GetString("Nickname") else PropFile:SetString("Nickname", "Bob the Great") end if Player:IsOp() then Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all") return false else Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all") return false end end Hooks.Add("player.connect", "PlayerCom", OnPlayerConnect) [/code]
[QUOTE=Genesis999;31438625]i fixed up the chat issue. had an if equals false do such and such instead of if not equals false do such and such. one thing i should mention is that Files.CreateProp will return nil if the file already exists. And the SetString method doesnt return a value. you should use GetString instead. [code]function OnPlayerConnect(Player) local PropFile = Files.LoadProp("lua/users/USERNAME") local Nickname if PropFile then Nickname = PropFile:GetString("Nickname") else PropFile:SetString("Nickname", "Bob the Great") end if Player:IsOp() then Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all") return false else Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!") Server.Chat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all") return false end end Hooks.Add("player.connect", "PlayerCom", OnPlayerConnect) [/code][/QUOTE] I was just thinking, when you do this: [code]local PropFile = Files.LoadProp("lua/users/USERNAME") local Nickname if PropFile then Nickname = PropFile:GetString("Nickname") else PropFile:SetString("Nickname", "Bob the Great") end[/code] If the file has not been created, the Nickname will be left as nil, right? And the download link is still at build 02
Fixed up the download link. 03 changes: Fixed chat cancelling no matter what. The property file's set functions return the value passed into them. [editline]31st July 2011[/editline] [QUOTE=Funley;31448748]I was just thinking, when you do this: [code]local PropFile = Files.LoadProp("lua/users/USERNAME") local Nickname if PropFile then Nickname = PropFile:GetString("Nickname") else PropFile:SetString("Nickname", "Bob the Great") end[/code] If the file has not been created, the Nickname will be left as nil, right? And the download link is still at build 02[/QUOTE] And yes. If the file has not been created then Nickname will be left as nil.
I just tried doing some scripts with this just now, but I can't figure out if there is a function to place a new block of a specified type? I tried using World.SetBlock and World.SetBlockMetaData but none of them did that, I suppose I'm using those functions wrong aswell. Is there a function to create a new block? Also I have a suggestion: Could you make your hook system work kind of like garrysmod does it? Having one unique name for each hook, since now its impossible to create hooks of the same type in the same script. [editline]1th August 2011[/editline] Nevermind that place block thing, I didn't think that "air" was really a block
[QUOTE=Genesis999;31457009]Fixed up the download link. 03 changes: Fixed chat cancelling no matter what. The property file's set functions return the value passed into them. [editline]31st July 2011[/editline] And yes. If the file has not been created then Nickname will be left as nil.[/QUOTE] Okay, so i have this now: [code]local PropFile = Files.CreateProp("lua/users/USERNAME") local Money if PropFile then Money = PropFile:GetInt("Money") else PropFile:SetInt("Money", 50) --This is line 7 end[/code] And im getting this error: [code][WARNING] Lua: Error running function. [WARNING] lua/PlayerCom/PlayerCom.lua:7: attempt to index ? (a nil value)[/code] :/
[QUOTE=Funley;31465797]Okay, so i have this now: [code]local PropFile = Files.CreateProp("lua/users/USERNAME") local Money if PropFile then Money = PropFile:GetInt("Money") else PropFile:SetInt("Money", 50) --This is line 7 end[/code] And im getting this error: [code][WARNING] Lua: Error running function. [WARNING] lua/PlayerCom/PlayerCom.lua:7: attempt to index ? (a nil value)[/code] :/[/QUOTE] You're setting PropFile:SetInt although the if check says it doesn't exist.
[QUOTE=leiftiger;31465805]You're setting PropFile:SetInt although the if check says it doesn't exist.[/QUOTE] Thats a good point, never realised that :P
How would i compare a number with a string from an argument? If i do; [code]if MyNumber < Arguments[2] then[/code] it will say you cannot compare numebr with string.
Depends on what kind of string it is. If it's a string that can be converted to a number, just use tonumber( str )
[QUOTE=Divran;31469488]Depends on what kind of string it is. If it's a string that can be converted to a number, just use tonumber( str )[/QUOTE] Ah thanks. Also, SUGGESTION! A new function in the PlayerClass, [code]IsInArea(X, Y, Z, width, height, depth)[/code] This function would simply check if the player is in the given area. Eg. [code] if Player:IsInArea(100, 10, 20, 5, 5, 5)[/code] Would check if the player is in a 5x5x5 area in location 100,10,20.
[QUOTE=Funley;31470582]Also, SUGGESTION! A new function in the PlayerClass, [code]IsInArea(X, Y, Z, width, height, depth)[/code] This function would simply check if the player is in the given area. Eg. [code] if Player:IsInArea(100, 10, 20, 5, 5, 5)[/code] Would check if the player is in a 5x5x5 area in location 100,10,20.[/QUOTE] Adding functions for everything would just make it bloated. You can always write such a function yourself.
[QUOTE=Divran;31471500]Adding functions for everything would just make it bloated. You can always write such a function yourself.[/QUOTE] I could, yes.
Im thinking of making a zombie survival mod with this :) [editline]2 August 2011[/editline] I can really get started as soon text file reading and writing is implemented.
Anything for SP? :(
[QUOTE=Funley;31470582]Ah thanks. Also, SUGGESTION! A new function in the PlayerClass, [code]IsInArea(X, Y, Z, width, height, depth)[/code] This function would simply check if the player is in the given area. Eg. [code] if Player:IsInArea(100, 10, 20, 5, 5, 5)[/code] Would check if the player is in a 5x5x5 area in location 100,10,20.[/QUOTE] It's called create a table give it x,y,z values and loop through the table to see if the player is near it.
Someone needs to make a Gmod-gamemode-esque base for this. Would be awesome to have servers with different gamemodes that can easily be changed by a vote and all that jazz. Stuff like a basic team system and scoring.
I want Lua wrapper for SP :< And how is it dumb?
New version released. == Build 19 Changelog == Text files implemented. Added a Server.AddRecipe() function to allow for custom recipes. Added a GetType() function to most objects that get passed out to scripts. ( things like player objects, inventory objects, mobs... etc) Reworked the player.death hook to allow distinction as to how someone died. Added a mob.death hook that is run everytime a mob dies. Added a "player.authenticate" hook that is run before the "player.connect" hook. Split "player.breakblock" into "player.digblock", "player.breakblock" and "player.dropblock" Hook system is changed to be more Gmod like. Timers moved from the global Server object to their own Timers object. Changed GetInt() and SetInt() in property files to GetNumber() and SetNumber() Added a Player:DropHeldItem() function. Some other hooks have had their parameters twiddled.
[QUOTE=Genesis999;31635446]New version released. == Build 19 Changelog == Text files implemented. Added a Server.AddRecipe() function to allow for custom recipes. Added a GetType() function to most objects that get passed out to scripts. ( things like player objects, inventory objects, mobs... etc) Reworked the player.death hook to allow distinction as to how someone died. Added a mob.death hook that is run everytime a mob dies. Added a "player.authenticate" hook that is run before the "player.connect" hook. Split "player.breakblock" into "player.digblock", "player.breakblock" and "player.dropblock" Hook system is changed to be more Gmod like. Timers moved from the global Server object to their own Timers object. Changed GetInt() and SetInt() in property files to GetNumber() and SetNumber() Added a Player:DropHeldItem() function. Some other hooks have had their parameters twiddled.[/QUOTE] HOLY SHIT YES!! [editline]yay[/editline] When i do this: [code]local PropFile = Files.GetFile("users/" .. Player:GetUsername(), Files.Prop) local Money Money = Arguments[3] PropFile:SetMoney("Money", Money) --LINE 229 HERE Player:Print("10^Money set to 14^" .. Money .. "10^.")[/code] I get this error in the console: [code]lua/OPCommands/OPCommands.lua:229: attempt to index ? (a nil value)[/code]
[QUOTE=Genesis999;31635446]Added a GetType() function to most objects that get passed out to scripts. ( things like player objects, inventory objects, mobs... etc)[/QUOTE] Why not just use Lua's type function?
[QUOTE=Genesis999;31635446]New version released. == Build 19 Changelog == Text files implemented. Added a Server.AddRecipe() function to allow for custom recipes. Added a GetType() function to most objects that get passed out to scripts. ( things like player objects, inventory objects, mobs... etc) Reworked the player.death hook to allow distinction as to how someone died. Added a mob.death hook that is run everytime a mob dies. Added a "player.authenticate" hook that is run before the "player.connect" hook. Split "player.breakblock" into "player.digblock", "player.breakblock" and "player.dropblock" Hook system is changed to be more Gmod like. Timers moved from the global Server object to their own Timers object. Changed GetInt() and SetInt() in property files to GetNumber() and SetNumber() Added a Player:DropHeldItem() function. Some other hooks have had their parameters twiddled.[/QUOTE] Is it possible to do for SP? That could make modding MC easier.
2 Things: 1.: The Property File tutorial on your wiki isnt complete... 2.: I've made a script with which the Ops can set a spawn and the user can teleport there with /spawn But when i run it it tells me: [QUOTE][INFO] Reloaded script: Exactspawn [WARNING] Lua: Error running function. [WARNING] lua/Exactspawn/Exactspawn.lua:2: attempt to call nil[/QUOTE] That's the code: [QUOTE] function OnCommand(Player, Command, Arguments) local propFile = Files.GetFile("lua/Exactspawn/Exactspawn", Files.Prop) if Player then if Command == "setspawn" then if Player:IsOp() then propFile:SetNumber(X, Player.GetPositionX()) propFile:SetNumber(Y, Player.GetPositionY()) propFile:SetNumber(Z, Player.GetPositionZ()) Player:Print("2^You succesfully saved your Position as Spawn.") else Player:Print("12^You are not allowed to use that command.") end elseif Command == "spawn" then local SpawnX = propFile:GetNumber(X) local SpawnY = propFile:GetNumber(Y) local SpawnZ = propFile:GetNumber(Z) player:TeleportTo(SpawnX, SpawnY, SpawnZ) end end end Hooks.Add("game.command", "Exactspawn", OnCommand) [/QUOTE] EDIT: Is there any way i can use MySQL instead of SqlLite, also i would like to see a SQL / PropFile Tutorial EDIT²: I've found a problem, everytime i want to execute a command ingame it show [INFO] iZeD_IV tried command: item 5 And it doesnt show anything ingame. Script: [QUOTE]function OnCommand(Player, Command, Arguments) if Command == "item" then if Player then if Player:IsOp() then if Arguments[2] then Player:GetInventory():AddItem(Arguments[2], 1) if Arguments[3] then Player:GetInventory():AddItem(Arguments[2], Arguments[3]) if Arguments[4] then Player:GetInventory():AddItem(Arguments[2], Arguments[4], Arguments[3]) if Arguments[5] then Arguments[5]:GetInventory():AddItem(Arguments[2], Arguments[4], Arguments[3]) if Arguments[6] then Player:Print("Syntax: /item <id> <amount> <meta> <player>") else Player:Print("Syntax: /item <id> <amount> <meta> <player>") end end end end else Player:Print("4^Syntax: /item <id> <amount> <meta> <player>") end else Player:Print("4^You are not allowed to use that command!") end else Player2 = Arguments[2] Player2:GetInventory():AddItem(Arguments[3], Arguments[5], Arguments[4]) end elseif Command == "i" then if Player then if Player:IsOp() then if Arguments[2] then Player:GetInventory():AddItem(Arguments[2], 1) if Arguments[3] then Player:GetInventory():AddItem(Arguments[2], Arguments[3]) if Arguments[4] then Player:GetInventory():AddItem(Arguments[2], Arguments[4], Arguments[3]) if Arguments[5] then Arguments[5]:GetInventory():AddItem(Arguments[2], Arguments[4], Arguments[3]) if Arguments[6] then Player:Print("Syntax: /i <id> <amount> <meta> <player>") else Player:Print("Syntax: /i <id> <amount> <meta> <player>") end end end end else Player:Print("4^Syntax: /i <id> <amount> <meta> <player> end else Player:Print("4^You are not allowed to use that command!") end else Player2 = Arguments[2] Player2:GetInventory():AddItem(Arguments[3], Arguments[5], Arguments[4]) end end end Hooks.Add("game.command", "Item", OnCommand) [/QUOTE]
[QUOTE=iZeD_IV;31655589]2 Things: 1.: The Property File tutorial on your wiki isnt complete... 2.: I've made a script with which the Ops can set a spawn and the user can teleport there with /spawn But when i run it it tells me: That's the code: EDIT: Is there any way i can use MySQL instead of SqlLite, also i would like to see a SQL / PropFile Tutorial EDIT²: I've found a problem, everytime i want to execute a command ingame it show [INFO] iZeD_IV tried command: item 5 And it doesnt show anything ingame. Script:[/QUOTE] Forgot to mention this before: calls to CreateFile, GetFile and DeleteFile all start inside the lua directory. For your spawn script... Your calls to SetNumber and GetNumber need to pass a string as the first argument. Eg: SetNumber("X", Player.GetPositionX()) instead of SetNumber(X, Player.GetPositionX()) As to your item command function your not using "return false" anywhere so the command will not be cancelled and will run through the default command handler. [editline]11th August 2011[/editline] Funley your calling propfile:setmoney ... There's no setmoney function
Well ... Thx for this answer, but i have got another problem ^^ [QUOTE]function OnCommand(Player, Command, Arguments) if Command == "version" then if Player then Player:Print("10^This server is running build 18_01 of LuaServer from Genesis999 + iZeD_IV's Lua Scripts.") return false else Server.Info("10^You are running build 18_01 of LuaServer from Genesis999 + iZeD_IV's Lua Scripts.") return false end elseif Command == "reload" then if Player then if Player:IsOp() then Scripts.Reload(Arguments[2]) Player:Print("2^Reloaded script: ".. Arguments[2]) return false else Player:Print("12^You do not have the required permissions.") return false end else if Arguments[2] then Scripts.Reload(Arguments[2]) Server.Info("Reloaded script: ".. Arguments[2]) return false else Server.Info("You need to enter a second parameter.") return false end end end end function PlayerJoined( Player ) Server.Chat( Player:GetUsername() .. " has joined Zombe.net", 10, "#all" ) end function PlayerLeaved( Player ) Server.Chat( Player:GetUsername() .. " has left Zombe.net", 10, "#all" ) end Hooks.Add("game.command", "Join", OnCommand) Hooks.Add("player.connect", "Join", PlayerJoined) Hooks.Add("player.disconnect", "Join", PlayerLeaved)[/QUOTE] There it seems that everything is right, but the commands doesnt work ingame/console. It just shows [INFO] Unknown console command. Type "help" for help. or [INFO] iZeD_IV tried command: version Well... I learn thru problems :D EDIT: Can you make a short and easy Property file tutorial? Cause, i fixed my Exactspawn script and when i execute /setspawn as Op i get this in the console: [QUOTE][LUA] Error running function. [LUA] lua/Exactspawn/Exactspawn.lua:6: attempt to index ? (a nil value) [INFO] iZeD_IV issued server command: setspawn[/QUOTE] Heres my code: [QUOTE]function OnCommand(Player, Command, Arguments) local propFile = Files.GetFile("lua/Exactspawn/Exactspawn", Files.Prop) if Player then if Command == "setspawn" then if Player:IsOp() then propFile:SetNumber("X", Player.GetPositionX()) propFile:SetNumber("Y", Player.GetPositionY()) propFile:SetNumber("Z", Player.GetPositionZ()) Player:Print("2^You succesfully saved your Position as Spawn.") return false else Player:Print("12^You are not allowed to use that command.") return false end elseif Command == "spawn" then local SpawnX = propFile:GetNumber(X) local SpawnY = propFile:GetNumber(Y) local SpawnZ = propFile:GetNumber(Z) player:TeleportTo(SpawnX, SpawnY, SpawnZ) return false end end end Hooks.Add("game.command", "Exactspawn", OnCommand)[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.