• Reputation
    3 replies, posted
I am new to lua, so I was wondering if anyone could point out any obvious errors I've made in this script I've been working on. [CODE]local CATEGORY_NAME = "Utility" CreateConVar("ulx_up", 3, FCVAR_ARCHIVE, "Adding reputation to a player.") CreateConVar("ulx_down", 30, FCVAR_ARCHIVE, "Removing reputation from a player.") CreateConVar("ulx_rep", 0, FCVAR_ARCHIVE, "Check your current reputation.") CreateConVar("ulx_reptime", 30, FCVAR_ARCHIVE, "How long before the server adds reputation to a player") if !file.Exists( "ulx", "DATA" ) then file.CreateDir( "ulx" ) end if !file.Exists( "ulx/Reputation", "DATA" ) then file.CreateDir( "ulx/Reputation" ) end --[[ ulx.up( calling_ply, target_ply ) calling_ply : PlayerObject : Player who ran the command. target_ply : PlayerObject : Player who is receiving reputation. This function is the ULX function that allows for a reputation of a player. ]] function ulx.up( calling_ply, target_ply ) if reason and reason ~= "" then ulx.fancyLogAdmin( calling_ply, "#T reputation increased to rep_count (#s)", target_ply ) else reason = nil ulx.fancyLogAdmin( calling_ply, "#A added reputation to #T", target_ply ) end ulx.up( target_ply, calling_ply, reason ) end local rep = ulx.command( CATEGORY_NAME, "ulx up", ulx.up, "!up" ) rep:addParam{ type=ULib.cmds.PlayerArg } rep:addParam{ type=ULib.cmds.StringArg, hint="Add Reputation To This Player", ULib.cmds.optional, ULib.cmds.takeRestOfLine } rep:defaultAccess( ULib.ACCESS_ADMIN ) rep:help( "Add Reputation to a player." ) --[[ ulx.up( target_ply, calling_ply, reason ) target_ply : PlayerObject : Player who receives reputation. calling_ply : PlayerObject : Admin or player who added the reputation rep_count : PlayerObject : Reputation Received This helper function is what adds the reputation to the player's table and calls the save helper function. ]] function ulx.up( target_ply, calling_ply, reason ) if target_ply.reptable == nil then target_ply.reptable = {} end if target_ply.reptable["repcount"] == nil then target_ply.reptable["repcount"] = 0 end if target_ply.reptable["Reputation"] == nil then target_ply.reptable["Reputation"] = {} end table.insert(target_ply.reptable["Reputation"], {os.date(), calling_ply:Nick(), rep}) target_ply.reptable["repcount"] = target_ply.reptable["repcount"] + 1 ULib.tsayColor(target_ply, Color(0,0,0,255), "Rep: " , Color(255,255,255,255), "Your reputation was increased by ", Color(0,0,0,255), "(", Color(0,255,0,255), calling_ply:Nick(), Color(0,0,0,255), ")", Color(255,255,255,255), " ", Color(255,0,0,255), reason) if target_ply.reptable["repcount"] >= GetConVarNumber( "ulx_up" ) then if GetConVarNumber( "ulx_rep" ) == 0 then target_ply.reptable["repcount"] = target_ply.reptable["repcount"] - 1 ulx.RepSave( target_ply ) else local btime = tostring( GetConVarNumber( "ulx_reptime" ) ) target_ply.reptable["repcount"] = target_ply.reptable["repcount"] - 1 ulx.RepSave( target_ply ) end else ulx.RepSave( target_ply ) end end --[[ ulx.DecayRep() This function runs on a timer and adds 1 reputation to a player. The player needs to be playing on the server when this is called to receive reputation. ]] function ulx.DecayRep() print("Reputation Timer Running") for _, pl in pairs ( player.GetAll() ) do if pl.reptable == nil then continue end if pl.reptable["repcount"] == nil then continue end if pl.reptable["repcount"] <= 0 then continue end pl.reptable["repcount"] = pl.reptable["repcount"] + 1 ulx.RepSave( pl ) ULib.tsayColor(pl, Color(0,0,0,255), "Rep: " , Color(255,255,255,255), "Your reputation has been increased for playing. It has been raised by ", Color(255,0,0,255), "1") end timer.Create( "ULX_DecayTimer", GetConVarNumber( "ulx_down" ) * 60, 1, ulx.DecayRep ) end timer.Create( "ULX_DecayTimer", 1, 1, ulx.DecayRep ) --[[ ulx.RepSave( pl ) pl : PlayerObject : Player whos reputations are being saved This helper function saves the player's reputations to a text file for future use. ]] function ulx.RepSave( pl ) local tbl = pl.reptable local SID = pl:SteamID64() toencode = util.TableToJSON(tbl) file.Write("ulx/Reputation/"..SID..".txt", toencode) end --[[ ulx.RepLoad( pl ) pl : PlayerObject : Player whos reputations are being loaded This helper function loads a player's saved reputationss from their file to their player object. ]] function ulx.RepLoad( pl ) local SID = pl:SteamID64() if file.Exists( "ulx/Reputation/" .. SID .. ".txt", "DATA" ) then local todecode = file.Read( "ulx/Reputation/" .. SID .. ".txt", "DATA" ) local tbl = util.JSONToTable( todecode ) pl.reptable = tbl end end hook.Add( "PlayerAuthed", "RepLoad", ulx.RepLoad ) --[[ ulx.rep( calling_ply, target_ply ) calling_ply : PlayerObject : Admin or player who runs the command. target_ply : PlayerObject : Target player whos reputations are being displayed. This function allows an admin or whoever is granted access to see the history of reputations on a target player. ]] function ulx.rep( calling_ply, target_ply ) if not IsValid(calling_ply) then return end if not IsValid(target_ply) then return end if target_ply.reptable == nil then target_ply.reptable = {} end if target_ply.reptable["Reputation"] == nil then ULib.console( calling_ply, "Showing reputation for player: " .. target_ply:Nick() ) ULib.console( calling_ply, "This players reputation is currently zero." ) else ULib.console( calling_ply, "Showing reputation for player: " .. target_ply:Nick() ) ULib.console( calling_ply, "Date By" ) ULib.console( calling_ply, "---------------------------" ) for k, v in pairs( target_ply.reptable[ "Reputation" ] ) do local date = v[1] local by = v[2] line = date .. string.rep(" ", 25 - date:len()) .. by .. string.rep(" ", 35 - by:len()) .. reason ULib.console( calling_ply, line ) end end end local checkrep = ulx.command( CATEGORY_NAME, "ulx checkrep", ulx.checkrep ) checkrep:addParam{ type=ULib.cmds.PlayerArg } checkrep:defaultAccess( ULib.ACCESS_ADMIN ) checkrep:help( "Lists all reputations to console." ) --[[ ulx.down( calling_ply, target_ply, rep_count ) calling_ply : PlayerObject : Admin or player who runs the command. target_ply : PlayerObject : Target player whos reputations are being displayed. rep_count : Integer : Amount of reputation to remove from player. This function will allow an admin to remove active reputations from a target player. ]] function ulx.down( calling_ply, target_ply, rep_count ) if not IsValid(calling_ply) then return end if not IsValid(target_ply) then return end if target_ply.reptable == nil then target_ply.reptable = {} end if target_ply.reptable["repcount"] == nil then ULib.console( calling_ply, "Player " .. target_ply:Nick() .. " has no reputation points.") return end if target_ply.reptable["repcount"] == 0 then ULib.console( calling_ply, "Player " .. target_ply:Nick() .. " has no reputation points.") return end local total_reputation = target_ply.reptable["repcount"] local to_remove = rep_count if to_remove > total_reputation then to_remove = total_reputation end target_ply.reptable["repcount"] = total_reputation - to_remove ulx.fancyLogAdmin( calling_ply, "#S removed removed reputation from #T.", target_ply ) ULib.console( calling_ply, "You removed (" .. to_remove .. ") reputation from " .. target_ply:Nick() .. ". Player current has (" .. target_ply.reptable["repcount"] .. ") reputation points.") end local down = ulx.command( CATEGORY_NAME, "ulx down", ulx.Down ) down:addParam{ type=ULib.cmds.PlayerArg } down:addParam{ type=ULib.cmds.NumArg, hint="reputation to remove" } down:defaultAccess( ULib.ACCESS_ADMIN ) down:help( "Removes reputation from a player." ) --[[ ulx.RemoveReputationHistory( calling_ply, target_ply ) calling_ply : PlayerObject : Adm
Did you test it? If so, what is the error?
This is ULX AWarn with any occurrence of the word 'warn' being changed to 'reputation', not yours.
[QUOTE=Aj;42339984]This is ULX AWarn with any occurrence of the word 'warn' being changed to 'reputation', not yours.[/QUOTE] I didn't say it was mine, and I was suggested to use this to make a reputation system to make it, so I did Also, I don't get any errors, but it doesn't print the reputations.
Sorry, you need to Log In to post a reply to this thread.