NativeVoteAPI-CS2 0.2.4

dotnet add package NativeVoteAPI-CS2 --version 0.2.4
                    
NuGet\Install-Package NativeVoteAPI-CS2 -Version 0.2.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NativeVoteAPI-CS2" Version="0.2.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NativeVoteAPI-CS2" Version="0.2.4" />
                    
Directory.Packages.props
<PackageReference Include="NativeVoteAPI-CS2" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NativeVoteAPI-CS2 --version 0.2.4
                    
#r "nuget: NativeVoteAPI-CS2, 0.2.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=NativeVoteAPI-CS2&version=0.2.4
                    
Install NativeVoteAPI-CS2 as a Cake Addin
#tool nuget:?package=NativeVoteAPI-CS2&version=0.2.4
                    
Install NativeVoteAPI-CS2 as a Cake Tool

NativeVoteAPI CS2

CounterStrikeSharp implementation of API for Counter-Strike 2's native vote.

Caution

This is just an API for native vote!

This API does not provide standalone functionality. You need to create your own plugin to use it.

Features

  • Basic vote management
  • Panorama vote UI
  • Event system (on vote fail, pass, cancel)

Setup

  1. Download NativeVoteAPI from latest Release
  2. Put into your game/csgo/addons/counterstrikesharp/ directory
  3. Ready to use this API

Development

Setup

  1. Create or go to your existing project
  2. run dotnet add package NativeVoteAPI-CS2
  3. Ready to develop.

Full example is here: NativeVoteAPITest.cs

Using custom string in vote text

Since valve fixed a XSS exploit in html text, we can't use custom string in normal mean.

When we provide custom UI text in a platform_<language name>.txt file (e.g. platform_english.txt) and place it in the game/csgo/resource/ directory on both server and client, we can use custom text from the plugin.

Note

We can use pictures using <img src='{s:s1}'>, but it will display only once. after second one is not showing correctly.

Example

platform_english.txt

"lang"
{
    "Language" "English" 
    "Tokens"
    {
        "SFUI_vote_custom_vote_default"           "{s:s1}"
        "SFUI_vote_custom_vote_green"             "<font color='#00FF00'>{s:s1}</font>"
        "SFUI_vote_custom_vote_red"               "<font color='#FF0000'>{s:s1}</font>"
        "SFUI_vote_custom_vote_blue"              "<font color='#0000FF'>{s:s1}</font>"
        "SFUI_vote_custom_vote_image"             "<img src='{s:s1}'>"
    }
}

Plugin code (edit from NativeVoteApiTest.cs)

var potentialClients = Utilities.GetPlayers().Where(p => p is { IsBot: false, IsHLTV: false }).ToList();
var potentialClientsIndex = potentialClients.Select(p => p.Index).ToList();


string displayString = "#SFUI_vote_custom_vote_default";
string detailsString = "Custom string that will displayed in vote";

string voteIdentifier = "TEST_VOTE!";


NativeVoteInfo nInfo = new NativeVoteInfo(voteIdentifier, displayString ,detailsString, potentialClientsIndex, VoteThresholdType.AbsoluteValue, 0.5F, 5.0F);

// When the vote is successfully initiated, it will return InitializeAccepted.
NativeVoteState state = _nativeVoteApi.InitiateVote(nInfo);

Special thanks

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.2.4 244 4/4/2025
0.2.3 189 3/18/2025
0.2.2 135 3/18/2025
0.2.1 137 3/18/2025
0.2.0 139 3/17/2025
0.1.0 127 3/16/2025
0.0.1 126 3/16/2025