Jump to content

Recommended Posts

Posted

Hello everyone. An event i created some time ago(1-2 months).

 

Every x minutes a question is poped and players have to answer it in trade(+) chat. First who answers correctly wins.

 

/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.l2j.gameserver.model.entity.events;

import java.util.Map;

import javolution.util.FastList;
import javolution.util.FastMap;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.ItemTable;
import net.sf.l2j.gameserver.model.L2World;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.clientpackets.Say2;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
import net.sf.l2j.util.Rnd;
/**
* @author Anarchy
*
*/
public class Quiz
{
private static FastList<String> availableQuestions = new FastList<String>();
private static String currentQuestion = null,
	lastQuestion = null;
public static String currentAnswer = null;
private static int currentRewardId = 0,
currentRewardCount = 0;
public static boolean generatedQuestion = false;

public static void getInstance()
{
	int time = getRandomTime(Config.QUIZ_EVENT_TIME[0], Config.QUIZ_EVENT_TIME[1]);
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
	{
		@Override
		public void run()
		{
			if (!generatedQuestion)
			{
				generateQuestion();
			}
		}
	}, time*1000*60/2, time*1000*60);
}

public static void announceWinner(L2PcInstance p)
{
	p.addItem("Quiz event winner.", currentRewardId, currentRewardCount, p, true);
	announce("Winner: "+p.getName()+" Answer: "+currentAnswer);
	lastQuestion = currentQuestion;
	currentQuestion = null;
	currentAnswer = null;
	currentRewardId = 0;
	currentRewardCount = 0;
	generatedQuestion = false;
	availableQuestions.clear();
}

private static void generateQuestion()
{
	currentQuestion = getRandomQuestion();
	setReward();
	announce(currentQuestion);
	announce("Reward: "+currentRewardCount+" "+ItemTable.getInstance().getTemplate(currentRewardId).getName());
	announce("You have to answer in trade(+) chat.");
	announce("You have 5 minutes to answer.");
	generatedQuestion = true;

	ThreadPoolManager.getInstance().scheduleGeneral(new NoAnswerTask(), 5*1000*60);
}

private static class NoAnswerTask implements Runnable
{
	@Override
	public void run()
	{
		if (!generatedQuestion)
		{
			return;
		}

		generatedQuestion = false;
		lastQuestion = currentQuestion;
		currentQuestion = null;
		currentAnswer = null;
		currentRewardId = 0;
		currentRewardCount = 0;
		availableQuestions.clear();
		announce("There was no correct answer, so the question has been canceled.");
	}
}

private static void setReward()
{
	Map<String, String> questionsKey = new FastMap<String, String>();
	questionsKey.put(currentQuestion, currentAnswer);
	Map<Integer, Integer> questionsValue = Config.QUIZ_EVENT_QUESTIONS.get(questionsKey);
	for (int i : questionsValue.keySet())
	{
		currentRewardId = i;
		currentRewardCount = questionsValue.get(i);
	}
}

private static String getRandomQuestion()
{
	for (String s : Config.QUIZ_EVENT_QUESTIONS_KEYSET.keySet())
	{
		if (s.equals(lastQuestion))
		{
			continue;
		}

		availableQuestions.add(s);
	}

	int randomQuestionId = Rnd.get(availableQuestions.size());
	String question = availableQuestions.get(randomQuestionId);
	currentAnswer = Config.QUIZ_EVENT_QUESTIONS_KEYSET.get(question);

	return question;
}

private static void announce(String msg)
{
	CreatureSay cs = new CreatureSay(0, Say2.TRADE, "Quiz Event", msg);
	for (L2PcInstance p : L2World.getInstance().getAllPlayers().values())
	{
		p.sendPacket(cs);
	}
}

private static int getRandomTime(int min, int max)
{
	int time = Rnd.get(min, max);
	return time;
}
}

 

Configs:

# Quiz event.
AllowQuizEvent = True
# Quiz event time(in minutes) between questions.
# Must be set like: min/max.
# Time will be randomly chosen, for example if you put 5,15 it may be 7 or 9 or 13.
QuizEventTime = 10,20
# Quiz event questions.
# Must be set like: question,answer,rewardid,rewardcount;question,answer,rewardid,rewardcount;
QuizEventQuestions = Who created this event?,Anarchy,3470,5;What is the name of this server?,L2Server,57,100000000;

    public static boolean ALLOW_QUIZ_EVENT;
    public static int[] QUIZ_EVENT_TIME = new int[2];
    public static Map<Map<String, String>, Map<Integer, Integer>> QUIZ_EVENT_QUESTIONS = new FastMap<Map<String, String>, Map<Integer, Integer>>();
    public static Map<String, String> QUIZ_EVENT_QUESTIONS_KEYSET = new FastMap<String, String>(); // Hidden variable.

                ALLOW_QUIZ_EVENT = Boolean.parseBoolean(elcardia.getProperty("AllowQuizEvent", "false"));
                String quiz_event_time = elcardia.getProperty("QuizEventTime", "10,20");
                QUIZ_EVENT_TIME[0] = Integer.parseInt(quiz_event_time.split(",")[0]);
                QUIZ_EVENT_TIME[1] = Integer.parseInt(quiz_event_time.split(",")[1]);
                String quiz_event_questions = elcardia.getProperty("QuizEventQuestions"," Who created this event?,Anarchy,3470,5;What is the name of this server?,L2Server,57,100000000;");
                String[] quiz_event_questions_splitted_1 = quiz_event_questions.split(";");
                for (String s : quiz_event_questions_splitted_1)
                {
                	String[] quiz_event_questions_splitted_2 = s.split(",");
                	Map<String, String> string_map = new FastMap<String, String>();
                	string_map.put(quiz_event_questions_splitted_2[0], quiz_event_questions_splitted_2[1]);
                	Map<Integer, Integer> int_map = new FastMap<Integer, Integer>();
                	int_map.put(Integer.parseInt(quiz_event_questions_splitted_2[2]), Integer.parseInt(quiz_event_questions_splitted_2[3]));
                	QUIZ_EVENT_QUESTIONS.put(string_map, int_map);
                	QUIZ_EVENT_QUESTIONS_KEYSET.put(quiz_event_questions_splitted_2[0], quiz_event_questions_splitted_2[1]);
                }

 

GameServer.java

	if (Config.ALLOW_QUIZ_EVENT)
	{
		Quiz.getInstance();
	}

 

I know it's created before and shared too, but this one is coded in another way(configs) and created from scratch by me.

 

Have fun.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • First, you need to understand what you're doing and what you want to achieve. You have to choose a server core. After that, decide what you want your server to include, code it, modify the client to fit your server, go public, and drink champagne.   If you know how to code, creating a server is relatively easy — a few months of work and you can make it happen. Modifying the client is a completely different story. There’s a lack of tutorials, tools, and source materials. I’m currently working on the client myself, and I’ve already spent over three weeks just trying to get started due to the lack of information. If you don’t have the knowledge and experience, you’ll need a team and a bag of money — but realistically, it just won’t succeed.
    • The server has been online and stable for over 2 months now, and we’re still going strong! No wipes, no shortcuts ~ just continuous work, daily fixes, events, and improvements to ensure the best possible experience.   Great News! 🔥 CHAPTER II IS COMING — GRACIA FINAL 🔥 On February 16, L2Elixir enters a new era. The server will be officially updated to Gracia Final, opening Chapter II of our journey. Expect new content, improvements, and surprises that will refresh the gameplay while keeping the classic Gracia Final spirit alive.   More challenges, more competition, and more reasons to log in.   📅 Update Date: February 16 ⚔️ Chapter II: Gracia Final This is not a reset. This is evolution.   Prepare yourselves — Chapter II begins soon.   Website: https://l2elixir.org/ Discord: https://discord.gg/5ydPHvhbxs    
    • Server owners, Top.MaxCheaters.com is now live and accepting Lineage 2 server listings. There is no voting, no rankings manipulation, and no paid advantages. Visibility is clean and equal, and early listings naturally appear at the top while the platform grows. If your server is active, it should already be listed. Submit here 👉https://Top.MaxCheaters.com This platform is part of the MaxCheaters.com network and is being built as a long-term reference point for the Lineage 2 community. — MaxCheaters.com Team
    • Hello! We are Genesis, small team that works on new Lineage 2 project. Our goal with this project is to create a fresh new place to play — built around real community feedback, with no aggressive pay-to-win donations and with carefully thought-out quality-of-life improvements, balance changes etc. We believe that even tho we all love this game, everyone has at least one or two things they would like to change in the game to make it more enjoyable. Thats why we want the comunity feedback to shape our server. Main information about the server: • Interlude Classic version • Rates: EXP x4 SP x2 Loot x2, Spoil x2 (not set in stone, might be changed) • Local & Server-Side Dualbox Protection • Complete, Clear Website with Integrated Account Panel (Game account creation, direct communication with support, bug reporting, voting and reward system) • Launcher – External Game Login System: manage all your accounts inside the launcher, “Play” button logs you directly into the game server Here are list of few changes we already added/decided to add to the server: • Reworked Client to fit interlude Era with upgraded Classic Ui • Custom Antibot system • Custom AntiDualBox System • Offline shops • Offline shop with buffs (available only in towns) • Mass Sweeper added to the game • Newbie buffs available all the way to lvl 76 (nothing crazy, but its free) • Slight balance change to Destroyer damage with Polearm and Cancel spell from SPS • PvP zones on every Epic spawn spot • Overbuffing blocked • And more! Since we put big focus on community feedback and suggestions, we are looking for people for our internal tests, that will discuss whether current changes „fit” into the game and maybe suggest some changes themselves. If what you’ve just read sounds interesting to you, if you want to help creating server fitted for you, join our server Discord. Help us to understand what Lineage 2 players in 2026 actually expect and need — so we can meet those expectations and avoid becoming just another server that dies a natural death.     Even if you’re not interested in playing right now, but you are a long-time Lineage 2 player, feel free to join our community. We would greatly appreciate your experience and feedback to help us improve and develop our project. Join the growing L2Genesis community: https://discord.gg/mcuHsQzNCm Also check our website: https://l2genesis.com/
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..