Jump to content
  • 0

[help] pvp lord engine


Question

Posted

i prefet to be pvp lord in 16:17 but nothing i wait 10 minutes BUT NOTHING... :((

this is code...

package com.l2jfrozen.gameserver.model.entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;

import com.l2jfrozen.util.database.L2DatabaseFactory;
import com.l2jfrozen.gameserver.model.entity.Announcements;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;

/**
+ *
+ * @author  Fanky
+ */
public class PvpLordTask
{
public static void getInstance()
{
	ThreadPoolManager.getInstance().scheduleGeneral(new Runnable()
	{
		public void run()
		{
			String currentPvpLord = null,
			newPvpLord = null;
			int topTodayPvps = 0;
			Connection con = null;
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement stm = con.prepareStatement("SELECT char_name FROM characters WHERE pvplord=? AND accesslevel=?");
				stm.setInt(1, 1);
				stm.setInt(2, 1);
				ResultSet rSet = stm.executeQuery();

				if (rSet.next())
				{
					currentPvpLord = rSet.getString("char_name");
				}

				rSet.close();
				stm.close();

				if (currentPvpLord != null)
				{
					boolean cont = false;
					L2PcInstance cPvpLord = L2World.getInstance().getPlayer(currentPvpLord);
					if (cPvpLord == null || cPvpLord.isOnline() == 0)
					{
						cont = true;
					}
					else
					{
						cPvpLord.setPvpLord(false);
						cPvpLord.broadcastUserInfo();
					}

					if (cont)
					{
						stm = con.prepareStatement("UPDATE characters SET pvplord=? WHERE char_name=?");
						stm.setInt(1, 0);
						stm.setString(2, currentPvpLord);

						stm.execute();
						stm.close();
					}
				}

				stm = con.prepareStatement("SELECT todaypvps,char_name FROM characters WHERE accesslevel=? ORDER BY todaypvps DESC LIMIT 1");
				stm.setInt(1, 0);
				rSet = stm.executeQuery();

				if (rSet.next())
				{
					newPvpLord = rSet.getString("char_name");
					topTodayPvps = rSet.getInt("todaypvps");
				}

				rSet.close();
				stm.close();

				boolean cont = false;
				L2PcInstance nPvpLord = L2World.getInstance().getPlayer(newPvpLord);
				if (nPvpLord == null || nPvpLord.isOnline() == 0)
				{
					cont = true;
				}
				else
				{
					nPvpLord.setPvpLord(true);
					nPvpLord.broadcastUserInfo();
				}

				if (cont)
				{
					stm = con.prepareStatement("UPDATE characters SET pvplord=? WHERE char_name=?");
					stm.setInt(1, 1);
					stm.setString(2, newPvpLord);

					stm.execute();
					stm.close();
				}

				stm = con.prepareStatement("UPDATE characters SET todaypvps=?,todaypks=?,todaydeaths=?");
				stm.setInt(1, 0);

				stm.execute();
				stm.close();

				Announcements.getInstance().announceToAll("New PvP Lord: "+newPvpLord);
				Announcements.getInstance().announceToAll(newPvpLord+", Today PvPs: "+topTodayPvps);
			}
			catch (Exception e)
			{ }
			finally
			{
				try
				{
					con.close();
				}
				catch (Exception e)
				{ }
			}
		}
	}
	, getValidationTime());
}

private static long getValidationTime()
{
	Calendar cld = Calendar.getInstance();
	cld.set(Calendar.HOUR_OF_DAY, 16);
	cld.set(Calendar.MINUTE, 17);

	long time = cld.getTimeInMillis();
	if (System.currentTimeMillis()-time <= 0)
	{
		return time;
	}

	return 0;
}
}

11 answers to this question

Recommended Posts

  • 0
Posted

dont do 12321321 things in same time, dont create 2 topics about same thing.

Try thing by your own, try to find in which moment code is not working:

System.out.println("write something in console"); helps a lot.

  • 0
Posted

whatever u want to check, u can use it like this: System.out.println("time:"+getValidationTime());

System.out.println("lord online:"+nPvpLord.isOnline());

check what u need to check, read errors and think.

  • 0
Posted

but if i now what i check, i'm to newbie, please vampir help me, last time...

i am not giving ready codes for free, try to learn something but changing variables and checking reactions.

  • 0
Posted

all working, but i don't understand why in my set time don't set pvp lord and clean todaypvps, todaypks, todaydeaths

as i say i wait 10 minutes, but nothing, i change time, but nothing, no errors, so vampir please help to me, because in this situation i'm 0, if i have money i pay to you, i swear, if you help to me i share this to all, PLEASE!!!

  • 0
Posted

its not about the money, i just want u to try solve it by yourself. Check by yourself which part is working, and which part isnt :)

  • 0
Posted

vampir, i'm to newbie, after 1 week i use eclipse, but with your help i understand this more and more, so please help to me.

in gameserver.java i maked

		PvpLordTask.getInstance();
	_log.info("!!!PvpLordTask: loaded!!!");

this is working, then loading gameserver i see it

  • 0
Posted

hmm

this is not going to work because of return time;

it need to be changed to return time - System.currentTimeMillis();

last time i am creating code for u and not with u.

  • 0
Posted

now i use this code, and made after olympiad end is new pvp lord, but then made new pvp lord i need todaypvps,todaypks,todaydeaths clear, then is new pvp lord in navicat set todaypvps,todaypks,todaydeaths 0 but in game i have command getstats, then i wrote it, it show to me real todaypvps,todaypks,todaydeaths and after server restart in navicat back real points, how make that after new pvp lord

todaypvps,todaypks,todaydeaths set to 0 and then made new pvp lord, old pvp lord in navicat set pvplord 0

package com.l2jfrozen.gameserver.model.entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Calendar;
import java.sql.SQLException;

import com.l2jfrozen.util.database.L2DatabaseFactory;
import com.l2jfrozen.gameserver.model.entity.Announcements;
import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
import com.l2jfrozen.gameserver.model.L2World;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;

public class PvpLordTask
{

public static void newPvpLord(){

	int masterId = 0;
	int topTodayPvps = 0;
	Connection con = null;
	PreparedStatement state = null;
	ResultSet rset = null;

	try{
		con = L2DatabaseFactory.getInstance().getConnection();
		state = con.prepareStatement("SELECT obj_Id,todaypvps FROM characters ORDER BY todaypvps DESC LIMIT 1;");
		rset = state.executeQuery();
		if(rset.next())
		masterId = rset.getInt(1);

		if(masterId == 0)
			return;
		topTodayPvps = rset.getInt("todaypvps");

		state.close();
		rset.close();

		for(L2PcInstance p : L2World.getInstance().getAllPlayers()){
			if(p.getObjectId() == masterId)
			{
				p.sendMessage("You are the PvP Lord!");
				p.setPvpLord(true);
				p.broadcastUserInfo();

		state = con.prepareStatement("UPDATE characters SET pvplord=1 WHERE obj_Id=?");
		state.setInt(1, masterId);
		state.execute();
		state.close();

		state = con.prepareStatement("UPDATE characters SET todaypvps=0,todaypks=0,todaydeaths=0 WHERE obj_Id!=?");
		state.setInt(1, masterId);
		state.execute();
		state.close();	

			}
			Announcements.getInstance().announceToAll("PvP Lord is : "+p.getName());
			Announcements.getInstance().announceToAll("Today PvPs: "+topTodayPvps);
		}
		}
				catch(Exception e){
						e.printStackTrace();
					}
					finally{
						try
						{
							con.close();
						}
						catch (SQLException e)
						{
							e.printStackTrace();
						}
			}
			}
			}

Guest
This topic is now closed to further replies.
×
×
  • 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..