Its a WIP isnt much of an excuse. Its easier to use the function instead of text.
I made an Op command script, which is now only used to set the rain on and off, but it doesnt work.
[code]function OnScriptStart()
Server.AddHook("game.command", "OnCommand", "OPCommands")
end
function OnCommand(Player, Command, Arguments)
if Command == "version" then
if Player then
Player:Print("This server is running build 17 of LuaServer.")
return false
else
PrintToConsole("info", "You are running build 17 of LuaServer.")
return false
end
elseif Command == "rain" then
if Player:IsOp() == false then
Player:Print("12^Command 'rain' is Op only.")
return false
else
local world = Server.GetWorld(0)
if Player then
if Arguments[2] == nil then
Player:Print("12^You must input 'set' or 'get'")
return false
elseif Arguments[2] == "get" then
Player:Print("10^Raining: " .. world.IsRaining() .. ".")
return false
elseif Arguments[2] == "set" then
if Arguments[3] == nil then
Player:Print("12^You must input either true or false.")
return false
elseif Arguments[3] == "true" then
Player:Print("10^Raining set on.")
world.SetRaining(true)
return false
elseif Arguments[3] == "false" then
Player:Print("10^Raining set off.")
world.SetRaining(false)
return false
else
Player:Print("12^Invalid argument '" .. Arguments[3] .. "'.")
return false
end
end
end
end
end
end[/code]
The console says this:
[code][WARNING] Lua: Error running function.
[WARNING] method cannot be called without instance[/code]
:/
I also have a suggestion. "Inventory:GetItem(<itemidhere>)", which will return nil if the item with the given ID cannot be found, and return an ItemClass if the item is found. Then, the ItemClass will have a few functions, such as "GetCount()" to get the count of the item, "SetCount(<number>)" to set the count of the item, and a few more such as "Drop()", "ChangeID(<newidhere>)" and "GetId()". Tell me what you think about this idea!
[QUOTE=Funley;31385707]I made an Op command script, which is now only used to set the rain on and off, but it doesnt work.
[code]function OnScriptStart()
Server.AddHook("game.command", "OnCommand", "OPCommands")
end
function OnCommand(Player, Command, Arguments)
if Command == "version" then
if Player then
Player:Print("This server is running build 17 of LuaServer.")
return false
else
PrintToConsole("info", "You are running build 17 of LuaServer.")
return false
end
elseif Command == "rain" then
if Player:IsOp() == false then
Player:Print("12^Command 'rain' is Op only.")
return false
else
local world = Server.GetWorld(0)
if Player then
if Arguments[2] == nil then
Player:Print("12^You must input 'set' or 'get'")
return false
elseif Arguments[2] == "get" then
Player:Print("10^Raining: " .. world.IsRaining() .. ".")
return false
elseif Arguments[2] == "set" then
if Arguments[3] == nil then
Player:Print("12^You must input either true or false.")
return false
elseif Arguments[3] == "true" then
Player:Print("10^Raining set on.")
world.SetRaining(true)
return false
elseif Arguments[3] == "false" then
Player:Print("10^Raining set off.")
world.SetRaining(false)
return false
else
Player:Print("12^Invalid argument '" .. Arguments[3] .. "'.")
return false
end
end
end
end
end
end[/code]
The console says this:
[code][WARNING] Lua: Error running function.
[WARNING] method cannot be called without instance[/code]
:/
I also have a suggestion. "Inventory:GetItem(<itemidhere>)", which will return nil if the item with the given ID cannot be found, and return an ItemClass if the item is found. Then, the ItemClass will have a few functions, such as "GetCount()" to get the count of the item, "SetCount(<number>)" to set the count of the item, and a few more such as "Drop()", "ChangeID(<newidhere>)" and "GetId()". Tell me what you think about this idea![/QUOTE]
1/ Your doing the Player:IsOp() check before your doing the check to see if the Player exists.
2/ World objects are java objects and are thus accessed by using world:SetRaining() not world.SetRaining()
[editline]28th July 2011[/editline]
[QUOTE=Map in a box;31385653]Its a WIP isnt much of an excuse. Its easier to use the function instead of text.[/QUOTE]
I dont know what made you thought I was but I dont give excuses. I give reasons. Stop being a difficult asshat.
[QUOTE=Genesis999;31385872]1/ Your doing the Player:IsOp() check before your doing the check to see if the Player exists.
2/ World objects are java objects and are thus accessed by using world:SetRaining() not world.SetRaining()
[editline]28th July 2011[/editline]
I dont know what made you thought I was but I dont give excuses. I give reasons. Stop being a difficult asshat.[/QUOTE]
Thanks! I also tried to set storming on and off, but nothing didnt happen when i turned it on.
[QUOTE=Funley;31386029]Thanks! I also tried to set storming on and off, but nothing didnt happen when i turned it on.[/QUOTE]
I do think for storming to work you need to have raining turned on as well.
[QUOTE=Genesis999;31385872]snip[/QUOTE]
I'm not being an asshat, learn to take criticism.
Everyone gives excuses. That was an excuse because implementing something beforehand makes it easier in after.
Im really starting to become some sort of bug reporter to you, since ive found yet more stuff that doesnt work as the wiki said.
When i tried to do
[code]local PropFile = Files.CreateProp("lua/users/USERNAME")
PropFile:SetInt("Cash", 50)[/code]
The console says this
[code][WARNING] Lua: Error running function.
[WARNING] attempt to call function[/code]
That sounds kinda funny, since it errors because i tried to call a function :P
Well it was just another issue with some lines being "this.arg" instead of "v.arg" :(
Reuploaded and updated download links.
Still doesnt work :/ Same error.
I also have one more suggestion. In PrintToChat, after the players parameter, every parameter after that should be player names which the message will not appear to.
Eg;
[code]PrintToChat("Players asd and das cannot see this.", 15, "#all", "asd", "das")[/code]
New version. *groovyface*
-Scripts global table added. Hooks global table added.
-Moved PrintToChat() to Server.Chat()
-Moved PrintToConsole() to Server.Info() and Server.Warning()
-Moved Server.ReloadScript() to Scripts.Reload()
-Added Scripts.Load()
-Added Scripts.Disable()
-Added Scripts.Enable()
-Moved Server.AddHook() to Hooks.Add()
-Added Hooks.Remove()
-Fixed up property file functions again.
-OnScriptStart no longer called.
-Hooks.Add takes an actual function rather than the name of a function.
[QUOTE=Genesis999;31405761]New version. *groovyface*
-Scripts global table added. Hooks global table added.
-Moved PrintToChat() to Server.Chat()
-Moved PrintToConsole() to Server.Info() and Server.Warning()
-Moved Server.ReloadScript() to Scripts.Reload()
-Added Scripts.Load()
-Added Scripts.Disable()
-Added Scripts.Enable()
-Moved Server.AddHook() to Hooks.Add()
-Added Hooks.Remove()
-Fixed up property file functions again.
-OnScriptStart no longer called.[/QUOTE]
Thanks! Gonna spend a while editing my scripts...
MOAR ERRORS, NUU!!
I have three scripts, ExampleScript, MOTD and OPCommands. When i run the server, the console says this:
[code][WARNING] Loading script: ExampleScript.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid
[WARNING] Loading script: MOTD.
[WARNING] Lua: Error loading lua file.
[WARNING] attempt to call nil
[WARNING] Loading script: OPCommands.
[WARNING] Lua: Error at Hooks.Add() script name is not a loaded script.[/code]
The function names are correct in each script.
[QUOTE=Funley;31405914]Thanks! Gonna spend a while editing my scripts...
MOAR ERRORS, NUU!!
I have three scripts, ExampleScript, MOTD and OPCommands. When i run the server, the console says this:
[code][WARNING] Loading script: ExampleScript.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid
[WARNING] Loading script: MOTD.
[WARNING] Lua: Error loading lua file.
[WARNING] attempt to call nil
[WARNING] Loading script: OPCommands.
[WARNING] Lua: Error at Hooks.Add() script name is not a loaded script.[/code]
The function names are correct in each script.[/QUOTE]
The Hooks.Add function is changed from the Server.AddHook parameter.
Eg:
Hooks.Add("hookcode", "scriptname", function)
Instead of:
Server.AddHook("hookcode", "functionname", "scriptname")
[QUOTE=Genesis999;31406045]The Hooks.Add function is changed from the Server.AddHook parameter.
Eg:
Hooks.Add("hookcode", "scriptname", function)
Instead of:
Server.AddHook("hookcode", "functionname", "scriptname")[/QUOTE]
TOTAL NEW ERROR REPORT.
I took the ExampleScript out, and ran the server. I get these errors:
[code][WARNING] Loading script: MOTD.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid
[WARNING] Loading script: OPCommands.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid[/code]
The MOTD script starts like this:
[code]Hooks.Add("player.connect", "MOTD", OnPlayerConnect)
function OnPlayerConnect(Player)
--etc[/code]
And the OPCommands script starts like this:
[code]Hooks.Add("game.command", "OPCommands", OnCommand)
function OnCommand(Player, Command, Arguments)
--etc[/code]
You're adding the hook before the function exists. There are two ways to solve this.
One:
[code]local function something( stuff )
-- do stuff here
end
Hooks.Add( "stuff", "stuff", something )[/code]
Two:
[code]Hooks.Add( "stuff", "stuff", function( stuff )
-- do stuff here
end)[/code]
[QUOTE=Divran;31406462]You're adding the hook before the function exists. There are two ways to solve this.
One:
[code]local function something( stuff )
-- do stuff here
end
Hooks.Add( "stuff", "stuff", something )[/code]
Two:
[code]Hooks.Add( "stuff", "stuff", function( stuff )
-- do stuff here
end)[/code][/QUOTE]
Well that worked. But still, i get this error when i join the game:
[code][WARNING] Lua: Error running function.
[WARNING] attempt to index ? (a nil value)[/code]
Must be the MOTD script. Here's the script:
[code]function OnPlayerConnect(Player)
local PropFile = Files.CreateProp("lua/users/USERNAME")
PropFile:SetInt("Cash", 50)
if Player:IsOp() then
Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!")
PrintToChat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all")
return false
else
Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!")
PrintToChat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all")
return false
end
end
Hooks.Add("player.connect", "MOTD", OnPlayerConnect)[/code]
[QUOTE=Funley;31406223]TOTAL NEW ERROR REPORT.
I took the ExampleScript out, and ran the server. I get these errors:
[code][WARNING] Loading script: MOTD.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid
[WARNING] Loading script: OPCommands.
[WARNING] Lua: Error at Hooks.Add() parameter three was invalid
[WARNING] Lua: Error at Hooks.Add() one of the three parameters are missing or invalid[/code]
The MOTD script starts like this:
[code]Hooks.Add("player.connect", "MOTD", OnPlayerConnect)
function OnPlayerConnect(Player)
--etc[/code]
And the OPCommands script starts like this:
[code]Hooks.Add("game.command", "OPCommands", OnCommand)
function OnCommand(Player, Command, Arguments)
--etc[/code][/QUOTE]
Im looking into it. Seems to only be an issue when multiple scripts are loaded.
[lua]Hooks.Add("game.command", "Manager", function(ply, cmd, arg)
Server.Info(cmd)
end)[/lua]
[code]
I enter: reload
[INFO] eload // Server.Info(cmd)
[INFO] Unknown console command. Type "help" for help.
[/code]
Broken.
You should ditch the garbled mess and do things properly.
Server.Info - seriously?
[QUOTE=Radapalf;31406570]Server.Info - seriously?[/QUOTE]
[lua]function print(str, ...)
Server.Info(string.format(tostring(str), ...))
end[/lua]
I hope he fixes some stuff up..
The standard Lua function "print" works fine as-is for my Bukkit version. I didn't have to change anything. Because of this, I won't be adding a "PrintToConsole" function.
[QUOTE=Divran;31406619]The standard Lua function "print" works fine as-is for my Bukkit version. I didn't have to change anything. Because of this, I won't be adding a "PrintToConsole" function.[/QUOTE]
I'd love to see your version.. but here print, io.write, error and others don't do anything.
It's not ready for any release yet, but when I release the source code, it'd be great if people who are good at Java could make sure I haven't done anything stupid :V
I updated now with a small few fixes.
-print and error work now. ( as to anything either do besides formatting and printing out.. they dont do )
-fixed commands from the console being trimmed of the first character when the command didnt start with a /
[editline]29th July 2011[/editline]
And as well i figured out funley's issue. calls to hooks.add that call a function need to be written after the function has been defined. so:
function DoSomething(somevar)
end
Hooks.Add("game.command", "example", DoSomething)
[QUOTE=Genesis999;31408170]I updated now with a small few fixes.
-print and error work now. ( as to anything either do besides formatting and printing out.. they dont do )
-fixed commands from the console being trimmed of the first character when the command didnt start with a /
[editline]29th July 2011[/editline]
And as well i figured out funley's issue. calls to hooks.add that call a function need to be written after the function has been defined. so:
function DoSomething(somevar)
end
Hooks.Add("game.command", "example", DoSomething)[/QUOTE]
I get this error when im trying to join the game:
[code][WARNING] Lua: Error running function.
[WARNING] lua/MOTD/MOTD.lua:3: vm error: java.lang.NullPointerException[/code]
This is the MOTD script:
[code]function OnPlayerConnect(Player)
if Player:IsOp() then
Player:Print("10^Welcome back, 4^" .. Player:GetUsername() .. "10^!")
PrintToChat("10^Op 4^" .. Player:GetUsername() .. "10^ has joined, say hello!", 10, "#all")
return false
else
Player:Print("10^Welcome, 7^" .. Player:GetUsername() .. "10^!")
PrintToChat("10^Player 7^" .. Player:GetUsername() .. "10^ has joined!", 10, "#all")
return false
end
end
Hooks.Add("player.connect", "MOTD", OnPlayerConnect)[/code]
Jezus, so there are 3 different people working on 3 different lua mods.
Funley the issue you have is due to a small bug that affected everything that uses the colours system. I've fixed it but won't be able to upload till I get back from work.
[QUOTE=Genesis999;31418252]Funley the issue you have is due to a small bug that affected everything that uses the colours system. I've fixed it but won't be able to upload till I get back from work.[/QUOTE]
Ah, thanks!
Okay i think something in Facepunch is broke, i cant go to the page 8! It just throws me to the top of this page.
[QUOTE=Funley;31425088]Ah, thanks!
Okay i think something in Facepunch is broke, i cant go to the page 8! It just throws me to the top of this page.[/QUOTE]
I believe that's because nothing is on it yet.
But I think my post will now be on the eighth page. I think.
[editline]30th July 2011[/editline]
Yup.
[QUOTE=Jacinth;31425134]I believe that's because nothing is on it yet.
But I think my post will now be on the eighth page. I think.[/QUOTE] Well now i got here. Should it even be showing the new page if there is nothing on it?
[editline]30th July 2011[/editline]
Just one more tiny thing, i MAY make the video tutorial on how to use the LuaServer, how can i show YouTube videos here? I have tried the media tags, just shows the URL.
[QUOTE=Funley;31425141]Well now i got here. Should it even be showing the new page if there is nothing on it?
[editline]30th July 2011[/editline]
Just one more tiny thing, i MAY make the video tutorial on how to use the LuaServer, how can i show YouTube videos here? I have tried the media tags, just shows the URL.[/QUOTE]
The new page bug appears if 2 posts get automerged from what I know.
You can show youtube videos in [noparse][hd][/hd][/noparse] tags.
Sorry, you need to Log In to post a reply to this thread.