Two Script in One.Please Help
 

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

Two Script in One.Please Help

Started by James, 01 May, 2005, 08:16:57

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

James

Hey guy`s!

Trivia Ex Quiss Bot in Combination with Simple Gag Bot !!

 Is it possible to change the Trivia-Ex bot , so that  anybody anwering 12 question in a row without receiving any hints or help will be banned by the gag rule of this hub from main chat for about 30min.there are just to many chaps in here who already know all the answers by heart. those same chaps are taking the fun out the quiz for the new users who havnt played the trivia yet. so please be fair, let others play too, or get caught and be banned.

Example:

if (self.streak == 12) then
            TrivEx:SendToPlayers(nick.." *!gag/mute* ??? ;), "..self.streak.." runs in a row. Amazing.")
         elseif (self.streak == 9) then
            TrivEx:SendToPlayers("ey "..nick.."Warning No 2")
         elseif (self.streak == 5) then
            TrivEx:SendToPlayers("ey "..nick.."Warning No 1")
         elseif (self.streak == 1) then
            TrivEx:SendToPlayers(nick..", that makes "..self.streak.." runs in a row.")
         
The Warning is ok...works
The Gag/Mute is not ok

  Thanks in Advance

James

nothing? or not possible ?

jiten

Well, the "smart guy" will be gagged when he reaches a streak of 12 and that gag can be removed with the "!iungag" command. Hope this helps you...

Add this to your lua file:
sGag = {}

TrivEx._Cmds.iungag = TrivEx.UnGag			-- Ungags a user

function TrivEx:UnGag(curUser,data)
	if self:AllowedProf("Config+",curUser) then
		local s,e,v = string.find(data,"%b<>%s+%S+%s+(%S+)") 
		local victim = GetItemByName(v) 
		if victim == nil then 
			self:SendToUser(curUser,"User is not in the hub.") 
		else 
			if sGag[victim.sName] == 1 then 
				sGag[victim.sName] = nil; 
				TrivEx:SendToPlayers(victim.sName.." was ungagged for knowing all the answers by heart.")
				TrivEx:WriteTable(sGag,"sGag","gagged.tbl")
			else
				self:SendToUser(curUser,victim.sName.." wasn?t gagged.") 
			end
		end 
	end
end
and replace your old functions with these:
function TrivEx:ParseData(mode,curUser,data)

	self._datamode = mode
	data = string.sub(data,1,string.len(data)-1)
	local _,_,sdata = string.find( data, "^%b<>%s(.*)$")
	local _,_,cmd = string.find( data, "^%b<>%s["..self._Sets.prefixes.."](%w+)")
	if cmd then
		cmd = string.lower(cmd)
		if self._Cmds[cmd] then
			self._Cmds[cmd](self,curUser,data)
			return 1
		end
	elseif sdata then
		local corrans = table.foreachi(curTriv.ans, function(_,v)
			if string.lower(sdata) == string.lower(v) then
				return (v)
			end
		end)
		if sGag[curUser.sName] == 1 then
			return 1
		end
		if corrans and (not curTriv:GetGetQues()) then
			-- SetGetQues
			curTriv:SetGetQues(1)
			local ansTime = string.format("%.2f",(os.clock()-curTriv.start)) -- Get Answering Time in sec.
			if (TrivEx._Sets.showcorrectanswer == 1) then
				-- Show right answer
				local talked = nil
				if string.find( sdata, corrans ) then
					talked = corrans
				end
				if talked then
					if not (self:GetPlayMode() == "pm") then
						SendToAll(curUser.sName,corrans)
					end
					self:SendToPlayers("Correct "..curUser.sName.." the answer was \""..corrans.."\", You get "..curTriv.points.." Point(s). Answer solved in "..ansTime.." sec.")
					-- Show other answeres if present
					if curTriv.availans > 1 then
						curTriv:ShowAnswer()
					end
					-- Update Scores
					if self._Scores[curUser.sName] then
						self._Scores[curUser.sName].Score = self._Scores[curUser.sName].Score + curTriv.points
						self._Scores[curUser.sName].AvTime[1] = self._Scores[curUser.sName].AvTime[1] + ansTime
						self._Scores[curUser.sName].AvTime[2] = self._Scores[curUser.sName].AvTime[2] + 1
						self._Scores[curUser.sName].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sName].AvTime[1]/self._Scores[curUser.sName].AvTime[2]))
					else
						self._Scores[curUser.sName] = {}
						self._Scores[curUser.sName].Score = curTriv.points
						self._Scores[curUser.sName].Streak = 1
						self._Scores[curUser.sName].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
					end
					if (self._Sets.showcorrectanswer == 1) then
						self:SendToPlayers(curUser.sName.."'s Stats, Score: "..self._Scores[curUser.sName].Score.." Point(s), Answerd Questions: "..self._Scores[curUser.sName].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sName].AvTime[3]).." sec.")
					end
					-- Check for Streak
					curTriv.streak:UpdStreak(curUser)
					return 1
				end
			elseif (TrivEx._Sets.showcorrectanswer == 2) then
				-- Show right answer
				local talked = nil
				if string.find( sdata, corrans ) then
					talked = corrans
				end
				if talked then
					if not (self:GetPlayMode() == "pm") then
						SendToAll(curUser.sName,corrans)
					end
					self:SendToPlayers("Correct "..curUser.sName.." the answer was \""..corrans.."\", You get "..curTriv.points.." Point(s).")
					-- Show other answeres if present
					if curTriv.availans > 1 then
						curTriv:ShowAnswer()
					end
					-- Update Scores
					if self._Scores[curUser.sName] then
						self._Scores[curUser.sName].Score = self._Scores[curUser.sName].Score + curTriv.points
						self._Scores[curUser.sName].AvTime[1] = self._Scores[curUser.sName].AvTime[1] + ansTime
						self._Scores[curUser.sName].AvTime[2] = self._Scores[curUser.sName].AvTime[2] + 1
						self._Scores[curUser.sName].AvTime[3] = tonumber(string.format("%.2f",self._Scores[curUser.sName].AvTime[1]/self._Scores[curUser.sName].AvTime[2]))
					else
						self._Scores[curUser.sName] = {}
						self._Scores[curUser.sName].Score = curTriv.points
						self._Scores[curUser.sName].Streak = 1
						self._Scores[curUser.sName].AvTime = { tonumber(ansTime),1,tonumber(ansTime) }
					end
					if (self._Sets.showcorrectanswer == 1) then
						self:SendToPlayers(curUser.sName.."'s Stats, Score: "..self._Scores[curUser.sName].Score.." Point(s), Answerd Questions: "..self._Scores[curUser.sName].AvTime[2]..", Average Answering Time: "..string.format("%.2f",self._Scores[curUser.sName].AvTime[3]).." sec.")
					end
					-- Check for Streak
					curTriv.streak:UpdStreak(curUser)
					return 1
				end
			end

		elseif (self:GetPlayMode() == "pm") then
			self:SendToPlayers(data,curUser)
		end

	end

end

curTriv.streak.UpdStreak = function(self,curUser)

	if curUser then
		-- Write Scores by next saving
		curTriv.streak.write_scores = 1
		-- Set Unanswered Questions to zero
		curTriv.unansques = 0
		local nick = curUser.sName
		if (self.nick == nick) then
			self.streak = self.streak + 1
			if (self.streak > TrivEx._Scores[curUser.sName].Streak)  then
				TrivEx:SendToPlayers(nick..", you broke your current run of "..TrivEx._Scores[curUser.sName].Streak..".")
				TrivEx._Scores[curUser.sName].Streak = self.streak
			end
			if (self.streak == 12) then
				if sGag[nick] == nil then 
					sGag[nick] = 1 
					TrivEx:SendToPlayers(nick.." was gagged for knowing all the answers by heart.")
					TrivEx:WriteTable(sGag,"sGag","gagged.tbl")
				end
			elseif (self.streak == 9) then
				TrivEx:SendToPlayers("ey "..nick.."Warning No 2") 
			elseif (self.streak == 6) then
				TrivEx:SendToPlayers("And the miracle continues, "..nick.." that makes "..self.streak.." runs in a row now.")
			elseif (self.streak == 5) then
				TrivEx:SendToPlayers("ey "..nick.."Warning No 1") 
			elseif (self.streak == 3) then
				TrivEx:SendToPlayers(nick..", that makes "..self.streak.." runs in a row.")
			end
		else
			if (self.streak >= 12) then
				TrivEx:SendToPlayers("And "..nick.." ends "..self.nick.." miracle of "..self.streak.." runs in a row. Ole!")
			elseif (self.streak >= 9) then
				TrivEx:SendToPlayers(nick.." *applause*, was about time to break, "..self.nick.."'s "..self.streak.." runs in a row.")
			elseif (self.streak >= 6) then
				TrivEx:SendToPlayers("Beat it "..self.nick..", "..nick.." just set and end to your "..self.streak.." runs in a row.")
			elseif (self.streak >= 3) then
				TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
			end
			self.nick = nick
			self.streak = 1
		end
	else
		if (self.nick ~= "") then
			if (self.streak >= 12) then
				TrivEx:SendToPlayers("Well that was obvious, that this questions would end "..self.nick.."'s run of "..self.streak.." ;)")
			elseif (self.streak >= 9) then
				TrivEx:SendToPlayers(self.nick.." say 'good bye' to your run of "..self.streak)
			elseif (self.streak >= 3) then
				TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
			end
		end
		self.nick = ""
		self.streak = 0
	end
end
Best regards,

jiten

James

Thanks jiten ...-)))  but ...

if i change it, trivia quiz will not work... or im doing something wrong?... can you give me the whole changed trivia quizbot?

Thanks in advance -)))

jiten

QuoteOriginally posted by James
Thanks jiten ...-)))  but ...

if i change it, trivia quiz will not work... or im doing something wrong?... can you give me the whole changed trivia quizbot?

Thanks in advance -)))
Ok, I'll post the whole script here later today.
Btw, check the allowed profiles in the script.
That could be the reason also.

Best regards

jiten

Grab the stand-alone Lua file here.

Best regards,

jiten

James

^^  no syntax error
          but
 ^^ no works ;(

jiten

QuoteOriginally posted by James
^^  no syntax error
          but
 ^^ no works ;(
What PtokaX version are u using?
I tried the script some minutes ago and it worked perfectly (PtokaX build 17.03 debug).
Btw, check ur profile settings in the script too.

Cheers

James

ufff...16.05   ...   have LavMaker @ this works not with 17.03

jiten

#9
QuoteOriginally posted by James
ufff...16.05   ...   have LavMaker @ this works not with 17.03
Tried it with 16.05 and it worked.
Open ur .lua file and replace the profile part with this:
TrivEx._Profiles.Normal = {
	[0] = "Master",
	[1] = "Operator",
	[2] = "VIP",
	[3] = "Reg",
	[4] = "Moderator",
	[5] = "NetFounder",
	[-1] = "Noobs",
}

TrivEx._Profiles.Config = {
	[0] = "Master",
	[1] = "Operator",
	[2] = "VIP",
	[3] = "Reg",
	[4] = "Moderator",
	[5] = "NetFounder",
}

TrivEx._Profiles["Config+"] = {
	[0] = "Master",
	[1] = "Operator",
	[4] = "Moderator",
	[5] = "NetFounder",
}
If I'm not wrong, u haven't added the extra profiles of LawMaker in the TriviaEx tables.
Not sure of them so I just added robocop ones. Change at will. It will certainly work after this.

Cheers

bastya_elvtars

QuoteOriginally posted by jiten
If I'm not wrong, u haven't added the extra profiles of LawMaker in the TriviaEx tables.

Cheers

You are wrong, because LawMaker uses the default profiles, however I don't know whether Triv has them as defaults.  ;)
Everything could have been anything else and it would have just as much meaning.

James

LOOOOOL

I'm so stupid. The changed TriviaQuiss does work with ptoka 16.05, with 17.03 and lawmaker too. But I had the Quiss on autmaticstart so I never thought about turning it on with !triviastart *ashamed* . Very good work.

          thank you. ;)

jiten

QuoteOriginally posted by James
LOOOOOL

I'm so stupid. The changed TriviaQuiss does work with ptoka 16.05, with 17.03 and lawmaker too. But I had the Quiss on autmaticstart so I never thought about turning it on with !triviastart *ashamed* . Very good work.

          thank you. ;)
Glad to hear that it's working :]

Best regards,

jiten

James

Is it possible to change The Gag/Mute in Gag on Time ?
  Example   after 5 or 10 Min automaticaly ungag ?

James

in Your script jiten '' ungag ''not works...

Change this please :

TrivEx._Cmds.1ungag = TrivEx.UnGag

To this

TrivEx._Cmds.ungag = TrivEx.UnGag

now works the ungag-)))

Is possible to add the Timegag ???  ;)

jiten

Well, it's possible. Add this to ur script:
TrivEx._Sets.gtime = 1						-- After this period in minutes, the gagged user is automatically ungagged

and replace your functions with these:
curTriv.streak.UpdStreak = function(self,curUser)

	if curUser then
		-- Write Scores by next saving
		curTriv.streak.write_scores = 1
		-- Set Unanswered Questions to zero
		curTriv.unansques = 0
		local nick = curUser.sName
		if (self.nick == nick) then
			self.streak = self.streak + 1
			if (self.streak > TrivEx._Scores[curUser.sName].Streak)  then
				TrivEx:SendToPlayers(nick..", you broke your current run of "..TrivEx._Scores[curUser.sName].Streak..".")
				TrivEx._Scores[curUser.sName].Streak = self.streak
			end
			if (self.streak == 12) then
				if sGag[nick] == nil then 
					sGag[nick] = TrivEx._Sets.gtime*60
					TrivEx:SendToPlayers(nick.." was gagged for knowing all the answers by heart.")
					TrivEx:WriteTable(sGag,"sGag","gagged.tbl")
				end
			elseif (self.streak == 9) then
				TrivEx:SendToPlayers("ey "..nick.."Warning No 2") 
			elseif (self.streak == 6) then
				TrivEx:SendToPlayers("And the miracle continues, "..nick.." that makes "..self.streak.." runs in a row now.")
			elseif (self.streak == 5) then
				TrivEx:SendToPlayers("ey "..nick.."Warning No 1") 
			elseif (self.streak == 2) then
				TrivEx:SendToPlayers(nick..", that makes "..self.streak.." runs in a row.")
			end
		else
			if (self.streak >= 12) then
				TrivEx:SendToPlayers("And "..nick.." ends "..self.nick.." miracle of "..self.streak.." runs in a row. Ole!")
			elseif (self.streak >= 9) then
				TrivEx:SendToPlayers(nick.." *applause*, was about time to break, "..self.nick.."'s "..self.streak.." runs in a row.")
			elseif (self.streak >= 6) then
				TrivEx:SendToPlayers("Beat it "..self.nick..", "..nick.." just set and end to your "..self.streak.." runs in a row.")
			elseif (self.streak >= 3) then
				TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
			end
			self.nick = nick
			self.streak = 1
		end
	else
		if (self.nick ~= "") then
			if (self.streak >= 12) then
				TrivEx:SendToPlayers("Well that was obvious, that this questions would end "..self.nick.."'s run of "..self.streak.." ;)")
			elseif (self.streak >= 9) then
				TrivEx:SendToPlayers(self.nick.." say 'good bye' to your run of "..self.streak)
			elseif (self.streak >= 3) then
				TrivEx:SendToPlayers("There goes "..self.nick.."'s run of "..self.streak)
			end
		end
		self.nick = ""
		self.streak = 0
	end
end

function TrivEx:OnTimer()

	-- Load Questions if needed
	if (table.getn(self._Questions) == 0) then
		self:LoadQuestions()
	end
	-- Check if Trivia should be paused
	if (self._Sets.dobreak == 1) then
		if (not curTriv:Pause()) then
			-- Update TimeBreak
			TrivTimers.timebreak = TrivTimers.timebreak + 1
			if (TrivTimers.timebreak >= self._Sets.timebreak) and curTriv:GetGetQues() then
				curTriv:SetPause(1)
				TrivTimers.timebreak = 0
				TrivTimers.breaktime = 0
				self:SendToPlayers("Short Trivia break for "..(self._Sets.breaktime/60).." min.")
			end
		end
		if curTriv:Pause() then
			-- Update BreakTime
			TrivTimers.breaktime = TrivTimers.breaktime + 1
			if (TrivTimers.breaktime >= self._Sets.breaktime) then
				curTriv:SetPause(0)
				TrivTimers.timebreak = 0
				TrivTimers.breaktime = 0
				TrivTimers.showques = 0
			end
		end
	end
	-- Check if Trivia should be Autostoped
	if curTriv:GetGetQues() then
		if self._Sets.autostop and (curTriv.unansques == self._Sets.autostop) then
			StopTimer()
			curTriv:SetGetQues(1)
			self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..TrivEx._Sets.ScoresFile)
			self:SendToPlayers("Trivia stopped due to Autostop, "..self._Sets.autostop.." questions weren't answered in a row.")
			return
		end
	end
	if (not curTriv:Pause()) then
		--Update ShowQuestion Time
		TrivTimers.showques = TrivTimers.showques + 1
		if (TrivTimers.showques == self._Sets.showques) then
			TrivTimers.showques = 0
			-- Check if to get new question
			if curTriv:GetNewQues() then
				curTriv:SendQuestion()
				-- Count unsanswered questions one up
				curTriv.unansques = curTriv.unansques + 1
			else
				curTriv:UpdHint()
				if curTriv:GetGetQues() then
					-- Show the Answer
					curTriv:ShowAnswer()
					-- Check for Streak
					curTriv.streak:UpdStreak()
				else
					curTriv:SendQuestion()
				end
			end
		end
		for nick,v in sGag do
			local usr = GetItemByName(nick)
			sGag[nick] = sGag[nick] - 1
			if sGag[nick] == 0 then
				sGag[nick] = nil
				TrivEx:SendToPlayers(nick.. " was ungagged from TriviaGame.")
				TrivEx:WriteTable(sGag,"sGag","gagged.tbl")
			end
		end
	end
	if (self._Sets.savestats ~= 0) then
		TrivTimers.savestats = TrivTimers.savestats + 1
		if TrivTimers.savestats >= self._Sets.savestats then
			TrivTimers.savestats = 0
			if (curTriv.streak.write_scores == 1) then
				self:WriteTable(self._Scores,"TrivEx._Scores",self._Sets.folder.."/"..TrivEx._Sets.ScoresFile)
				curTriv.streak.write_scores = 0
			end
		end
	end
end
Not really tested.

Cheers

jiten

QuoteOriginally posted by James
in Your script jiten '' ungag ''not works...

Change this please :

TrivEx._Cmds.1ungag = TrivEx.UnGag

To this

TrivEx._Cmds.ungag = TrivEx.UnGag

now works the ungag-)))

Is possible to add the Timegag ???  ;)
It was a small typo ;)
Already fixed it.

Cheers

SMF spam blocked by CleanTalk