Jump to content
  • 0

VoteReward problem


Question

Posted

Hi guys. Today i added 2 votereward systems on my server but both of them doesnt work. First i tried this one here and after that i tried this one here but nothing. Even if i get 5 votes , it keeps telling me i have 0.

3 answers to this question

Recommended Posts

  • 0
Posted

Hmm I can share with you my code, I use it as script in DataPack side.

 

/*
* 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 custom.AutoVoteEngine;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.Event;


/**
* @author Sirpaypi~
* @version 2.7
*/
public class AutoVoteRewardHandler
{
protected static final Logger _log = Logger.getLogger(AutoVoteRewardHandler.class.getName());
private final static String _url = "YOUR VOTE SCRIPT";	
      private final int _votesRequiredForReward = 5;
private final int initialCheck = 5;
private final int delayForCheck = 10;

private final static int[][] ITEMs =
      {
	{ 57, 200 }, 	
      };

private int _lastVoteCount = 0;

private AutoVoteRewardHandler()
{
	_log.info("[AutoVoteReward]: AUTO Vote Reward Started.");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck * 60000, delayForCheck * 60000);
}

private class AutoReward implements Runnable
{
	public void run()
	{
		int votes = getVotes();
		int rewardedPlayers = 0;
		if (votes > -1)
		{
			if  ((getLastVoteCount() != 0) && (votes >= (getLastVoteCount() + _votesRequiredForReward)))
			{	
				for (L2PcInstance player : L2World.getInstance().getAllPlayersArray())
				{
					if ((player != null) && !player.getClient().isDetached())
					{
						for (int[] reward : ITEMs)
						{
							if (player.getInventory().validateCapacityByItemId(reward[0]))
							{
								player.addItem("reward", reward[0], player, true);
							}
						}
						rewardedPlayers++;
					}
				}
				setLastVoteCount(getLastVoteCount() + _votesRequiredForReward);
			}
			else if (getLastVoteCount() == 0)
			{
				setLastVoteCount(votes);
			}
			_log.info("[AutoVoteReward]: Current Count : " + votes + ", Rewared Players : " + rewardedPlayers);
			Event.getInstance().eventToAll("L2Cataclysm's Current vote count is " + votes + " , Next Reward on " + (getLastVoteCount() + _votesRequiredForReward) + " Votes.");
		}
		else
		{
			_log.log(Level.WARNING, "[AutoVoteReward]: Oups Failled...");
		}
	}
}

private static int getVotes()
{
	BufferedReader in = null;
	int votes = -1;
	try
	{
		in = new BufferedReader(new InputStreamReader(new URL(_url).openStream()));
		String inputLine;
		while (((inputLine = in.readLine()) != null) && (votes == -1))
		{
			if (inputLine.contains("moreinfo_total_rank_text"))
			{
				try
				{
					votes = Integer.valueOf(inputLine.split(">")[2].replace("</div", ""));
				}
				catch (Exception e)
				{
				}
			}
		}
		in.close();
	}
	catch (Exception e)
	{
		_log.log(Level.WARNING, "[AutoVoteReward]: " + e.getMessage(), e);
	}
	return votes;
}

private void setLastVoteCount(int voteCount)
{
	_lastVoteCount = voteCount;
}

private int getLastVoteCount()
{
	return _lastVoteCount;
}

public static AutoVoteRewardHandler getInstance()
{
	return SingletonHolder._instance;
}

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler();
}

public static void main(String[] args)
{
	AutoVoteRewardHandler.getInstance();
}
}

  • 0
Posted

I create method 'getAllPlayersArray' in L2World, but i have again error, because of that?

Later error here,

 

((Object) Event.getInstance()).eventToAll("L2Cataclysm's Current vote count is " + votes + " , Next Reward on " + (getLastVoteCount() + _votesRequiredForReward) + " Votes.");

And again i create Class Event, " public static Object getInstance() " but nothing.

 

Anyway, i don't think to have wrong in 2 vote reward system.... maybe the topzone link have problem.

  • 0
Posted

Event.getInstance()).eventToAll("L2Cataclysm's Current vote count is " + votes + " , Next Reward on " + (getLastVoteCount() + _votesRequiredForReward) + " Votes.");

 

Easy stuff I use Event announcement. So the code should be for your server.

 

Announce.getInstance()).announceToAll("L2Cataclysm's Current vote count is " + votes + " , Next Reward on " + (getLastVoteCount() + _votesRequiredForReward) + " Votes.");

 

Or check your announcement code delete Event import add Announce one.

 

And best way to add link use php script.

 

Something like :

 

<?php
$url="YOUR LINK";
$ch=curl_init();
$timeout = 60;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$file_contents = curl_exec($ch);
curl_close($ch);
echo $file_contents;
?>

 

And don't creat methods etc. They all already exist...

 

For your other question.

 

Make folder with custom/voteblabala name add the .java file in your script.cfg.

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Hello everyone, Lineage II clan MightyTeam is reopening recruitment and looking for ambitious, active players who want to compete seriously and grow together. We are building a disciplined and organized environment focused on teamwork, strategy, and long-term success. What we offer: Strong and experienced leadership, Fair and respectful treatment for every member, Organized clan structure and tactical gameplay, Competitive mentality with clear goals, Stable and drama-free environment, What we expect: Activity and willingness to improve, Teamplay and communication, Respect toward clan members, Motivation to compete and dominate, No politics. No toxicity. Only focused players with the right mentality.   If you are interested in joining MightyTeam, contact on Discord: tzelal.  <-- there is a dot  or Telegram tz3gg. 
    • Lol thanks no l better get Acis /Lucera/Mobius and will squeeze more profit that your crazy ass price files for fucks know what. Even Reborn was smart enough use Acis after Lucera to squeeze shit a lot of money 😁 Fucking hell 15 grants lol 😂 
    • It seems the SkyLord is simply not familiar with what l2-scripts and Bonux represents today. His opinion is likely based on our older materials — which is understandable. We haven't been standing still. Over the years, the studio has moved to a fundamentally different level of development. Our early builds are still available on the legacy site at very accessible prices — and they remain entirely viable for launching a project. As practice shows, solid servers can still be built on them, albeit with greater effort. As for the market — Classic, Essence, and Main have long been running on l2-scripts engines, and the majority of successful servers have, at one stage or another, used our source code as their foundation. This isn't self-promotion — it's the history of the industry. Today, for established projects with a reputation, we offer a different format: private partnership with individual terms tailored to your business goals. If you're interested in long-term collaboration — we're open to the conversation. We have solutions for every level — from newcomers to top-tier projects. Feel free to reach out, and we'll be happy to discuss.
  • Topics

×
×
  • 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..