• Print

Author Topic: Admin sounds, tools and other code chat.  (Read 95065 times)

0 Members and 1 Guest are viewing this topic.

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #150 on: June 02, 2008, 01:38:23 am »
Adding more to the script from above, I'm trying to have server promotions based on the players total time in the server while they have not had a warning lvl.

Players_Time.txt:
Code: [Select]
"players"
{
"STEAM_0:1:13630765"
{
"time"
{
"0"
}
}
}

Promotions.lua:
Code: Lua
  1. Promotion_Inerval = 2 // Time in hours
  2. Time_Reduction = 10 // Time lost in minutes per warning level
  3.  
  4.  
  5. Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
  6.  
  7.  
  8. function PromotionInit( ply )
  9.         timer.Create( ply:Nick().. "Promotion_Timer", 1, 0, SetTime, ply)
  10.         ply.Last_Check = 0
  11.                 for _, Id in pairs(Player_Time_Table.players) do
  12.                         if string.find( Id, ply:SteamID(), 1, true) then
  13.                                 ply.total_time = Player_Time_Table.players.ply:SteamID().time
  14.                         else
  15.                                 ply.total_time = 0
  16.                         end
  17.                 end
  18. end
  19. hook.Add( "PlayerInitialSpawn", "PromotionInit_Hook", PromotionInit )
  20.  
  21. function SetTime( ply )
  22.         ply.total_time = (ply.total_time + 1)
  23.         table.insert( Player_Time_Table.players.ply:SteamID().time, 1, ply.total_time)
  24.         file.Write( "Player_Times.txt", ULib.makeKeyValues(Players_Time_Table))
  25. end
  26.  
  27.  
  28. function Warn_Think()
  29.         for _, ply in pairs( player.GetAll() ) do
  30.                 if ply.warn > 0 then
  31.                         if timer.IsTimer( ply:Nick().. "Promotion_Timer" ) then
  32.                                 timer.Stop( ply:Nick().. "Promotion_Timer" )
  33.                         end
  34.                 else
  35.                         if timer.IsTimer( ply:Nick().. "Promotion_Timer" ) then
  36.                                 timer.Start( ply:Nick().. "Promotion_Timer" )
  37.                         end
  38.                 end
  39.                 if (ply.warn > 5) and (!ply.warn == ply.Last_Check) then
  40.                         if (!ply.total_time == 0) then
  41.                                 ply.total_time = (ply.total_time - (ply.warn * Time_Reduction))
  42.                                 ply.Last_Check = ply.warn
  43.                                         if ply.total_time < 0 then
  44.                                                 ply.total_time = 0
  45.                                         end
  46.                         end
  47.                 end
  48.         end
  49. end
  50. timer.Create( "ThinkTimer_Warn", 1, 0, Warn_Think)

Error:
Code: [Select]
Timer Error: ULib/modules/Promotions.lua:22: attempt to perform arithmetic on fi
eld 'total_time' (a nil value)
That's with me in the server, I realize I didn't add the PlayerDisconnected hook to Destroy the timer yet.
Um... Warn_Think is working as it should, but the total_time isn't getting set, and I need that inorder to go any further in this script. I don't see anything wrong, but I've been know to miss the little to medium problems :S.
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #151 on: June 02, 2008, 11:49:20 pm »
Ok, wow. There were alot of errors in that last script, so here's the new one.

Promotions.lua:
Code: Lua
  1. Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
  2. Msg("Table Created and set \n")
  3.  
  4. function PromotionInit( ply )
  5.         Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
  6.         ply.Last_Check = 0
  7.                 for _, Id in pairs(Player_Time_Table.players) do
  8.                         if string.find( Id, ply:Nick(), 1, true) then
  9.                        
  10.                         else
  11.                                 Player_Time_Table.players.ply:Nick() = {}
  12.                                 Player_Time_Table.players.ply:Nick().time = 0
  13.                         end
  14.                 end
  15. end
  16. hook.Add( "PlayerInitialSpawn", "PromotionInit_Hook", PromotionInit )

Player_Times.txt:
Code: [Select]
"players"
{
"Jay209015"
{
"time" 20
}
"TestPlayer"
{
"time" 0
}
}

Jay209015 was entered straight into the text file by me, but test players was entered in with:

Code: [Select]
Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
lua_run Player_Time_Table.players.TestPlayer = {}
lua_run Player_Time_Table.players.TestPlayer.time = 0

in that order. After the server starts Player_Time_Table = nil for somereason, even if the tables are in the text file.

Code: [Select]
> PrintTable(Player_Time_Table)...
includes\util.lua:21: bad argument #1 to 'pairs' (table expected, got nil)

==EDIT==

More to the errors list:
Code: [Select]
ULib/modules/Promotions.lua:14: unexpected symbol near '='
ULib/modules/Promotions.lua:14: unexpected symbol near '='
-- Error SENDING CLIENTSIDE file -------------------------
- File: ULib/modules/Promotions.lua
----------------------------------------------------------
« Last Edit: June 03, 2008, 12:57:13 am by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #152 on: June 03, 2008, 02:04:54 am »
Code: Lua
  1. Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
  2. Msg("Table Created and set \n")
  3.  
  4. function PromotionInit( ply )
  5.         ply.Last_Check = 0
  6.                 if !(util.tobool(Player_Time_Table.playersJay209015.time)) then
  7.                         Player_Time_Table.players.Jay209015 = { time = 0}
  8.                 end
  9.                 timer.Create(ply:Nick().. "Promotion_Timer", 1, 0, SetTime, ply)
  10. end
  11. hook.Add( "PlayerInitialSpawn", "PromotionInit_Hook", PromotionInit )
  12.  
  13. function SetTime( ply )
  14.         Player_Time_Table.players.Jay209015.time = Player_Time_Table.players.Jay209015.time + 1
  15.         file.Write( "Player_Times.txt", ULib.makeKeyValues(Player_Time_Table))
  16. end

Above works fine, but below does not.

Code: Lua
  1. Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
  2. Msg("Table Created and set \n")
  3.  
  4. function PromotionInit( ply )
  5.         ply.Last_Check = 0
  6.                 if !(util.tobool(Player_Time_Table.players.ply:Nick().time)) then
  7.                         Player_Time_Table.players.ply:Nick() = { time = 0}
  8.                 end
  9.                 timer.Create(ply:Nick().. "Promotion_Timer", 1, 0, SetTime, ply)
  10. end
  11. hook.Add( "PlayerInitialSpawn", "PromotionInit_Hook", PromotionInit )
  12.  
  13. function SetTime( ply )
  14.         Player_Time_Table.players.ply:Nick().time = Player_Time_Table.players.ply:Nick().time + 1
  15.         file.Write( "Player_Times.txt", ULib.makeKeyValues(Player_Time_Table))
  16. end

Server side error:
Code: [Select]
ULib/modules/Promotions.lua:11: unexpected symbol near '='
ULib/modules/Promotions.lua:11: unexpected symbol near '='
-- Error SENDING CLIENTSIDE file -------------------------
- File: ULib/modules/Promotions.lua
----------------------------------------------------------

Client side error:
Code: [Select]
ULib/_cl_2.20/misc.lua:38: bad argument #1 to 'gsub' (string expected, got nil)


is there something else I can use other than ply:Nick() to get the players name and have it work in a table?
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

Offline jay209015

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 934
  • Karma: 62
    • Dev-Solutions
Re: Admin sounds, tools and other code chat.
« Reply #153 on: June 03, 2008, 06:33:41 pm »
Ok, after a bit of research I fixed the problem from above, but the new one is confusing.

All was good until my server was completely restarted. Now it does something really wierd.

Player_Time.txt:
Code: [Select]
"players"
{
"TestPlayer"
{
"time" 0
}
}

lua_run PrintTable(Player_Time_Table):
Code: [Select]
???^*#1:
                TestPlayer:
                                time    =       0

Code that rights this table.
Code: [Select]
Player_Time_Table = (ULib.parseKeyValues( file.Read("Player_Times.txt")))
Msg("Table Created and set \n")

verification table was set:
Code: [Select]
[ULIB] Loading module: Promotions.lua
Table Created and set

Only error reported:
Code: [Select]
ERROR: Hook 'PromotionInit_Hook' Failed: ULib/modules/Promotions.lua:13: attempt
 to index field 'players' (a nil value)
Removing Hook 'PromotionInit_Hook'

Function of the hook mentioned above:
Code: Lua
  1. function PromotionInit( ply )
  2.         ply.Last_Check = 0
  3.                 if Player_Time_Table.players[ply:Nick()] == nil then
  4.                         Player_Time_Table.players[ply:Nick()] = { time = 0 }
  5.                 end
  6.                 if !ply:IsAdmin() and !ply:IsSuperAdmin() then
  7.                         if ply:IsUserGroup( "user" ) then
  8.                                 ply.promotionlvl = 0
  9.                         else
  10.                                 if ply:IsUserGroup( "mod" ) then
  11.                                         ply.promotionlvl = 1
  12.                                 else
  13.                                         if ply:IsUserGroup( "respected" ) then
  14.                                                 ply.promotionlvl = 2
  15.                                         else
  16.                                                 if ply:IsUserGroup( "operator" ) then
  17.                                                         ply.promotionlvl = 3
  18.                                                 end
  19.                                         end
  20.                                 end
  21.                         end
  22.                 end
  23.                 timer.Create(ply:Nick().. "Promotion_Timer", 1, 0, SetTime, ply)
  24. end
  25. hook.Add( "PlayerInitialSpawn", "PromotionInit_Hook", PromotionInit )

It's obvious why the hook is broken, but not the reason that the "players" changes to "???^*#1" this is the wierdest errors I've seen so far. Any suggestions/idea on how to fix or as to why this is happening?

==EDIT==
Got this error on client:
Code: [Select]
Client side error:
[code]
ULib/_cl_2.20/misc.lua:38: bad argument #1 to 'gsub' (string expected, got nil)
[/code]

Line 38 from the error above:
Code: [Select]
str = string.gsub( str, ULib.makePatternSafe( comment ) .. "[%S \t]*", "" )


« Last Edit: June 03, 2008, 06:42:19 pm by jay209015 »
An error only becomes a mistake when you refuse to correct it. --JFK

"And thus the downfall of the great ULX dynasty was wrought not by another dynasty, but the slow and steady deterioration of the leaders themselves, followed by the deprecation of the great knowledge they possessed." -Gmod, Chapter 28, verse 34 -- Stickly

  • Print