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

    • I created a system of FAKES to improve my GeoEngine, but I'm having problems with blocks. I've tried everything to fix it, but a block going from the inside out bugs the player's movement and freezes them. However, the reverse doesn't cause this bug. If I'm outside and click inside, the path is traced normally, but if it's reversed, it bugs at the fence. I've created several debugs and read all kinds of GeoEngine versions, but I haven't had any success. Can someone give me some insight into graphical data?   When fakes spawn, they are given possible routes, but they don't follow them. If there's a target, instead of following the correctly drawn path, it simply uses a straight line.  
    • The legendary L2Elixir you remember from 2008 is officially back — remastered, refreshed, and reborn! Our x3 Interlude server launched on 28 November, and the community is growing every single day.   🔥 Fresh start 🔥 Active players joining daily 🔥 Long-term project — Licensed for over 5 years from PlayINERA. 🔥 True 2008 nostalgia with modern stability & polish   If you were part of the original Elixir family, this is your chance to relive the magic. If you’re new — welcome to a classic Lineage II experience built with passion, not profit.   Join the battles. Join the nostalgia. Join L2Elixir Reborn. Website: https://l2elixir.org/ Discord: https://discord.gg/5ydPHvhbxs
    • still available?  java version? client  salvation?  accept smarguart¡?
    • 🎉 L2NeverPain StuckSub - GRAND OPENING 12 December 2025🎉 After beta, testing, mistakes, laughs and a lot of PvP, the moment has finally come. L2NeverPain StuckSub is officially opening its gates on 12 December 2025.   ⚔️What to expect: ✦Main Class +2 Stuck Sub system ✦Balanced PvP & custom party farm areas ✦Custom events, bosses and strong rewards ✦Competitive clan scene with castle rewards   📌Until the opening: ✦Create your clans and register them in the Clan-Register channel ✦Invite your friends / old parties / CPs ✦Stay tuned for more information (rates, events, siege times, etc.)   Get your setups ready, prepare your macros and your Discord/voice. On 12 December 2025 20:00 GMT+2, we write the first chapter of NeverPain together. 🔥 https://l2neverpain.com/ https://discord.gg/kNP3UXgkmN
  • 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