Jump to content
  • 0

VoteReward problem


k00k00

Question

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.

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

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

Link to comment
Share on other sites

  • 0

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.

Link to comment
Share on other sites

  • 0

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.

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



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