Jump to content

Player Of The Hour Minievent


Guest Elfocrash

Recommended Posts

Guest Elfocrash

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
Link to comment
Share on other sites

Great idea elfo,but what about the feeders ? amazing share anyway.

 

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

Link to comment
Share on other sites

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()))

Link to comment
Share on other sites

Guest Elfocrash

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Guest Elfocrash

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.

Link to comment
Share on other sites

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 .

Link to comment
Share on other sites

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


  • Posts

    • Trustworthy person; hope you find what you're looking for!
    • Customs being added to systextures/animation/texture influences the increase in virtual ram by a very small amount, which means you won't have a headache in the future with critical error issues, unless it's a dubious custom, there are 2 custom weapon packs available for H5 that are "compromised", they didn't make a very good adaptation, one of the packages is the weapons from the goddess of destruction for H5, another is the hero weapons from the goddess of destruction for H5, avoid these customs for your H5 server if you see it on any forum.   Now coming back to your question; one thing that the NCSoft developers never did was add files to their system, probably because they were aware of what could happen when doing that, now think about one thing: the game's system retail itself is no more than 70MB, every time there was an update made by NCSoft they always added the equipment/items/cloaks etc. in their folders intended for that, so why do we do this? I still have my client containing a system with almost 1GB, 1-2h online is the time I can stay online before the ram memory limit, but I have already redone my entire client with customs being destined for textures/systexture/animations, almost all the customs that I had on that client containing a 1GB system I have on my current server, with the difference that I removed everything from the system and critical error is now nothing more than legends, my current server has a total of 220MB in the system folder And theoretically speaking, based on what I've seen, especially on many forums, I believe that the heavier the system folder is, the faster we accelerate the consumption of the client's virtual ram memory, causing countless different types of critical error in one short period of time, in many forums that I've seen on topics involving critical, the solution that stands out the most is about downloading a new clean "system"
    • Do you think that everything on the system is loaded regardless if you use it or not ? or even worst, are they loaded even if they exist as textures/meshes but not defined on the DAT files ?
    • DISCORD : utchiha_market telegram : https://t.me/utchiha_market SELLIX STORE : https://utchihamkt.mysellix.io/ Join our server for more products : https://discord.gg/hoodservices https://campsite.bio/utchihaamkt
    • Yes, it is, it's not hard to do (if you know what you're doing); just time consuming.   To make some things clear: 1. You can not create .ukx files with animated skeletalmeshes inside, by using any of the freeshared L2Editors (basically, no support for .psa files) 2. You need a patched UT2003/UT2004. You can either get your own ut2004 and download Gildor's patch from his web, or use any of these: When you use these, you should be able to import both .psk and .psa animations > link the skeletalmesh to the psa > save as .ukx > use ut2down to convert the file to l2 format > encrypt the .ukx with standard l2 encryption (you can use mxc encdec, you can find it in the folder of the l2editor i shared). Your best bet is to use pawnviewer (aka dev mode) to test that. If you have troubles with that process then leave a reply here, otherwise, if it works correctly, you can move on to adding missing animnotify classes to you unrealed, then proper animnotifies, sounds, effects or w/e is missing from your .ukx files. Keep in mind that this is overall not difficult but a huge amount of work (unless you're good at scripting/macros) since you'd need to manually re-create every single animnotify, by hand. If you have doubts or i wasn't clear enough let me know here. (in case you don't know what an animnotify is: UDN - Two - AnimNotifies (unrealengine.com) )  
  • Topics

×
×
  • Create New...