Jump to content

Recommended Posts

Posted (edited)
### Eclipse Workspace Patch 1.0
#P L2J_DataPack
Index: dist/game/data/scripts/custom/QuizEvent/QuizEvent.java
===================================================================
--- dist/game/data/scripts/custom/QuizEvent/QuizEvent.java    (revision 0)
+++ dist/game/data/scripts/custom/QuizEvent/QuizEvent.java    (working copy)

package custom.QuizEvent;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;

import com.l2jserver.Config;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.util.Broadcast;
import com.l2jserver.util.Rnd;

/**
 * 
 * @author Bellatrix
 *
 */
public class QuizEvent
{
    public static boolean                             _quizRunning;
    private static String                             _question;
    private static String                             _answer1;
    private static String                             _answer2;
    private static String                             _answer3;
    private static int                                 _rightanswer;
    private static Map<L2PcInstance,Integer>     _players;
    private static int                                 status;
    private static int                                 announced;
    private static ThreadPoolManager                 tpm;
    private static AutoEventTask                    task;
    private static String[][]                         _questions;
    private static int i = 0;
    private static final int STATUS_NOT_IN_PROGRESS = 0;
    private static final int STATUS_ASK = 1;
    private static final int STATUS_ANSWER = 2;
    private static final int STATUS_END = 3;
    
    //----------------------------------------------------------------------------
    //------------------------------ CONFIG --------------------------------------
    //----------------------------------------------------------------------------
    
    //Number of questions per event
    private static int _questionNumber = 3;
    
    //The Item ID of the reward
    private static int _rewardID = 57;
    
    //The ammount of the reward
    private static int _rewardCount = 1000;
    
    //Wait for the first event after the server start (in seconds)
    private static int _initWait = 3600;
    
    //Time for answer the question (in seconds)
    private static int _answerTime = 60;
    
    //Time between two event (in seconds)
    private static int _betweenTime = 18000;
    
    
    
    public QuizEvent()
    {
        tpm = ThreadPoolManager.getInstance();
        status = STATUS_NOT_IN_PROGRESS;
        task = new AutoEventTask();
        announced = 0;
        _quizRunning = false;
        _question = "";
        _answer1 = "";
        _answer2 = "";
        _answer3 = "";
        _rightanswer = 0;
        _players = new HashMap<>(100);
        _questions = new String[20][];
        includeQuestions();
        tpm.scheduleGeneral(task, _initWait*1000);
        
    }
            
    
    
    private void includeQuestions()
    {
        
        
        File questionFile = new File(Config.DATAPACK_ROOT, "data/scripts/custom/QuizEvent/QuizEvent.xml");
        Document doc = null;
        try
        {
            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setIgnoringComments(true);
            dbf.setValidating(false);
            DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(questionFile);
            
            for (Node root = doc.getFirstChild(); root != null; root = root.getNextSibling())
            {
                if ("list".equalsIgnoreCase(root.getNodeName()))
                {
                    
                    for (Node child = root.getFirstChild(); child != null; child = child.getNextSibling())
                    {
                
                        if ("question".equalsIgnoreCase(child.getNodeName()))
                        {
                            int id, correct;
                            String ask, answer1, answer2, answer3;
                            NamedNodeMap attrs = child.getAttributes();
                            
                            id = Integer.parseInt(attrs.getNamedItem("id").getNodeValue());
                            correct = Integer.parseInt(attrs.getNamedItem("correct").getNodeValue());
                            ask = attrs.getNamedItem("ask").getNodeValue();
                            answer1 = attrs.getNamedItem("answer1").getNodeValue();
                            answer2 = attrs.getNamedItem("answer2").getNodeValue();
                            answer3 = attrs.getNamedItem("answer3").getNodeValue();
                            
                            _questions[id] = new String[]{ ask, answer1, answer2, answer3, ""+correct }; 
                            i++;
                        
                            
                        }
                    }
                }
            }
        }
        catch (Exception e)
        {
            
        }
    }
    
    
    
    
    
    
    private class AutoEventTask implements Runnable
    {
        @Override
        public void run()
        {
            switch (status)
            {
            case STATUS_NOT_IN_PROGRESS:
                announceStart();
                break;
            case STATUS_ASK:    
                    if (announced < _questionNumber)
                    {
                    announceQuestion();
                    }
                    else
                    {
                    status = STATUS_END;
                    tpm.scheduleGeneral(task, 3000);
                    }
                break;
            case STATUS_ANSWER:
                announceCorrect();
                break;
            case STATUS_END:
                endEvent();
                break;
            default:
                break;
                
            }
        }
    }
    
    
    
    //Get a random question from the quiz_event table    
    private static void selectQuestion()
    {
        int id = Rnd.get(i)+1;
        _question = _questions[id][0];        
        _answer1 = _questions[id][1];
        _answer2 = _questions[id][2];
        _answer3 = _questions[id][3];
        _rightanswer = Integer.parseInt(""+_questions[id][4]);
    }
    
    
    
    //Announce the question
    private static void announceQuestion()
    {

        selectQuestion();
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("Question: "+_question);
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("1: "+_answer1);
        Broadcast.toAllOnlinePlayers("2: "+_answer2);
        Broadcast.toAllOnlinePlayers("3: "+_answer3);
        Broadcast.toAllOnlinePlayers("-----------------");
        
        status = STATUS_ANSWER;
        tpm.scheduleGeneral(task, _answerTime*1000);
    }
    
    
    
    //Announce the correct answer
    private static void announceCorrect()
    {
        Broadcast.toAllOnlinePlayers("-----------------");
        Broadcast.toAllOnlinePlayers("The correct answer was: "+_rightanswer);
        Broadcast.toAllOnlinePlayers("-----------------");
        announced++;
        giveReward();
        status = STATUS_ASK;
        tpm.scheduleGeneral(task, 5000);
    }
    
    
    private static void announceStart()
    {
        _quizRunning = true;
        _players.clear();
        Broadcast.toAllOnlinePlayers("Quiz Event begins! "+_questionNumber+" questions. "+_answerTime+" secs for answer each. ");
        Broadcast.toAllOnlinePlayers("Type . and the number of the correct answer to the chat. (Like: .1)");
        Broadcast.toAllOnlinePlayers("Get Ready!");
                
        status = STATUS_ASK;
        tpm.scheduleGeneral(task, 5000);
    }
    
    //Add a player and its answer
    public static void setAnswer(L2PcInstance player, int answer)
    {
        if( _players.containsKey(player) )
            player.sendMessage("You already choosen an aswer!: "+_players.get(player));
        else
        _players.put(player, answer);
    }
    
    
    private static void endEvent()
    {
        _quizRunning = false;
        Broadcast.toAllOnlinePlayers("The Quiz Event is over!");
        announced = 0;
        status = STATUS_NOT_IN_PROGRESS;
        tpm.scheduleGeneral(task, _betweenTime*1000);
    }
    
    
    
    private static void giveReward()
    {        
        for( L2PcInstance p: _players.keySet())
        {
            if(_players.get(p) == _rightanswer)
                {
                p.sendMessage("Your answer was correct!");
                p.addItem("Quiz", _rewardID, _rewardCount, p, true);
                }
                else
                {
                p.sendMessage("Your answer was not correct!");
                }

            
        }
        _players.clear();
    }
}
\ No newline at end of file
Index: dist/game/data/scripts/Custom/QuizEvent/QuizEvent.xml
===================================================================
--- dist/game/data/scripts/custom/QuizEvent/QuizEvent.xml    (revision 8768)
+++ dist/game/data/scripts/custom/QuizEvent/QuizEvent.xml    (working copy)
<?xml version="1.0" encoding="UTF-8"?>
<list>
    <question id = "1" ask = "Quel type Bijoux Drop Baium" answer1 = "Necklace" answer2 = "Ring" answer3 = "Earring" correct = "2" />
    <question id = "2" ask = "Comment s'appel l'admin" answer1 = "Bellatrix" answer2 = "Roberta" answer3 = "Jo" correct = "1" />
    <question id = "3" ask = "Quel Recompense donne le tvt" answer1 = "Codex" answer2 = "Coin" answer3 = "EventCoin" correct = "3" />
</list>
Index: dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java
===================================================================
--- dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java    (revision 0)
+++ dist/game/data/scripts/handlers/voicedcommandhandlers/Quiz.java    (working copy)
package handlers.voicedcommandhandlers;

import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;

import custom.QuizEvent.QuizEvent;

/**
 * @author Bellatrix
 */
public class Quiz implements IVoicedCommandHandler {
    private static final String[] _voicedCommands = {
        "quiz",
        "1",
        "2",
        "3"
    };
    
    /**
     * @see Bellatrix
     */
    @Override
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params) {
        
        if (command.equalsIgnoreCase("1") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 1);
        }
        
        if (command.equalsIgnoreCase("2") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 2);
        }
        
        if (command.equalsIgnoreCase("3") && QuizEvent._quizRunning) {
            QuizEvent.setAnswer(activeChar, 3);
        }
        return true;
    }
    
    /**
     * @see Bellatrix
     */
    @Override
    public String[] getVoicedCommandList() {
        new QuizEvent();
        return _voicedCommands;
    }
}
Index: dist/game/data/scripts/handlers/MasterHandlers.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandlerjava    (revision 0)
+++ dist/game/data/scripts/handlers/Masterhandlers.java    (working copy)
import handlers.voicedcommandhandlers.Quiz;


    private static final Class<?>[] VOICED_COMMAND_HANDLERS =
    {
        StatsVCmd.class,
        // TODO: Add configuration options for this voiced commands:
        // CastleVCmd.class,
        // SetVCmd.class,
        (Config.L2JMOD_ALLOW_WEDDING ? Wedding.class : null),
        (Config.BANKING_SYSTEM_ENABLED ? Banking.class : null),
        (Config.L2JMOD_CHAT_ADMIN ? ChatAdmin.class : null),
        (Config.L2JMOD_MULTILANG_ENABLE && Config.L2JMOD_MULTILANG_VOICED_ALLOW ? Lang.class : null),
        (Config.L2JMOD_ENABLE_ONLINE_STATUS ? OnlineStatus.class : null),
        (Config.L2JMOD_DEBUG_VOICE_COMMAND ? Debug.class : null),
        (Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null),
        Quiz.class,

 

Edited by extasie80
  • Like 1
  • Upvote 1
  • 1 year later...

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

    • IMPORTANT INFO: In a few days, I will switch to completely new code, written from scratch with a new download system, patch building and management system. The Updater will become true 2026 code with "foolproof systems". I'm going to create a Discord server for customers to request new ideas and features. FIRST CUSTOMERS ARE ALREADY USING THE NEW UPDATER ON LIVE SERVERS! Watch this topic for upcoming info because the new updater is around the corner! Yes, you can still use self-update on the previous updater! No, the new updater won't be compatible with the old patch system! A new build is required, but players who already have game files won't have to download the entire patch again! New templates and updates to existing templates are coming soon! Sneak peek:  
    • i used guytis IL project and source. i found in his project there are 3 Client version source... 1,CliExt_H5   --->this one cant be compiled in VS2005,i did know why..is it for H5 client? 2,CliExtNew  --->this one is IL version ,but when i compiled it and use it.player cant login game,MD5Checksum wrong.i check the source code,but not found any hints. 3,L2Server    --->this one for HB client?im not sure...   so my question is what are the differences between these three versions of cliext.dll?how can i fix the issue of the MD5Checksum not matching problem?   01/29/2026 21:04:11.366, [CCliExt::HandleCheckSum] Invalid Checksum[1130415144] vs [-721420287] packet[dd] len[29] sum[2698] key[30] HWID[] Account[]! 01/29/2026 21:04:11.366, SocketLimiter::UserSocketBadunknownprotocol 11111111111 01/29/2026 21:04:11.366, [usersocket]unknown protocol from ip[113.137.149.115]!      
    • ## [1.4.1] - 2026-01-29   ### ✨ New Features - **Short Description**: Server owners can add a short tagline (up to 240 characters) on the server info page, under the "Online" status. It appears in the server list (By Votes) for VIP, Gold VIP, and Pinned servers so players see a brief summary at a glance.   ### 🔄 Improvements - **Server Info Page**: Description field is limited to 3000 characters with a character counter; the textarea is vertically resizable. A second **Save Changes** button was added at the bottom (after the description) for easier saving. - **Server Name**: In My Servers → Edit, the server name is read-only and can no longer be changed (avoids accidental changes and naming conflicts). - **Server Rows (By Votes)**: Short descriptions wrap correctly and no longer affect row height; long text is clipped to two lines so the list stays tidy and consistent.   ---
    • @Celestine  sorry for mu question , and post it's to old but i want to ask  ?   do you have uncrypted interface x dat of this interface? i want to add custom autofarm button but when i open it with xdat say file seems  to be  encrypted. thanks!
  • 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..