Git Product home page Git Product logo

tibia-votelistener's Introduction

How it works

tibia-votelistener is a standalone program that runs on the same machine as your Tibia server. It listens for vote notifications from otservers.org, and then rewards the player who voted.

Download

Installation

Installation is very easy. Simply run the executable file (or if using the Python script, run it with python VoteListener.py) and a VoteListener.ini file will be generated in the same folder.

Configuring VoteListener.ini

Set the language of the vote listener. en for English and pr for Portuguese.

[LANGUAGE]
lang = en

This is the IP and Port the vote listener will use. Normally you will want to enter your public IP address (not localhost or 127.0.0.1). The key can be obtained from your otservers.org control panel.

[VOTE LISTENER]
ip = 192.168.204.161
port = 7272
key = YOUR_KEY_HERE

Enter your Tibia server database connection information. A table named player_votes will be created automatically and used to store votes. If you are not running multiple servers on the same machine, leave the table_prefix blank.

[TIBIA DATABASE]
username = root
password = toor
database = tibia
ip = 127.0.0.1
port = 3306
table_prefix =

Adding the Lua script

Open data/talkactions/talkactions.xml and add the following line.

<talkaction words="!vote" script="votelistener.lua" />

Create the file data/talkactions/scripts/votelistener.lua and add the following code to it. This script allows users to check for queued vote rewards using the !vote command, and also handles which rewards the player will receive. If the player does not have any vote rewards queued, they will be given a link to vote for the server.

function giveReward(player)
    -- Enter code here for rewards
    -- Refer to the Github readme for examples
    -- https://github.com/Arrexel/tibia-votelistener
end

function onSay(player, words, param)
	local resultId = db.storeQuery("SELECT `votes` FROM `player_votes` WHERE `name` = " .. db.escapeString(player:getName()))
	if resultId == false then
		return false
	end

	local votes = result.getNumber(resultId, "votes")
	result.free(resultId)

	if votes == 0 then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have any pending vote rewards.")
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "To vote, go to https://otservers.org/en/vote/YOUR_SERVER_ID_HERE")
		return false
	end
    
    db.query("UPDATE `player_votes` SET `votes` = 0 WHERE `name` = " .. db.escapeString(player:getName()))
    
    for vote=0,votes,1
    do
        giveReward(player)
        print("> " .. player:getName() .. " voted!")
        for _, targetPlayer in ipairs(Game.getPlayers()) do
            targetPlayer:sendPrivateMessage(MESSAGE_EVENT_ADVANCE, player:getName() .. " received rewards for voting!")
            targetPlayer:sendPrivateMessage(MESSAGE_EVENT_ADVANCE, "Say !vote for awesome rewards.")
        end
    end

	return false
end

Customizing vote rewards

Customizing vote rewards is very easy. Simply add the rewards to the giveReward() function.

Example (give items)

Gives the player 10x earth. Refer to data/items/items.xml for a list of all item IDs.

function giveReward(player)
    player:addItem(101, 10)
end

tibia-votelistener's People

Contributors

arrexel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.