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

    • someone ban again this piece of shit this guy is a virus we should make an antikara or karabytes
    • 🍂 The cost on Vibe-sms is dropping, like autumn leaves falling from the trees.     It’s a little sad to watch the last days of summer fade away with its warmth, but that’s how the world works  every season has its own rules. The same goes for our prices: they are gradually but steadily going down, opening up new opportunities and great deals. 💸   🌍 USA is already at the minimum, and Europe, Asia, and dozens of other countries will follow soon. Don’t miss out  fresh rates are waiting for you!   Website link — https://vibe-sms.net/ Our Telegram channel — https://t.me/vibe_sms
    • You didn't tell me anywhere that you wanted core.jar as proof, I have everything ready for an independent developer to review. All the conversations, all your edits. I won't settle anything with you, so you can threaten me again and damage my name.
    • So what? Did i say anything wrong? You have no idea what source/compile is. I still wait for your .jar or source to be posted since you say i destroyed the compiled version of yours. Why you don't post it? Are you afraid that people will just see few addon lines and you did not even know that your source and compiled had different things? I should not even waste 2 minute to fix your raidboss_spawnlist thing.    Your mentally ill. What you posted is our primary deal nothing against me.  Because all he does is post whatever i write as if i hide and i did not say any mod to join and check my discord. i want him actual post something against me or any offenses i did. I also requested him several hours ago to post his .jar where my code "HACKED" his server but he wont post.    Nobody should allow open a random topic and cause issues to other's life without proofs. I demand punishment and soon unless he post evidence that i hurt his server or left him or did not make what he asked. 
  • 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