• Help with wallet cap
    1 replies, posted
So Im trying to make a money cap for my server. Different ranks will have different caps. My code works, until I try to make it work for more than 1 rank. Could be that my logic is all messed up, but if you could take a look at it and point out my errors I would appreciate it! [CODE]for _,v in pairs( player.GetAll() ) do local cap = 0 rank = v:GetNWString("usergroup") if rank == "moderator" then cap = 100 end if rank == "superadmin" then cap = 10000 end hook.Add("PlayerWalletChanged", "WalletCap", function(ply, amount, total) return math.Min(total + amount, cap) end) hook.Add("Think", "WalletCap", function() for k,v in pairs(player.GetAll()) do if (v:getDarkRPVar("money") > cap) then RunConsoleCommand("rp_setmoney", v:SteamID(), cap) end end end) end[/CODE] It usually just sets the cap to the superadmin one, even if my rank is moderator. Edit: Also this is placed in addons/moneycap/lua/autorun/server/sv_moneycap.lua
[QUOTE=imMrAnarchy;45551285]So Im trying to make a money cap for my server. Different ranks will have different caps. My code works, until I try to make it work for more than 1 rank. Could be that my logic is all messed up, but if you could take a look at it and point out my errors I would appreciate it! [CODE]for _,v in pairs( player.GetAll() ) do local cap = 0 rank = v:GetNWString("usergroup") if rank == "moderator" then cap = 100 end if rank == "superadmin" then cap = 10000 end hook.Add("PlayerWalletChanged", "WalletCap", function(ply, amount, total) return math.Min(total + amount, cap) end) hook.Add("Think", "WalletCap", function() for k,v in pairs(player.GetAll()) do if (v:getDarkRPVar("money") > cap) then RunConsoleCommand("rp_setmoney", v:SteamID(), cap) end end end) end[/CODE] It usually just sets the cap to the superadmin one, even if my rank is moderator. Edit: Also this is placed in addons/moneycap/lua/autorun/server/sv_moneycap.lua[/QUOTE] ewww bad, don't use think hooks, use darkrp hooks for money change, why is it wrapped in a for loop? [code] local ranks = { ["superadmin"] = 1000, ["moderator"] = 100 } hook.Add("PlayerWalletChanged", "LolSorry", function( ply, amount ) if ranks[ply:GetUserGroup()] then if amount > ranks[ply:GetUserGroup()] then ply:setDarkRPVar("money", ranks[ply:GetUserGroup()]) end end end) [/code] Maybe this? Looking at the hook, you might be able to return ranks[ply:GetUserGroup()] instead of setting money, unsure though.
Sorry, you need to Log In to post a reply to this thread.