VotingSystem

  • community
  • community-management
  • by r20
  • Takaro main
  • all
Version
View export JSON

R20_VotingSystem: Server Voting & Reward Platform

The R20_VotingSystem module provides a complete voting and rewards integration for your gaming server. This comprehensive Takaro module connects with popular voting platforms to incentivize players to vote for your server, increasing visibility and rankings.

Key Benefits:

  • Voting Site Integration: Seamless connection with popular server listing platforms
  • Flexible Reward Configuration: Multiple reward types for complete customization
  • Random Reward System: Element of surprise with randomized item distribution
  • API Communication: Automatic verification of player votes
  • Anti-Abuse Protection: Prevents duplicate reward claims

Features:

  • Support for major voting platforms including 7daystodie-servers.com and rust-servers.net
  • Configurable currency rewards integrated with server economy
  • Random item rewards with customizable probability
  • Fixed item rewards for guaranteed player benefits
  • Custom notification messages for successful votes
  • Public announcements to encourage community participation
  • Detailed player feedback during reward distribution
  • SteamID and username authentication support.

Configuration 10

Settings you fill in when installing the module on a server.

SettingTypeDefaultDescription
votingsite required votingsite string "https://7daystodie-servers.com" Site where players vote. Example: https://7daystodie-servers.com for 7 Days to Die; https://rust-servers.net for RUST
votekey required votekey string Vote key provided by the voting site
novote required novote string "You haven't voted yet. Please vote at https://7daystodie-servers.com first." Message to send to the player when voting site reports no vote was cast.
alreadyclaimed required alreadyclaimed string "You have already claimed your last vote." Message to send to the player when the voting site reports the vote reward was already claimed.
privatemessage privatemessage string "" Optional message to send to the player when the voting site reports a vote with no reward claimed yet. Example: Thanks for voting. Leave it blank if you want nothing to be sent instead.
publicmessage publicmessage string "" Optional message to broadcast to all players online when vote is successful. Use {name} in the message to refer to the player name. Example: [00FF00]{name}[-] voted at 7daystodie-servers.com and was rewarded Takaro Coins! Leave it blank if you want nothing to be sent instead.
currency currency number 0 How much currency to add to the player in Takaro, if any. Make sure to enable economy for this server.
randomitemnumber randomitemnumber number 0 Defines how many random items will be rewarded to the player, picked from randomitemlist config field. The quantities for each item picked is defined on the mentioned config field.
randomitemlist Items array List of items that will be used to select a random reward for the vote, as many times as defined at randomitemnumber.
fixedrewards Items array All the items in this list will be given as a reward for the vote.
Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [
    "votingsite",
    "votekey",
    "novote",
    "alreadyclaimed"
  ],
  "additionalProperties": false,
  "properties": {
    "votingsite": {
      "title": "votingsite",
      "description": "Site where players vote. Example: \nhttps://7daystodie-servers.com for 7 Days to Die;\nhttps://rust-servers.net for RUST\n\n",
      "default": "https://7daystodie-servers.com",
      "type": "string"
    },
    "votekey": {
      "title": "votekey",
      "description": "Vote key provided by the voting site",
      "type": "string"
    },
    "novote": {
      "title": "novote",
      "description": "Message to send to the player when voting site reports no vote was cast. ",
      "default": "You haven't voted yet. Please vote at https://7daystodie-servers.com first.",
      "type": "string"
    },
    "alreadyclaimed": {
      "title": "alreadyclaimed",
      "description": "Message to send to the player when the voting site reports the vote reward was already claimed.",
      "default": "You have already claimed your last vote.",
      "type": "string"
    },
    "privatemessage": {
      "title": "privatemessage",
      "description": "Optional message to send to the player when the voting site reports a vote with no reward claimed yet. \nExample: Thanks for voting.\nLeave it blank if you want nothing to be sent instead.",
      "default": "",
      "type": "string"
    },
    "publicmessage": {
      "title": "publicmessage",
      "description": "Optional message to broadcast to all players online when vote is successful. Use {name} in the message to refer to the player name.\nExample: [00FF00]{name}[-] voted at 7daystodie-servers.com and was rewarded Takaro Coins!\nLeave it blank if you want nothing to be sent instead.\n",
      "default": "",
      "type": "string"
    },
    "currency": {
      "title": "currency",
      "description": "How much currency to add to the player in Takaro, if any.\nMake sure to enable economy for this server.",
      "default": 0,
      "type": "number"
    },
    "randomitemnumber": {
      "title": "randomitemnumber",
      "description": "Defines how many random items will be rewarded to the player, picked from randomitemlist config field.\nThe quantities for each item picked is defined on the mentioned config field.",
      "default": 0,
      "type": "number"
    },
    "randomitemlist": {
      "title": "Items",
      "description": "List of items that will be used to select a random reward for the vote, as many times as defined at randomitemnumber.",
      "x-component": "item",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "object",
        "title": "Item",
        "properties": {
          "item": {
            "type": "string",
            "title": "Item"
          },
          "amount": {
            "type": "number",
            "title": "Amount"
          },
          "quality": {
            "type": "string",
            "title": "Quality"
          }
        }
      }
    },
    "fixedrewards": {
      "title": "Items",
      "description": "All the items in this list will be given as a reward for the vote.",
      "x-component": "item",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "object",
        "title": "Item",
        "properties": {
          "item": {
            "type": "string",
            "title": "Item"
          },
          "amount": {
            "type": "number",
            "title": "Amount"
          },
          "quality": {
            "type": "string",
            "title": "Quality"
          }
        }
      }
    }
  }
}
Raw UI schema
{}

Commands 1

Chat commands players trigger in game.

  • vote

    Claim rewards for voting for the server

    Command source
    
    import { takaro, data, axios } from '@takaro/helpers';
    async function main() {
      const { } = data;
    
      const { votingsite, votekey, novote, alreadyclaimed, privatemessage, publicmessage, currency, randomitemnumber, randomitemlist, fixedrewards } = data.module.userConfig;
      const { steamId } = data.player;
    
      let actualrandomitemnumber;
      if (randomitemnumber === 0) {
        actualrandomitemnumber = 0;
      } else {
        actualrandomitemnumber = randomitemnumber > randomitemlist.length ? randomitemlist.length : randomitemnumber;
      }
    
      let voteId = `steamid=${steamId}`;
      if (!steamId)
        voteId = `username=${data.player.name}`;
    
      const votingSiteResponse = (await axios.get(`${votingsite}/api/?object=votes&element=claim&key=${votekey}&${voteId}`)).data;
      // if you wish to test the command without actually voting, comment the line above and uncomment the line bellow, and to the same with lines 27 and 28.
      // const votingSiteResponse = 1;
      if (votingSiteResponse == 'Error: server key not found') { await data.player.pm(`The server vote key is invalid, please notify the admins.`); }
      if (votingSiteResponse == 0) { await data.player.pm(novote); }
      if (votingSiteResponse == 2) { await data.player.pm(alreadyclaimed); }
      if (votingSiteResponse == 1) {
    
        const claimresponse = (await axios.post(`${votingsite}/api/?action=post&object=votes&element=claim&key=${votekey}&${voteId}`)).data;
        //  const claimresponse = 1
        if (claimresponse == 1) {
          if (privatemessage) { await data.player.pm(privatemessage); }
          if (publicmessage) { await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, { message: publicmessage.replace('{name}', data.player.name), }); }
    
          if (actualrandomitemnumber > 0) {
            for (let i = 0; i < actualrandomitemnumber; i++) {
              const randomIndex = Math.floor(Math.random() * randomitemlist.length);
              const randomOption = randomitemlist.splice(randomIndex, 1)[0];
              if (typeof randomOption === 'string') {
                console.log(`Giving random item ${i + 1}/${actualrandomitemnumber}:`, randomOption);
                await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                  name: randomOption,
                  amount: 1,
                  quality: '0',
                });
                await data.player.pm(`You received ${randomOption}! (item ${i + 1}/${actualrandomitemnumber + fixedrewards.length})`);
              }
              else {
                const item = (await takaro.item.itemControllerFindOne(randomOption.item)).data.data;
                console.log(`Giving random item ${i + 1}/${actualrandomitemnumber}:`, item.name);
                try {
                  await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                    name: item.code,
                    amount: randomOption.amount ?? '1',
                    quality: randomOption.quality ?? '',
                  });
                } catch (error) {
                  await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                    name: item.code,
                    amount: randomOption.amount ?? '1',
                    quality: '',
                  });
                }
    
                await data.player.pm(`You received ${randomOption.amount}x ${item.name}! (item ${i + 1}/${actualrandomitemnumber + fixedrewards.length})`);
              }
            }
          }
    
          if (fixedrewards.length > 0) {
            let index = 1;
            for (const each of fixedrewards) {
              if (typeof each === 'string') {
                await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                  name: each,
                  amount: 1,
                  quality: '0',
                });
                await data.player.pm(`You received ${each}! (item ${index + actualrandomitemnumber}/${actualrandomitemnumber + fixedrewards.length})`);
              }
              else {
                const item = (await takaro.item.itemControllerFindOne(each.item)).data.data;
                try {
                  await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                    name: item.code,
                    amount: each.amount ?? 1,
                    quality: each.quality ?? '',
                  });
                } catch (error) {
                  await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {
                    name: item.code,
                    amount: each.amount ?? 1,
                    quality: '',
                  });
                }
    
    
                await data.player.pm(`You received ${each.amount}x ${item.name}! (item ${index + actualrandomitemnumber}/${actualrandomitemnumber + fixedrewards.length})`);
              }
              index++;
            }
          }
    
          if (currency > 0) {
            const currencyName = (await takaro.settings.settingsControllerGetOne('currencyName', data.gameServerId)).data.data;
            await takaro.playerOnGameserver.playerOnGameServerControllerAddCurrency(data.gameServerId, data.player.id, { currency: currency, });
            await data.player.pm(`You received ${currency} ${currencyName.value}.`);
          }
    
        } else {
          await data.player.pm(`Something went wrong while claiming your vote reward.`);
          console.log(votingSiteResponse);
        }
      }
    
    
    }
    
    await main();