[QUOTE=Genesis999]When using hooks.Add() if the hook you want to add is "player.command" then you can pass a fourth parameter,
A function that will be run before the command handler and determine whether the command handler should be run.
If it returns false the command handler wont be run.
( A validator)
Eg: hooks.Add("player.command", "Validator Example OP Hook", CommandHandler, function(ply) return ply.Op() end)[/QUOTE]
Why make it so damn overcomplicated?
[lua]hooks.Add("player.command", "Hook 1", function(ply)
if (ply.Op()) then
-- magic op capabilities
else
-- normal user
end
end)[/lua]
[QUOTE=The-Stone;32000344]Why make it so damn overcomplicated?
[lua]hooks.Add("player.command", "Hook 1", function(ply)
if (ply.Op()) then
-- magic op capabilities
else
-- normal user
end
end)[/lua][/QUOTE]
Its hardly overcomplicated. And if a person didnt want to use that way of doing it they could just leave the fourth parameter off and it would be run as usual. Im not forcing them to use that method of checking just providing them with the option of.
When are we going to get userdata.
[QUOTE=LEETNOOB;32000791]When are we going to get userdata.[/QUOTE]
Userdata for what?
[lua]
local Earth = Server.GetWorld(0)
local Neather = Server.GetWorld(1)
function GetPlayer( name )
for k, v in pairs(players.GetAll()) do
if string.lower(v:Username()) == string.lower(name) then
return v
else
return nil
end
end
end
hooks.Add("game.tick", "Tick", function( )
if !IsDayTime() then
Earth:SetTime(0)
elseif IsRaining() then
Earth:SetRaining(false)
elseif IsStorming() then
Earth:SetStorming(false)
end
end)
hooks.Add("game.command", "Command", function( p, c, a )
if !c and !a then return end
if c == "!clear" then
p:GetInventory():Clear()
p:Print(colour.Blue, "(LUA)", colour.LightBlue, " Your inventory has been cleared")
elseif c == "!give" or c == "add" then
if p:IsOp() then
local item = a[1]
p:GetInventory():Add(item)
p:Print(colour.Blue, "(LUA)", colour.LightBlue, item .. " has been added to your inventory.")
end
elseif c == "!tp" then
if p:IsOp() then
local target = GetPlayer( a[1] )
if target then
target:SetPosition( p:GetPosition() )
end
end
elseif c == "!goto" then
if p:IsOp() then
local target = GetPlayer( a[1] )
if target then
p:SetPosition( target:GetPosition() )
end
end
elseif c == "!ib" then
if p:IsOp() then
if !p.InstantBreak then
p.InstantBreak = true
else
p.InstantBreak = false
end
end
elseif c == "!op" then
if p:IsOp() then
local target = GetPlayer( a[1] )
if target and !target:IsOp() then
target:PromoteOp()
elseif target and target:IsOp() then
target:DemoteOp()
end
end
end
end)
[/lua]
Real basic shit haven't test.
[editline]29th August 2011[/editline]
[QUOTE=LEETNOOB;32000791]When are we going to get userdata.[/QUOTE]
Networking? Or are you referring to more player functions?
[QUOTE=Aide;32000929][lua]
!(value)
[/lua]
Real basic shit haven't test.[/QUOTE]
We are not in GMod / GLua sir. Use not
[QUOTE=The-Stone;32001245]We are not in GMod / GLua sir. Use not[/QUOTE]
Yeah, good point. Didn't know.
[lua][INFO] Started LuaServer Build: 24
world:SpawnItem(Vector(block.X, block.Y, block.Z), Item(289, 1))
[WARNING] Lua: Error at World.SpawnItem() first parameter should be a vector.[/lua]
Nice.
[QUOTE=LEETNOOB;32003583][lua][INFO] Started LuaServer Build: 24
world:SpawnItem(Vector(block.X, block.Y, block.Z), Item(289, 1))
[WARNING] Lua: Error at World.SpawnItem() first parameter should be a vector.[/lua]
Nice.[/QUOTE]
Use a . instead of :
Eg: world.SpawnItem instead of world:SpawnItem
This hooks.Remove() won't work for me. I'm trying to create a custom time command. Here's the code:
[lua]
hooks.Add( "player.command", "Player Command", function( p,c,a )
if not p.Op() then return end
if c == "time" then
local world = server.GetWorld(1)
local Func
if a[1] == "set" then Func = world.Time
elseif a[1] == "stay" then Func = StayTime
elseif a[1] == "get" then p.Print( colour.Grey, "The current time is: ", colour.White, world.Time() )
else p.Print( colour.Grey, "Invalid argument #1" )
end
if a[2] and Func then
if type(tonumber(a[2])) == "number" then Func(tonumber(a[2]))
elseif a[2] == "morning" then Func(0)
elseif a[2] == "noon" then Func(6000)
elseif a[2] == "evening" then Func(12000)
elseif a[2] == "night" then Func(18000)
elseif a[2] == "normal" then hooks.Remove( "game.tick", "StayTime" ) --Right here
else p.Print( colour.Grey, "Invalid argument #2" )
end
end
end
end)
function StayTime( time )
hooks.Add( "game.tick", "StayTime", function()
server.GetWorld(1).Time(time)
end)
end
[/lua]
Nothing happens when it gets called. It just continues to set the time.
[b]Edit:[/b]
Also, whenever I do anything with inventories my server just crashes.
[QUOTE=Sparky-Z;32013666]This hooks.Remove() won't work for me. I'm trying to create a custom time command. Here's the code:
[lua]
hooks.Add( "player.command", "Player Command", function( p,c,a )
if not p.Op() then return end
if c == "time" then
local world = server.GetWorld(1)
local Func
if a[1] == "set" then Func = world.Time
elseif a[1] == "stay" then Func = StayTime
elseif a[1] == "get" then p.Print( colour.Grey, "The current time is: ", colour.White, world.Time() )
else p.Print( colour.Grey, "Invalid argument #1" )
end
if a[2] and Func then
if type(tonumber(a[2])) == "number" then Func(tonumber(a[2]))
elseif a[2] == "morning" then Func(0)
elseif a[2] == "noon" then Func(6000)
elseif a[2] == "evening" then Func(12000)
elseif a[2] == "night" then Func(18000)
elseif a[2] == "normal" then hooks.Remove( "game.tick", "StayTime" ) --Right here
else p.Print( colour.Grey, "Invalid argument #2" )
end
end
end
end)
function StayTime( time )
hooks.Add( "game.tick", "StayTime", function()
server.GetWorld(1).Time(time)
end)
end
[/lua]
Nothing happens when it gets called. It just continues to set the time.[/QUOTE]
I fixed up the wiki to show the changes. When updating the wiki I missed that. Remove the "game.tick" parameter. You only need to pass in the unique name.
Sorry for bumping again, but I can't figure out why inventories won't work for me.
Here's a simple line of code I'm trying to run: (p is defined)
[lua]p:GetInventory():Clear()[/lua]
But then server crashes and I get this in log:
[code]
[WARNING] java.lang.ArrayIndexOutOfBoundsException: 34
[WARNING] at fx.d_(SourceFile:271)
[WARNING] at el.a(SourceFile:47)
[WARNING] at cl.a(Container.java:54)
[WARNING] at dl.m_(EntityPlayerMP.java:78)
[WARNING] at dj.a(World.java:1230)
[WARNING] at dp.a(WorldServer.java:39)
[WARNING] at dj.g(World.java:1206)
[WARNING] at dj.e(World.java:1125)
[WARNING] at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:470)
[WARNING] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
[WARNING] at bq.run(ThreadServerApplication.java:21)
[SEVERE] Unexpected exception
java.lang.ArrayIndexOutOfBoundsException: 34
at fx.d_(SourceFile:271)
at el.a(SourceFile:47)
at cl.a(Container.java:54)
at dl.m_(EntityPlayerMP.java:78)
at dj.a(World.java:1230)
at dp.a(WorldServer.java:39)
at dj.g(World.java:1206)
at dj.e(World.java:1125)
at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:470)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
at bq.run(ThreadServerApplication.java:21)
[/code]
Whats the point when you can always just implement java.
[QUOTE=zzaacckk;32052920]Whats the point when you can always just implement java.[/QUOTE]
Some people prefer one language over another.
[QUOTE=Sparky-Z;32051232]I get this in log:
[code]
[WARNING] java.lang.ArrayIndexOutOfBoundsException: 34
[WARNING] at fx.d_(SourceFile:271)
[WARNING] at el.a(SourceFile:47)
[WARNING] at cl.a(Container.java:54)
[WARNING] at dl.m_(EntityPlayerMP.java:78)
[WARNING] at dj.a(World.java:1230)
[WARNING] at dp.a(WorldServer.java:39)
[WARNING] at dj.g(World.java:1206)
[WARNING] at dj.e(World.java:1125)
[WARNING] at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:470)
[WARNING] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
[WARNING] at bq.run(ThreadServerApplication.java:21)
[SEVERE] Unexpected exception
java.lang.ArrayIndexOutOfBoundsException: 34
at fx.d_(SourceFile:271)
at el.a(SourceFile:47)
at cl.a(Container.java:54)
at dl.m_(EntityPlayerMP.java:78)
at dj.a(World.java:1230)
at dp.a(WorldServer.java:39)
at dj.g(World.java:1206)
at dj.e(World.java:1125)
at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:470)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
at bq.run(ThreadServerApplication.java:21)
[/code][/QUOTE]
Please take a look here: [url]http://forums.luaserver.org/showthread.php?tid=60[/url]
It has been reported, should be fixable :)
[editline]1st September 2011[/editline]
[QUOTE=ruarai;32052112]Can you tell me how you would find if a block was say, an iron block?[/QUOTE]
Usually by the blocks Id field... Take a [URL="http://wiki.luaserver.org/index.php/Block#.3Cblock.3E.Id"]look here[/URL]
Hey people just a quick update:
Build 25 is on it's way.
Some new features include:
Hook Player.takedamage(ply,cause,amount)
Hook weather.rainchange(startingorstopping)
Hook weather.stormchange(startingorstopping)
Fixed the inventory crash bug.
Added player armour access.
And more that I can't remember because I'm
Not at my computer. :)
The luaserver.jar can't download the files, is there a way to download without using the downloader?
[QUOTE=topgun98;32236382]The luaserver.jar can't download the files, is there a way to download without using the downloader?[/QUOTE]Sure, go ahead and download the SQLite binaries, Luaserver.jar and Changelog.txt from here: [url]http://downloads.luaserver.org/latest/[/url]
[QUOTE=topgun98;32236382]The luaserver.jar can't download the files, is there a way to download without using the downloader?[/QUOTE]
why cant it download the files?
[QUOTE=Genesis999;32249318]why cant it download the files?[/QUOTE]
I don't know, is there a problem with the server? I tried with 2 different computers.
Got it working.
I am having trouble with the getting started tutorial, can someone show me how it is meant to look?
[QUOTE=Chevron;32258735]I am having trouble with the getting started tutorial, can someone show me how it is meant to look?[/QUOTE]
What's the error?
[QUOTE=topgun98;32260566]What's the error?[/QUOTE]
No error, server.ChatAll is broken.
[editline]13th September 2011[/editline]
Is there a way to load files that are not the same name as the folder they are in?
[QUOTE=Chevron;32266851]No error, server.ChatAll is broken.[/QUOTE]
Can you show some example code? Have you gone through the forums.luaserver.org yet? The wiki.luaserver.org ?
[QUOTE=Chevron;32266851]Is there a way to load files that are not the same name as the folder they are in?[/QUOTE]
You can use: [code]dofile( filename )[/code][I]filename[/I] is a path relative to where Luaserver.jar is located.
So basically you may want to [code]dofile("lua/someotherscript/anything_here.lua")[/code]
[QUOTE=petsagouris;32268494]Can you show some example code? Have you gone through the forums.luaserver.org yet? The wiki.luaserver.org ?
You can use: [code]dofile( filename )[/code][I]filename[/I] is a path relative to where Luaserver.jar is located.
So basically you may want to [code]dofile("lua/someotherscript/anything_here.lua")[/code][/QUOTE]
Thank you.
Yea I have check the forums,
[url]http://forums.luaserver.org/showthread.php?tid=49&pid=281#pid281[/url]
Ir prints a blank line, if someone has got it to work tell me.
With that dofile command are you able to unmount them as well or is it only one way?
[editline]14th September 2011[/editline]
dotfile is like an import into the file, so I could just unload the hooks yea?
[QUOTE=Chevron;32280091]
With that dofile command are you able to unmount them as well or is it only one way?
dofile is like an import into the file, so I could just unload the hooks yea?[/QUOTE]
[url]http://pgl.yoyo.org/luai/i/dofile[/url]
If you want to unload/unregister hooks you should use the [URL="http://wiki.luaserver.org/index.php/Hook_Manager#hooks.Remove.28_name_.29"]hooks.Remove[/URL].
dofile is essentially this: [url]http://pgl.yoyo.org/luai/i/dofile[/url]
So for example, if you have this in a lua file you will be getting through "dofile":
[code]
-- some_table.lua
return {
"nice", "table", you = "have there"
}[/code]
You will want to do the following in your code if you want to unload it later.
[code]
some_table = dofile("lua/path/to/some_table.lua")
print(some_table.you) -- prints "have there" in the server output
some_table = nil -- unloads the table
[/code]
[QUOTE=petsagouris;32281666][url]http://pgl.yoyo.org/luai/i/dofile[/url]
If you want to unload/unregister hooks you should use the [URL="http://wiki.luaserver.org/index.php/Hook_Manager#hooks.Remove.28_name_.29"]hooks.Remove[/URL].
dofile is essentially this: [url]http://pgl.yoyo.org/luai/i/dofile[/url]
So for example, if you have this in a lua file you will be getting through "dofile":
[code]
-- some_table.lua
return {
"nice", "table", you = "have there"
}[/code]
You will want to do the following in your code if you want to unload it later.
[code]
some_table = dofile("lua/path/to/some_table.lua")
print(some_table.you) -- prints "have there" in the server output
some_table = nil -- unloads the table
[/code][/QUOTE]
So if I am using this to load another script, how does making the var I set it to = nothing, stop running said script.
[QUOTE=Chevron;32282593]So if I am using this to load another script, how does making the var I set it to = nothing, stop running said script.[/QUOTE]I am afraid you have this concept wrong. Just executes the code in the dofile'd filename.
If you want to have control over code execution, have a look at [URL="http://www.google.gr/search?q=lua+sandbox"]sandboxing Lua code[/URL].
In any case, what are you trying to achieve?
Build 25
======================================
Hey there people of Facepunch! :)
Build 25 was released tonight.
The changelog is viewable at:
[url]http://downloads.luaserver.org/latest/Changelog.txt[/url]
Enjoy lovely people.
[QUOTE=petsagouris;32282673]I am afraid you have this concept wrong. Just executes the code in the dofile'd filename.
If you want to have control over code execution, have a look at [URL="http://www.google.gr/search?q=lua+sandbox"]sandboxing Lua code[/URL].
In any case, what are you trying to achieve?[/QUOTE]
I am trying to have a base file that I can load and unload modules from.
[editline]14th September 2011[/editline]
[QUOTE=Genesis999;32283597]Build 25
======================================
Hey there people of Facepunch! :)
Build 25 was released tonight.
The changelog is viewable at:
[url]http://downloads.luaserver.org/latest/Changelog.txt[/url]
Enjoy lovely people.[/QUOTE]
Does it work with 1.8?
Sorry, you need to Log In to post a reply to this thread.