EtG Modding Guide
  • ETG Modding Guide
  • Getting started
    • Modding EtG: Installing Mods
    • Modding EtG: Creating a Mod
    • Uploading a Mod
    • Useful Tools
      • Using IlSpy
  • Making An Item
    • Creating A Passive
    • Creating An Active
    • Creating An Ammolet
    • Creating A Guon
    • Synergies
  • Making a Gun
    • Creating A Gun
      • Setting Up Gun Sprite Folders
      • Creating Gun Jsons/Jtk2ds
        • Pixel Measurement Conversions
    • Setting Up Projectiles
      • Adding Components To A Projectile
      • Projectile HitEffects (Visual Effects)
      • Adding status effects to a projectile
    • Continuous Fire Animations
    • Gun Ammo Types
  • Custom Characters
    • Creating A Standalone Custom Character
  • Making a Floor
    • Introduction
    • Setup
    • Making The Dungeon
    • Tileset
    • Rooms
    • Making the flow
    • Making the Entrance
    • All Files
  • Text, Text Boxes, Etc
    • Textboxes
    • Text Formatting
  • Sounds
    • Using Custom Sounds
    • Customising Gun Sounds
    • Basegame Sound List
    • wwise Sound Dump
  • Misc
    • Making Asset bundles
    • Assetbundles: How-To
    • How to create a hook
    • Creating A Command
    • Subscribing Methods to Actions
    • Reversing Player Controls
    • Undodgeable Projectiles
    • Creating An Enemy
  • Shaders
    • Creating Shaders
  • All things Spriting
    • Important Sprite Creation Information.
    • Importing a Sprite To Visual Studios
  • Monobehaviour Documentation
    • BounceProjModifier
    • PierceProjModifier
    • KeyProjModifier
    • CompanionFollowPlayerBehaviour
  • Various Lists of IDs, Sounds, Etc.
    • List of Item and Gun IDs
    • Enemy Guids
    • List of Base Game Synergies
    • dfSpriteList
    • All Custom Ammo Types
    • Gun .Json Dump
  • TwitchAPI and poll system guide
    • introduction and general functionality
  • The GlobalChatDelegate and GlobalToggleStatusNotification events
  • The poll system
  • Example of simple mod that uses polls
  • OFF TOPIC MEMES
    • Modders Anthem
Powered by GitBook
On this page

Was this helpful?

Example of simple mod that uses polls

simple mod example.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TwitchAPI;
using TwitchAPI.Polls;
using UnityEngine;

namespace Mod
{
    //this is added to a component to the game manager instance
    internal class OccasioanlPollSubmitter :MonoBehaviour
    {
        void Start()
        {
            //subscribe to notification to handle turning off polls
            TwitchAPI.TwitchAPI.GlobalToggleStatusNotification += tapiToggleHandler;
            //creates a random vote option pool
            options.Add(new VoteOption("Give glass guon stone",GivePlayerGlass));
            options.Add(new VoteOption("for each vote, heal once",HealPlayer));
            options.Add(new VoteOption("5 damage",DamagePlayer));
            options.Add(new VoteOption("Do nothing",DoNothing));
            options.Add(new VoteOption("spawn ammo",SpawnAmmo));
            options.Add(new VoteOption("spawn enemey",SpawnBulletKin));
            options.Add(new VoteOption("for each vote, give 1 casing",GivePlayerCoin));
 
        }
        void SubmitPoll()
        {
            if (GameManager.Instance.PrimaryPlayer && !GameManager.Instance.IsFoyer)
            {
                List<VoteOption> optionLoterry = new List<VoteOption>();
                for (int i = 0; i < 4; i++)
                {
                    optionLoterry.Add(options[UnityEngine.Random.Range(0, options.Count)]);
                }
                Poll poll = new Poll(30, optionLoterry, "an example poll", PollExampleCallBack, resolvePollOptions.randomIfTie);
                MainPollController.instance.SubmitPoll(poll);   
            }
        }
        //main callback. Can be used to handle generic poll conclusion, or edge cases
        void PollExampleCallBack(Poll poll) 
        {
            //gets winning votes from a poll. Can be used to handle conlusions any way we want
            List<VoteOption> winners = MainPollController.FindWinningVotes(poll);
            //since we just use the automatic random winner, we will ignore it and just spawn some particles
            
            Vector2 pos = GameManager.Instance.PrimaryPlayer.CenterPosition;
            GlobalSparksDoer.DoRadialParticleBurst(30, pos, pos, 1, 1, 1, null, null, null, GlobalSparksDoer.SparksType.FLOATY_CHAFF);

        }
        List<VoteOption> options = new List<VoteOption>();
        void tapiToggleHandler(bool toggleState)
        {
            //submits a poll every 60 seconds. Stops the submitions when tapi is toggled off
            if (toggleState)
                InvokeRepeating("SubmitPoll", 10f, 60f);
            else
                CancelInvoke("SubmitPoll");
        }
        //various small effects
        void GivePlayerGlass(VoteOption vote) {
            Vector2 position = GameManager.Instance.PrimaryPlayer.CenterPosition;
            LootEngine.SpawnItem(PickupObjectDatabase.GetById(565).gameObject, position, Vector2.zero, 0f);
        }
        void HealPlayer(VoteOption vote) 
        { GameManager.Instance.PrimaryPlayer.healthHaver.ApplyHealing((float)vote.votes); }
       
         void DamagePlayer(VoteOption vote) 
        { GameManager.Instance.PrimaryPlayer.healthHaver.ApplyDamage(2f, Vector2.zero, "poll"); }
        
        void GivePlayerCoin(VoteOption vote) {
            Vector2 position = GameManager.Instance.PrimaryPlayer.CenterPosition;
            for (int i = 0; i < vote.votes; i++)
                LootEngine.SpawnCurrency(position + UnityEngine.Random.insideUnitCircle.normalized, 1);
        }
        void GivePlayerArmor(VoteOption vote) {
            GameManager.Instance.PrimaryPlayer.healthHaver.Armor += 3;
        }
        void SpawnAmmo(VoteOption vote) {
            Vector2 position = GameManager.Instance.PrimaryPlayer.CenterPosition;
            LootEngine.SpawnItem(PickupObjectDatabase.GetById(78).gameObject, position, Vector2.zero,0f);
        }
        void SpawnBulletKin(VoteOption vote) {
            string[] a = { "bullet_kin" };
            ETGModConsole.Spawn(a);
        }

    }
}
PreviousThe poll systemNextModders Anthem

Last updated 5 days ago

Was this helpful?