Give Me Points
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

Give Me Points

Started by Madman, 15 February, 2009, 15:49:25

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Madman

-- GiveMePoints 1.2
-- Made by Madman
-- Idea based on a request by rox145 and applaud/smite system on board
--[[
	rox145 request will not be fullfilled by me, since he is running px 3.4?
	Unless you count this script as that. But this script requiers 0.4.1.1
]]--

-- Version 1.1
-- requests by †StIfFLEr†™
-- Added: profile settings for cmds
-- Added: lazy clicks
-- Added: KarmaAll in config
-- Added: all arg to pshow, (!pshow all). Shows all users in list, not top 11

-- Version 1.2
-- Changed: Profile settings for each cmd not all cmds, requested by †StIfFLEr†™
-- Changed: Rightclick changed

-- Version 1.3
-- Lazy Fix: quick rightclick fix


tConfig = {
	Bot = "PointToUsers",
	File = "ItIsGoodToPoint.pnt",
	Idiots = { -- Profiles allowed to use !pgood
		[0] = true,
		[1] = true,
		[2] = true,
		[3] = true,
		[-1] = true,
	},
	Retards = { -- Profiles allowed to use !pbad
		[0] = true,
		[1] = true,
		[2] = true,
		[3] = true,
		[-1] = true,
	},
	ShowOffs = { -- Profiles allowed to use !pshow
		[0] = true,
		[1] = true,
		[2] = true,
		[3] = true,
		[-1] = true,
	},
	LazyMenu = "Give Me Points", -- Right click
	KarmaAll = true, -- Send karma list to all in main
}

Path = Core.GetPtokaXPath().. "scripts/KeepingPoints/"
Givers = "Givers.dat"

Sec = 1000
Min = 60*Sec
Hour = 60*Min

function OnStartup()
	if os.execute('dir "'..Path:gsub("/","\\")..'"') ~= 0 then -- If our folder is not home
		os.execute('mkdir "'..Path:gsub("/","\\")..'"') -- Take it home
	end
	local Life = io.open(Path..tConfig.File) -- Is there life?
	if Life then -- There was!
		Life:close() -- Close the question of life
	else -- There was no life!
		local GiveLife = io.open(Path..tConfig.File,"w+") -- Give us unlimited powers and prepare!
		GiveLife:write('toThePoint = {\n\t["CrazyGuy"] = {\n\t\t["ImNotSoSmart"] = 0,\n\t\t["SantaPleaseBringMePresents"] = 100,\n\t\t["IDoNaughtyThings"] = 1,\n\t}\n}') -- Give life and add some data to life
		GiveLife:close() -- Close the process
	end
	local Child = io.open(Path..Givers) -- Do we have a child
	if Child then -- Yes! Is it a boy?
		Child:close() -- Who knows...
	else -- We want a child
		Man = Path..Givers
		Woman = "w+"
		local HaveSex = io.open(Man,Woman) -- Let's make one
		HaveSex:write('Gave = {\n}') -- And we made it
		HaveSex:close() -- Lets get dressed
	end
	LoadFromFile(Path..tConfig.File) -- Load our life
	LoadFromFile(Path..Givers) -- And the child is home
	-- A cruel, but effective way to calculate the time untill midnight.
	-- Will miss on a minute or so...
	local Time = os.date("%X")
	local M = string.sub(Time,4,-4)
	local H = string.sub(Time,1,-7)
	local cH = 23 - H
	local cM = 60 - M
	childTmr = TmrMan.AddTimer((cH*Hour)+(cM*Min),"RestartChild")
	--Core.SendToAll("!"..tostring(cH..":"..cM))
end

function RestartChild()
	local Child = io.open(Path..Givers,"w+")
	Child:write('Gave = {\n}')
	Child:close()
	TmrMan.RemoveTimer(childTmr)
	childTmr = TmrMan.AddTimer(24*Hour,"RestartChild")
	Core.SendToAll("<" ..tConfig.Bot.. "> It's now possible to give good and bad points again")
	--Core.SendToAll("Child was restarted")
end

tCmds = {
	["pgood"] = function(user,nick)
		if tConfig.Idiots[user.iProfile] then
			if nick then
				if nick ~= user.sNick then -- If we doing someone else
					local DoneIt = false -- We havent done it?
					if Gave[user.sNick] then -- Have we given
						for _,stored in pairs(Gave[user.sNick]["WasNice"]) do
							if stored == nick then -- Aww, we have been nice to that nick allready
								DoneIt = true -- So we Did it
								break
							end
						end
					else
						Gave[user.sNick] = {["WasNice"] = {},["HurtMe"] = {}}
						table.insert(Gave[user.sNick]["WasNice"],nick)
						SaveToFile(Path..Givers,Gave,"Gave")
					end
					if DoneIt then
						Core.SendToUser(user,"<" ..tConfig.Bot.. "> Sorry, you allready gave this user a good point, you have to wait after midnight (hub time), before you can give good point again")
					else
						DoTheTable(nick) -- Do the table
						toThePoint[nick]["SantaPleaseBringMePresents"] = toThePoint[nick]["SantaPleaseBringMePresents"]+ 1
						SaveToFile(Path..tConfig.File,toThePoint,"toThePoint")
						local KissAssText = { nick.. " just received + 1 point in karma! How much did " ..nick.. " pay this time?",
						"+ 1 in karma for " ..nick, "what does " ..nick.. " do to people, + 1 karma",}
						Msg = KissAssText[math.random(table.maxn(KissAssText))] -- Kiss some ass!
						table.insert(Gave[user.sNick]["WasNice"],nick)
						SaveToFile(Path..Givers,Gave,"Gave")
						Core.SendToAll("<" ..tConfig.Bot.. "> " ..Msg) -- Tell everyone we did it!
					end
				else
					DoTheTable(user.sNick) -- Let's do it
					toThePoint[user.sNick]["ImNotSoSmart"] = toThePoint[user.sNick]["ImNotSoSmart"] + 1 -- Plus one on stupid table
					if toThePoint[user.sNick]["ImNotSoSmart"] >= 3 then -- If stupid more then 3
						toThePoint[user.sNick]["IDoNaughtyThings"] = toThePoint[user.sNick]["IDoNaughtyThings"] + 1 -- User is so stuipd that user is bad
					end
					SaveToFile(Path..tConfig.File,toThePoint,"toThePoint")
					Core.SendToUser(user,"<" ..tConfig.Bot.. "> You can't give your self good points")
				end
			else
				Core.SendToUser(user,"<" ..tConfig.Bot.. "> Give points to who?")
			end
		else
			Core.SendToUser(user,"<" ..tConfig.Bot.. "> You can't use this command")
		end
	end,
	["pbad"] = function(user,nick)
		if tConfig.Retards[user.iProfile] then
			if nick then
				if nick ~= user.sNick then
					DoneIt = false
					if Gave[user.sNick] then
						for _,stored in pairs(Gave[user.sNick]["HurtMe"]) do
							if stored == nick then
								DoneIt = true
								break
							end
						end
					else
						Gave[user.sNick] = {["WasNice"] = {},["HurtMe"] = {}}
						table.insert(Gave[user.sNick]["HurtMe"],nick)
						SaveToFile(Path..Givers,Gave,"Gave")
					end
					if DoneIt then
						Core.SendToUser(user,"<" ..tConfig.Bot.. "> Sorry, you allready gave this user a bad point, you have to wait after midnight (hub time), before you can give bad point again")
					else
						DoTheTable(nick)
						toThePoint[nick]["IDoNaughtyThings"] = toThePoint[nick]["IDoNaughtyThings"] + 1
						SaveToFile(Path..tConfig.File,toThePoint,"toThePoint")
						local NotSoNice = { nick.. " has been mean, more bad points for you",
						"Bad bad " ..nick.."! More bad points for you",}
						TellUs = NotSoNice[math.random(table.maxn(NotSoNice))]
						table.insert(Gave[user.sNick]["HurtMe"],nick)
						SaveToFile(Path..Givers,Gave,"Gave")
						Core.SendToAll("<" ..tConfig.Bot.. "> " ..TellUs)
					end
				else
					Core.SendToUser(user, "<" ..tConfig.Bot.. "> Why would you give bad point to yourself")
				end
			else
				Core.SendToUser(user,"<" ..tConfig.Bot.. "> Can not give points, due to user error. Missing nick to give points to")
			end
		else
			Core.SendToUser(user,"<" ..tConfig.Bot.. "> You can't use this command")
		end
	end,
	["pshow"] = function(user,arg)
		if tConfig.ShowOffs[user.iProfile] then
			Vacation = {}
			for nick in pairs(toThePoint) do
				table.insert(Vacation,{["g"] = toThePoint[nick]["SantaPleaseBringMePresents"],["n"] = nick})
				--["b"] = toThePoint[nick]["IDoNaughtyThigns"]
			end
			table.sort(Vacation,function(a,b)
				if a.g > b.g then
					return b.g
				end
			end)
			KarmaBorder = string.rep("=",40)
			ShowMeKarmaInfo = "\r\n\tCurrent top eleven good karma users\r\n\t"..KarmaBorder.."\r\n\tPlace\tGood\tBad\tNick\r\n\t"..KarmaBorder
			ShowMeKarma = ""
			if arg == "all" then
				for i=1,table.maxn(Vacation) do
					if Vacation[i] then
						--ShowMeKarma = ShowMeKarma.."\r\n\t" ..i.. ".\t" ..Vacation[i]["g"].. "\t" ..toThePoint[Vacation[i]["n"]]["IDoNaughtyThings"].. "\t" ..Vacation[i]["n"]
						ShowMeKarma = "\r\n\t" ..i.. ".\t" ..Vacation[i]["g"].. "\t" ..toThePoint[Vacation[i]["n"]]["IDoNaughtyThings"].. "\t" ..Vacation[i]["n"]..ShowMeKarma
					end
				end
			else
				for i=1,11 do
					if Vacation[i] then
						--ShowMeKarma = ShowMeKarma.."\r\n\t" ..i.. ".\t" ..Vacation[i]["g"].. "\t" ..toThePoint[Vacation[i]["n"]]["IDoNaughtyThings"].. "\t" ..Vacation[i]["n"]
						ShowMeKarma = "\r\n\t" ..i.. ".\t" ..Vacation[i]["g"].. "\t" ..toThePoint[Vacation[i]["n"]]["IDoNaughtyThings"].. "\t" ..Vacation[i]["n"]..ShowMeKarma
					end
				end
			end
			ShowMeKarmaMsg = ShowMeKarmaInfo..ShowMeKarma
			if KarmaAll then
				Core.SendToAll("<" ..tConfig.Bot.. "> " ..ShowMeKarmaMsg)
			else
				Core.SendToUser(user,"<" ..tConfig.Bot.. "> " ..ShowMeKarmaMsg)
			end
		else
			Core.SendToUser(user,"<" ..tConfig.Bot.. "> You can't use this command")
		end
	end,
}

function DoTheTable(nick)
	if toThePoint[nick] == nil then -- If nick is not here
		toThePoint[nick] = {["SantaPleaseBringMePresents"]=0,["IDoNaughtyThings"]=0,["ImNotSoSmart"]=0} -- Add nick
	end
end

function ToArrival(user,data)
	local data = data:sub(1,-2)
	local s,e,cmd = data:find("%b<>%s+%p(%S+)")
	if cmd then
		local s,e,nick = data:find("%b<>%s+%p%S+%s+(%S+)")
		if tCmds[cmd] then
			return tCmds[cmd](user,nick),true
		end
	end
end

ChatArrival = ToArrival

tGood = {
	[1] = {"%[line:Nick]","Good point",1},
	[2] = {"%[nick]","Good point",2},
}

tBad = {
	[1] = {"%[line:Nick]","Bad point",1},
	[2] = {"%[nick]","Bad point",2},
}
tShow = {
	[1] = {"","Show Points",3}
	--%[line:all or empty]
}

function UserConnected(user)
	if tConfig.Idiots[user.iProfile] then
		for i in pairs(tGood) do
			Core.SendToNick(user.sNick, "$UserCommand 1 " ..tGood[i][3].. " "..tConfig.LazyMenu.."\\"..tGood[i][2].. "$<%[mynick]> !pgood " ..tGood[i][1].. "&#124;|")
		end
	end
	if tConfig.Retards[user.iProfile] then
		for i in pairs(tBad) do
			Core.SendToNick(user.sNick, "$UserCommand 1 " ..tBad[i][3].. " "..tConfig.LazyMenu.."\\"..tBad[i][2].. "$<%[mynick]> !pbad " ..tBad[i][1].. "&#124;|")
		end
	end
	if tConfig.ShowOffs[user.iProfile] then
		for i in pairs(tShow) do
			Core.SendToNick(user.sNick, "$UserCommand 1 " ..tShow[i][3].. " "..tConfig.LazyMenu.."\\"..tShow[i][2].. "$<%[mynick]> !pshow " ..tShow[i][1].. "&#124;|")
		end
	end
end

OpConnected = UserConnected
RegConnected = UserConnected

Serialize = function(tTable, sTableName, sTab)
	assert(tTable, "tTable equals nil");
	assert(sTableName, "sTableName equals nil");
	assert(type(tTable) == "table", "tTable must be a table!");
	assert(type(sTableName) == "string", "sTableName must be a string!");
	sTab = sTab or "";
	sTmp = ""
	sTmp = sTmp..sTab..sTableName.." = {\n"
	for key, value in pairs(tTable) do
		local sKey = (type(key) == "string") and string.format("[%q]",key) or string.format("[%d]",key);
		if(type(value) == "table") then
			sTmp = sTmp..Serialize(value, sKey, sTab.."\t");
		else
			local sValue = (type(value) == "string") and string.format("%q",value) or tostring(value);
			sTmp = sTmp..sTab.."\t"..sKey.." = "..sValue
		end
		sTmp = sTmp..",\n"
	end
	sTmp = sTmp..sTab.."}"
	return sTmp
end

SaveToFile = function(file , table , tablename)
	local handle = io.open(file,"w+")
	handle:write(Serialize(table, tablename))
	handle:flush()
	handle:close()
end

LoadFromFile = function(filename)
	local f = io.open(filename)
	if f then
		local r = f:read("*a")
		f:flush()
		f:close()
		local func,err = loadstring(r)
		if func then x,err = pcall(func) end
	end
end


This happens when i have to much free time...
I think it should work as i want it to ;p
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

thanks madman its description is same as i wanted few days back.
I had once requested for the same type of script. thanks a lot for making it. will look into it soon.

?StIfFLEr??

Script working great madman.
Few requests.
1 profile permissions who can use the script to give good and bad points.
2 Show command for everyone
3 right click function.

Madman

We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

!pshow command to see the karma of all the users for every1

Madman

Still don't understand exactly what you want
But i added 2 options 2 show cmd, KarmaAll in config and the arg all to pshow
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

Sorry my mistake could not make it clear was in bit hurry.
Till now the scripts looks great with new updates.
The profile permission is for all the commands in the script as per profile.
The only thing i wanted is that profile like operators and vips and masters can give good/bad points to users.
where the command !pshow should be available to all the users.
I am personally requesting this because some people misuse such points scripts for their own good so i want the points giving rights to be in good hands.
I hope i tried to explain most of the part.

Madman

#7
Okey, that I understood perfectly.
now config have profile permissions tabels for each cmd.

Ops, forgot the RC... brb

*Edit*

RC changed to fit update ;p
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

The pshow command
Quote========================================
   Place   Good   Bad   Nick
   ========================================
   4.   1   0   holmes
   3.   1   0   Dave
   2.   1   0   ?MuTHuBOi??
   1.   100   1   CrazyGuy
can it be made in acending order?(1,2,3,4...)
Moreover RC commands for reg profile are not working/has some problems.
The profile permissions are kept as
QuoteIdiots = { -- Profiles allowed to use !pgood
      
  • = true,
          [1] = true,
          [2] = false,
          [3] = false,
          [-1] = false,
       },
       Retards = { -- Profiles allowed to use !pbad
          
  • = true,
          [1] = true,
          [2] = false,
          [3] = false,
          [-1] = false,
       },
       ShowOffs = { -- Profiles allowed to use !pshow
          
  • = true,
          [1] = true,
          [2] = true,
          [3] = true,
          [-1] = true,
       },
The rest of the script is working awesome.
Thanks for the update.

Madman

rightclick tested and fixed.

As for the change of the sort. I want it to sort that way, so i wont add a switch for it,
But ofcourse you can change it manually.
At the pshow cmd there is 4 lines that start ShowMeKarma = (line 209,210,216,217).
Currently 209 and 216 is --commented, change that so, 210 and 217 is commented instead
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

Thanks a lot Madman.
This way i can learn more about scripting.
May i post my errors after editing if u can guide me to get it right?
Thanks a lot for the fixed update.

Madman

np. ofcourse, just post the errors and i'll help...
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

?StIfFLEr??

QuoteKarmaBorder = string.rep("=",40)
         ShowMeKarmaInfo = "\r\n\tCurrent top eleven good karma users\r\n\t"..KarmaBorder.."\r\n\tPlace\tGood\tBad\tNick\r\n\t"..KarmaBorder
         ShowMeKarma = ""
         if arg == "all" then
            for i=1,table.maxn(Vacation) do
               if Vacation then
                  --ShowMeKarma = ShowMeKarma.."\r\n\t" ..i.. ".\t" ..Vacation["g"].. "\t" ..toThePoint[Vacation["n"]]["IDoNaughtyThings"].. "\t" ..Vacation["n"]
                  ShowMeKarma = "\r\n\t" ..i.. ".\t" ..Vacation["g"].. "\t" ..toThePoint[Vacation["n"]]["IDoNaughtyThings"].. "\t" ..Vacation["n"]..ShowMeKarma
               end
            end
         else
            for i=1,11 do
               if Vacation then
                  --ShowMeKarma = ShowMeKarma.."\r\n\t" ..i.. ".\t" ..Vacation["g"].. "\t" ..toThePoint[Vacation["n"]]["IDoNaughtyThings"].. "\t" ..Vacation["n"]
                  ShowMeKarma = "\r\n\t" ..i.. ".\t" ..Vacation["g"].. "\t" ..toThePoint[Vacation["n"]]["IDoNaughtyThings"].. "\t" ..Vacation["n"]..ShowMeKarma
               end
            end
         end
         ShowMeKarmaMsg = ShowMeKarmaInfo..ShowMeKarma
Madman is this the place where change is needed?

Madman

yes, the 2 lines starting with --  is the lines you want. set -- to the lines bellow them and remove the current --
We suffer in silence, we lurk in the shadows, we kill in the night
Site currently down, ETA of returning online is 2099 ;p

SMF spam blocked by CleanTalk