Jump to content

Player Of The Hour Minievent


Recommended Posts

Guest Elfocrash
Posted (edited)

So it's been a long time i deleted my shares and a longer one i shared something.
I had this idea and i wanted to share it with you guys.

So what it is? Well it's pretty much an event that has rounds that are calculated by time. Every 1 hour the event restarts and a new round starts.
At the end of the period the guy that has the most pvp inside the zone you have set gets a reward that it totally your business to set.


Here is the core of the feature:

/*

* 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.events;



import java.sql.Connection;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.util.Calendar;

import java.util.Date;



import net.sf.l2j.L2DatabaseFactory;

import net.sf.l2j.gameserver.Announcements;

import net.sf.l2j.gameserver.ThreadPoolManager;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;



/**

* @author Elfocrash

*

*/

public class PlayerOfTheHour

{



public static long getTimeToOclock()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);



   

        c.add(Calendar.HOUR, 1);



    c.set(Calendar.MINUTE, 0);

    c.set(Calendar.SECOND, 0);

  // System.out.print(c.getTime());

    long howMany = (c.getTimeInMillis()-d.getTime());

        return howMany;

}



public static String getNextHourToDate()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);

    c.add(Calendar.HOUR, 1);

   

   

      return c.getTime().toString();

}

public static String getTimeToDate()

{

Date d = new Date();

  Calendar c = Calendar.getInstance();

    c.setTime(d);



   

        c.add(Calendar.HOUR, 1);



    c.set(Calendar.MINUTE, 0);

    c.set(Calendar.SECOND, 0);

   

   

        return c.getTime().toString();

}

public static int getZonePvp(L2PcInstance activeChar)

{

int id=0;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters WHERE obj_Id=?");

statement.setInt(1, activeChar.getObjectId());

ResultSet rset = statement.executeQuery();



while (rset.next())

{

id = rset.getInt("zone_pvp");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return id;

}



public static void addZonePvp(L2PcInstance activeChar)

{

try(Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=? WHERE obj_Id=?");

statement.setInt(1, getZonePvp(activeChar) +1);

statement.setInt(2, activeChar.getObjectId());

statement.executeUpdate();

statement.close();

}

catch(Exception e)

{



}

}



public static void resetZonePvp()

{

try(Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("UPDATE characters SET zone_pvp=0");

statement.executeUpdate();

statement.close();

}

catch(Exception e)

{



}

}



static int getTopZonePvpCount()

{

int id=0;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT zone_pvp FROM characters ORDER BY zone_pvp DESC LIMIT 1");

ResultSet rset = statement.executeQuery();



while (rset.next())

{

id = rset.getInt("zone_pvp");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return id;

}



static String getTopZonePvpName()

{

String name = null;

try (Connection con = L2DatabaseFactory.getInstance().getConnection())

{

PreparedStatement statement = con.prepareStatement("SELECT char_name FROM characters ORDER BY zone_pvp DESC LIMIT 1");

ResultSet rset = statement.executeQuery();



while (rset.next())

{

name = rset.getString("char_name");

}

rset.close();

statement.close();

}

catch (Exception e)

{

}

return name;

}



private PlayerOfTheHour()

{



}

public static void getTopHtml(L2PcInstance activeChar)

{

  NpcHtmlMessage htm = new NpcHtmlMessage(0);

    StringBuilder sb = new StringBuilder("<html><body>");

    sb.append("<center><br>Top 10 PvP:<br><br1>");

    Connection con = null;

            try

            {

              con = L2DatabaseFactory.getInstance().getConnection();

              PreparedStatement stm = con.prepareStatement("SELECT char_name,zone_pvp,accesslevel,online FROM characters ORDER BY zone_pvp DESC LIMIT 10");

              ResultSet rSet = stm.executeQuery();

              while (rSet.next())

              {

              int accessLevel = rSet.getInt("accesslevel");

              if (accessLevel > 0)

              {

                continue;

              }

              int pvpKills = rSet.getInt("zone_pvp");

              if (pvpKills == 0)

              {

                continue;

              }

              String pl = rSet.getString("char_name");

              sb.append("Player: <font color=\"LEVEL\">"+pl+"</font> PvPs: <font color=\"LEVEL\">"+pvpKills+"</font><br1>");

              }

            }

            catch (Exception e)

            {

              System.out.println("Error while selecting top 15 pvp from database.");

            }

            finally

            {

              try

              {

              if (con != null)

                con.close();

              }

              catch (Exception e)

              {}

            }

            sb.append("Next round: " + getTimeToDate() +"</body></html>");

            htm.setHtml(sb.toString());

            activeChar.sendPacket(htm);

  }



    public static void getInstance()

    {

   

        ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()

        {

            @Override

           

            public void run()

            {

           

            Announcements.announceToAll("The Player of the Hour is " + getTopZonePvpName() + " with "+getTopZonePvpCount()+ " pvps");

            //TODO Your reward should go here.

            resetZonePvp();

            Announcements.announceToAll("New Player of the Hour just started. Go to Primeval Isle and show us what you got.");

Announcements.announceToAll("This round will end at: " + getNextHourToDate() + ".");

            }

        }, getTimeToOclock() ,  3600000);

    }

   

   

}

You will also need this VoicedCommand in order to check the ranking for this hour. The command is .zonepvp.

/*

* 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.handler.voicedcommandhandlers;



import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.model.events.PlayerOfTheHour;





public class ZonePvp implements IVoicedCommandHandler

{

private static final String[] _voicedCommands = { "zonepvp"};





@Override

public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)

{



if(command.equals(_voicedCommands[0]))

{

PlayerOfTheHour.getTopHtml(activeChar);



}

return true;

}



@Override

public String[] getVoicedCommandList()

{

return _voicedCommands;

}

}

You also need to make your increasePvpKills() method look like this:

public void increasePvpKills()

{

// Add karma to attacker and increase its PK counter

setPvpKills(getPvpKills() + 1);



if(isInsideZone(ZoneId.ZONE_PVP))

PlayerOfTheHour.addZonePvp(this);



// Send a Server->Client UserInfo packet to attacker with its Karma and PK Counter

sendPacket(new UserInfo(this));

}

At last you need this zone. Dont forget to register it at ZoneId:

/*

* 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.zone.type;



import net.sf.l2j.gameserver.model.actor.L2Character;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

import net.sf.l2j.gameserver.model.zone.L2SpawnZone;

import net.sf.l2j.gameserver.model.zone.ZoneId;

import net.sf.l2j.gameserver.network.SystemMessageId;



/**

* An arena

* @author durgus

*/

public class L2ZonePvpZone extends L2SpawnZone

{

public L2ZonePvpZone(int id)

{

super(id);

}



@Override

protected void onEnter(L2Character character)

{

if (character instanceof L2PcInstance)

{

((L2PcInstance) character).sendMessage("You are now inside the Player of the Hour Zone.");

}



character.setInsideZone(ZoneId.ZONE_PVP, true);

character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, true);

}



@Override

protected void onExit(L2Character character)

{

character.setInsideZone(ZoneId.ZONE_PVP, false);

character.setInsideZone(ZoneId.NO_SUMMON_FRIEND, false);



if (character instanceof L2PcInstance)

{

((L2PcInstance) character).sendMessage("You are no longer inside the Player of the Hour Zone.");

}

}



@Override

public void onDieInside(L2Character character)

{

}



@Override

public void onReviveInside(L2Character character)

{

}

}

Finally you need to add this on gameserver:

PlayerOfTheHour.getInstance();

Last but not list design your database and add an unsigned column with a default of 0 on your characters table with the name 'zone_pvp'

Here is an image of the ingame html of .zonepvp and the annoucnements for the change of the round.
lJ2LbHU.png
(DW i fixed the order of the pvps so the one with the most is on the top line)
Sorry for not having a patch but you are not able to if your project is not comming from an SVN (as far as i know).
That's all guys. Enjoy. For any bug let me know.

 

Edited by Universe
Posted

Great idea indeed . I want to know about the feeders , You tested it on live server ?

add this check in increasekills method in pcinstance

if(!target.getActingPlayer().getClient().getConnection().getInetAddress().equals(this.getClient().getConnection().getInetAddress()))

Guest Elfocrash
Posted

add this check in increasekills method in pcinstance

if(!target.getActingPlayer().getClient().getConnection().getInetAddress().equals(this.getClient().getConnection().getInetAddress()))

Yeah this will fix it but either way if you set the zone as PI beach with so much mass pvp you wont be worried of feeding.

Posted

Yeah this will fix it but either way if you set the zone as PI beach with so much mass pvp you wont be worried of feeding.

As I see in the code it checks if player is in pvp zone so any dual box can go to anyplace like coliseum and farm.

Guest Elfocrash
Posted

As I see in the code it checks if player is in pvp zone so any dual box can go to anyplace like coliseum and farm.

No mate the zone is not te arena or coli. It is a custom one. You set it yourself. It is not the ZoneId.PVP but ZoneId.ZONE_PVP which is the custom one. For example on my test server ZONE_PVP Is only the beach in PI. For yours you set the coords wherever you want. It is not thr coli or arena zone. It s a custom one.

Posted

add this check in increasekills method in pcinstance

if(!target.getActingPlayer().getClient().getConnection().getInetAddress().equals(this.getClient().getConnection().getInetAddress()))

 

I am not planning to add it yet on my project , But thanks for the tip :P .

  • 5 months later...
  • 2 months later...
  • 3 months later...
Guest
This topic is now closed to further replies.


  • Posts

    • Lol good joke.   If I'd be the one contacting yo then I'd say at least 50% in advance because you can basically just fuck off when things doesn't go your way, and then you as a developer just wasted days or even weeks of time with development.
    • "Just make your own game!" sounds simple until you’ve tried it. I did, with Epic Dragon World and learned the hard way that "open source" often means "free labor for resellers." The MIT license became a buffet for people to grab code, rebrand it and ghost the project. Even basic collaboration collapsed because everyone wanted their vision, not *a* vision. NCSoft’s lawyers aren’t theoretical. They’re a sword of Damocles. Even if you rebuild a client from scratch, if it feels like Lineage 2, they’ll come knocking. Ask the Chrono Trigger fangame corpses how that goes. MMOs are hospice care. The genre’s on life support, kept alive by whales and nostalgia. Look at Throne and Liberty, NCSoft’s own "successor" to L2, flopping harder than a 2004 PKer in ToI. Classic reboots (WoW, L2) are bandaids, not resurrections. This is the hobby. Optimizing old systems, reverse-engineering spaghetti code and preserving janky mechanics is the fun part. Monetizing it turns it into customer service hell. No thanks. Community? What community? The L2 scene is 90% resellers, 10% players who’ll quit the second they don’t get +16 on day one. Both asking how to install Java and why running the uncompiled server does not work.
    • Dear players, Open beta test for C3 begins today at 19:00 server time (GMT +2). 💰 All participants who find bugs during OBT will be rewarded with Coin of Luck (CoL): - 1 CoL for each staticmesh issue found — e.g., walking through textures, etc., - 2 CoL or more for server-side issues, depending on their severity., We strongly recommend reviewing the quest list - when switching to Chronicle 3, the total number of quests should match the number shown in the upper right corner of the window and correspond to the quest count from Chronicle 2. To log into the game, use the same data you use to access the Airin server. 📌 Download client: Google Drive
    • 🔥 Sale Alert! 🔥 Twitter Accounts with 50 Followers — now on SALE! Looking to launch a project or warm up your account base fast? We’ve got starter Twitter accounts with ~50 followers at a sweet price. 💰 Limited-time offer – while stock lasts! ✅ Organic-Looking ✅ Clean & Safe ✅ Perfect for boosting credibility 📦 Instant delivery
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock