General > Developers Corner

Admin sounds, tools and other code chat.

<< < (19/31) > >>

jay209015:
Now I'm having a problem with concommand.Add

I typed this ingame.

--- Code: ---AddRule "Test"

--- End code ---

and got this in server console.

--- Code: ---autorun/Ajoin.lua:48: attempt to concatenate local 'args' (a table value)
--- End code ---

This is Line:48

--- Code: ---if string.find( Rules, "<li>" ..args, 1, true ) then
--- End code ---

==EDIT==
Got it :D

--- Code: ---function AddRule( ply, command, RuleA )
Rules = file.Read( "Umotd/rules.txt" )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if string.find( Rules, "<li>" ..Rule, 1, true ) then
Rules = Rules
else
Rules = Rules.. "<li>" ..Rule
file.Write( "Umotd/rules.txt", Rules )
end
else

end
else
print("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
--- End code ---

jay209015:

--- Code: ---Unknown command: AddRule
--- End code ---

--- Code: ---Unknown command: RemoveRule
--- End code ---
Errors above.


--- Code: ---Rules = file.Read( "Umotd/rulest.txt" )
RulesT = util.KeyValuesToTable( Rules )
for k,v in pairs( RulesT.rules ) do
RulesT.rules[tonumber(k)]=v
end
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if string.find( table.concat(RulesT.rules), "<li>" ..Rule, 1, true ) then
Msg("Rule already exists \n")
else
table.insert( RulesT.rules, "<li>" ..Rule )
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
file.Write( "Umotd/rulest.txt", util.TableToKeyValues(RulesT.rules))
end
else

end
else
Msg("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
function RemoveRule( ply, command, RuleB )
if ply:IsValid() then
if ply:IsAdmin() then
RuleN = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT.rules)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT.rules, RuleN )
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
file.Write( "Umotd/rulest.txt", util.TableToKeyValues(RulesT.rules))
else
Msg("Couldn't find the rule mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )

--- End code ---

rulest.txt below


--- Code: ---"Out"
{
"1" "<ol>"
"2" "<li>Test2"
"3" "<li>Test5"
"4" "<li>Test6"
}

--- End code ---

BTW I'm trying to make it handle the table like Uteam does with the Uteam.txt file in the data folder, so my rulest.txt should look like this below, but the rulest.txt was written by the script.



--- Code: ---"Out"
{
     "rules"
     {
     "1" "<ol>"
     "2" "<li>Test2"
     "3" "<li>Test5"
     "4" "<li>Test6"
     }
}

--- End code ---

jay209015:
Not Setting RulesT for somereason.


--- Code: ---if SERVER then
timer.Create( RulesTimer, 1, 0, SetRules )
function SetRules()
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
end
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if  table.HasValue(RulesT, "<li>" ..Rule) then
Msg("Rule already exists \n")
else
table.insert( RulesT, "<li>" ..Rule )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT, " ") )
end
else

end
else
Msg("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
Msg("p4")
function RemoveRule( ply, command, RuleB )
if ply:IsValid() then
if ply:IsAdmin() then
RuleN = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT, (tonumber(RuleN)+1) )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT, " ") )
else
Msg("Couldn't find the rule # mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )
Msg("p5")
else
Msg("Not Server, Ending Script")
timer.Destroy( RulesTimer )
end
--- End code ---

My rulest.txt

--- Code: ---"1" "<ol>"
"2" "<li>Test1"
"3" "<li>Test2"
"4" "<li>Test3"
"5" "<li>Test4"
--- End code ---

jay209015:
No one see anything wrong I guess?

jay209015:
Ok, after looking through the console I found the problem.


--- Code: ---autorun/Rules.lua:2: attempt to index global 'ULib' (a nil value)
======== Installing Table (De)Serialiser Module | ver: 1.4 ========
///////////////////////////////
//      Ulysses Library      //
///////////////////////////////
// Loading...                //
//  shared/defines.lua       //
//  server/hook.lua          //
//  server/gamemode_hooks.lua//
//  shared/misc.lua          //
//  shared/util.lua          //
//  shared/table.lua         //
//  shared/player.lua        //
//  server/player.lua        //
//  shared/messages.lua      //
//  shared/concommand.lua    //
//  server/concommand.lua    //
//  server/util.lua          //
//  shared/sh_ucl.lua        //
//  server/ucl.lua           //
//  server/phys.lua          //
//  server/player_ext.lua    //
//  server/entity_ext.lua    //
// Load Complete!            //
///////////////////////////////
[ULIB] Loading SHARED module: ulx_init.lua
///////////////////////////////
//       ULX Admin Mod       //
///////////////////////////////
// Loading...                //
//  sh_defines.lua           //
//  lib.lua                  //
//  base.lua                 //
//  log.lua                  //
//  MODULE: chat.lua         //
//  MODULE: fun.lua          //
//  MODULE: menus.lua        //
//  MODULE: rcon.lua         //
//  MODULE: slots.lua        //
//  MODULE: teleport.lua     //
//  MODULE: toolmode.lua     //
//  MODULE: user.lua         //
//  MODULE: util.lua         //
//  MODULE: vote.lua         //
//  MODULE: votemap.lua      //
//  MODULE: Umotd_helper.lua //
//  MODULE: userhelp.lua     //
//  end.lua                  //
// Load Complete!            //
///////////////////////////////
[ULIB] Loading SHARED module: umotd_init.lua
///////////////////////////////
//    Ulysses MOTD Revived   //
//        Version 2.A6       //
///////////////////////////////
// Umotd Loaded. Thanks!     //
///////////////////////////////
--- End code ---


--- Code: ---if SERVER then
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
function AddRule( ply, command, RuleA )
if ply:IsValid() then
if ply:IsAdmin() then
Rule = table.concat(RuleA)
if  table.HasValue(RulesT.rules, "<li>" ..Rule) then
Msg("Rule already exists \n")
else
table.insert( RulesT.rules, "<li>" ..Rule )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
end
else

end
else
Msg("Can't execute from console \n")
end
end
concommand.Add( "AddRule", AddRule )
function RemoveRule( ply, command, RuleB )
if ply:IsValid() then
if ply:IsAdmin() then
RuleN = table.concat(RuleB)
if tonumber(RuleN) < table.Count(RulesT.rules)+1 && tonumber(RuleN) > 1 then
table.remove( RulesT.rules, (tonumber(RuleN)+1) )
file.Write("Umotd/rulest.txt", ULib.makeKeyValues(RulesT))
RulesT = (ULib.parseKeyValues( file.Read("Umotd/rulest.txt")))
file.Write( "Umotd/rules2.txt", table.concat(RulesT.rules, " ") )
else
Msg("Couldn't find the rule # mentioned \n")
end
else

end
else
Msg("Can't run from console \n")
end
end
concommand.Add( "RemoveRule", RemoveRule )
else
Msg("Not Server, Ending Script")
end
--- End code ---

Is there a way to make it so that my script doesn't run until after ULib has been loaded?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version