Jump to content
  • 0

(HELP) All good people come here, please...


Question

Posted

Hello all! It's a mission help to me:D

How can i make only todaypvps,todaypks,todaydeaths clear to 0? because this code is not working correctly. It's only make in navicat everywhere 0 but! after server restart points are back:(

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

Recommended Posts

  • 0
Posted

i maked then olympiad end to open this code, and search player with most todaypvps, this is working code make me pvp lord but don't clear todaypvps,todaypks,todaydeaths...

  • 0
Posted

Reading the code we see that after announcing the pvp lord, the fields todaypvps,etc. are cleaned, but only are cleaned the fields of pvplord player? Should be cleaned of all ppl not?

For the problem of server restart... create a boolean alreadycleaned = false, set it to true when pvplord comes, and then in the task that saves the values when restarting the server, if that boolean is true don't save.

  • 0
Posted

and pvplord fields are not cleaned, yes should be cleaned of all ppl.

because as i say in my server is command .getstats which show todaypvps,etc.

and every day 24h then olympiad ends its cleaning, but code not working.:(

  • 0
Posted

^Wyatt,

For the problem of server restart... create a boolean alreadycleaned = false, set it to true when the pvplord comes, and then in the task that save the values when restarting the server, if that boolean is true don't save.

 

i don't understand this, because i'm newbie on coding, i use eclipse only one week, so please explain better, thanks.

  • 0
Posted

         state = con.prepareStatement("UPDATE characters SET todaypvps=0,todaypks=0,todaydeaths=0 WHERE obj_Id=?");
         state.setInt(1, masterId);
         state.execute();
         state.close();   
         
         p.setTodayPvps(0);
         p.setTodayPks(0);
         p.setTodayDeaths(0);
         
            }
            Announcements.getInstance().announceToAll("PvP Lord is : "+p.getName());
            Announcements.getInstance().announceToAll("Today PvPs: "+topTodayPvps);
         }
         }

yes?

  • 0
Posted

I don't remember the methods to get all player values (online & offline) and then change the value of ints to 0.

And I can't look for it, I'm on mobile xd

Let's wait for someone else to help u.

  • 0
Posted

if u want to do this on online and offline characters, first take all online:

for(L2PcInstance player : L2World.getInstance().getAllPlayers()) - or something like this

player.setTodayPvps(0).

 

now we need to change offline, we can do this only by database so

try (Connection con = L2DatabaseFactory.getInstance().getConnection())
	{
		try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET todaypvps=0 WHERE online=0"))
		{
			ps.execute();
		}
	}
	catch (Exception e)
	{

	}

Guest
This topic is now closed to further replies.


×
×
  • Create New...