Raised This Month: $51 Target: $400
 12% 

Need help with Knife Round Duels plugin (used CHAT GPT)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
r14170
Veteran Member
Join Date: Dec 2009
Old 03-07-2023 , 00:01   Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #1

Hi there.

Im trying to create a plugin which makes Knife Only Duels at the start of every map.

Winners of the duels become Terrorists - Losers become CTs. (hiders (Ts) and seekers (CTs) in HnS)

If there are even number of players, lets say 6 - it will create 3 duels.
If there are odd number of players, lets say 7, it will still create 3 duels but 1 guy at random will be assigned as CT (loser)

The "Knife only duels round" will start after 15 seconds of warmup has been played (so all players can connect if the map has changed)

After duels and when the actual game starts - it will remove the knifes from the Terrorists team but will not remove the knifes from the CTs.

Since Iam not a good coder, I tried using ChatGPT and here is where we ended up which is not compileable:

Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>

public void OnPluginStart()
{
    RegConsoleCmd("sm_kniferound", Command_KnifeRound);
    RegGameEvent("round_start", Event_RoundStart);
}

public Action Command_KnifeRound(int client, const char[] args)
{
    // Check if the game has not yet started
    if (gamestatus != GAME_COMMENCING) {
        PrintToChat(client, "Error: Cannot start knife round while game is in progress.");
        return Plugin_Handled;
    }

    // Get the number of players
    int num_players = GetClientCount();

    // Check if there are at least 2 players
    if (num_players < 2) {
        PrintToChat(client, "Error: Cannot start knife round with less than 2 players.");
        return Plugin_Handled;
    }

    // Determine the number of duels to create
    int num_duels = num_players / 2;

    // If the number of players is odd, remove one player at random to be a CT loser
    if (num_players % 2 != 0) {
        int loser = RandomInt(1, num_players);
        SetEntProp(loser, Prop_Send, "m_iTeamNum", 3); // Set loser to CT team
        num_duels = (num_players - 1) / 2;
    }

    // Start the warmup period
    ServerCommand("mp_warmup_start");

    // Schedule the knife round to start after 15 seconds
    CreateTimer(15.0, KnifeRound_TimerCallback);

    // Return Plugin_Handled to indicate success
    return Plugin_Handled;
}

public Action KnifeRound_TimerCallback(Handle timer)
{
    // Get the number of players
    int num_players = GetClientCount();

    // Check if there are at least 2 players
    if (num_players < 2) {
        PrintToChatAll("Error: Cannot start knife round with less than 2 players.");
        return Plugin_Handled;
    }

    // Determine the number of duels to create
    int num_duels = num_players / 2;

    // If the number of players is odd, remove one player at random to be a CT loser
    if (num_players % 2 != 0) {
        int loser = RandomInt(1, num_players);
        SetEntProp(loser, Prop_Send, "m_iTeamNum", 3); // Set loser to CT team
        num_duels = (num_players - 1) / 2;
    }

    // Shuffle the player order
    int player_order[num_players];
    for (int i = 0; i < num_players; i++) {
        player_order[i] = i + 1;
    }
    ShuffleArray(player_order, num_players);

    // Start each duel
    for (int i = 0; i < num_duels; i++) {
        int player1 = player_order[i * 2];
        int player2 = player_order[i * 2 + 1];
        PrintToChatAll("Duel: %s vs %s", GetClientName(player1), GetClientName(player2));
        SetEntProp(player1, Prop_Send, "m_iTeamNum", 2); // Set player1 to T team
        SetEntProp(player2, Prop_Send, "m_iTeamNum", 2); // Set player2 to T team
    }

    // Schedule the end of the knife round
    CreateTimer(10.0, Timer_KnifeRoundEnd);
    return Plugin_Handled;
}

public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
    if (strcmp(name, "round_start") == 0)
    {
        int playerCount = GetClientCount();
        if (playerCount >= 2)
        {
            Command_KnifeRound(0, 0);
        }
    }
}

public void Timer_KnifeRoundEnd(Handle timer)
{
    int players[MaxClients+1];
    int playerNum = 0;
    for (int i = 1; i <= MaxClients; i++)
    {
        if (!IsClientInGame(i))
            continue;
        players[playerNum] = i;
        playerNum++;
    }
    int numDuels = playerNum / 2;
    int currentDuel = 0;
    while (currentDuel < numDuels)
    {
        int player1 = players[currentDuel*2];
        int player2 = players[currentDuel*2+1];
        SetClientTeam(player1, Client_Team_Terrorists);
        SetClientTeam(player2, Client_Team_Terrorists);
        currentDuel++;
    }
    if (playerNum % 2 == 1)
    {
        int randomPlayer = players[RandomInt(0, playerNum-1)];
        SetClientTeam(randomPlayer, Client_Team_CounterTerrorists);
    }
}
I would also be happy with a team knife fight instead of duels.

I would really appreciate some help.

Thank you!

Last edited by r14170; 03-07-2023 at 00:03.
r14170 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-07-2023 , 06:07   Re: Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #2

Quote:
Originally Posted by r14170 View Post
Hi there.


...

Since Iam not a good coder, I tried using ChatGPT and here is where we ended up which is not compileable:

...

Thank you!
Tip to everyone, don't. Don't use that tool.
Bacardi is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-07-2023 , 11:49   Re: Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #3

Thanks, will try to do it next time

Last edited by r14170; 03-07-2023 at 11:50.
r14170 is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 03-07-2023 , 16:55   Re: Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #4

Here is some kind idea. But not fully working plugin what you request.


This "dual match" happen on warmup period only. And it pause warmup during that time.

There is timer, what create next "phases".
Plugin also execute config files called "cfg/sourcemod/sm_warmup_duel_phase_x.cfg" on every "phase".
You need replace "x" with number, 0 to 5.

When warmup start, after 15 sec it send messages. In this time players are entering in game also.
After next 15 sec, it create "duel match", pick one player from both team and teleport in specific location in cs_office map.

I repeat, works only cs_office map. Create only one "dual match".

There is no other features, no team change.

In last "phase", warmup timer continue with smaller time to end.



You need enable this "dual match", using cvar
Code:
sm_warmup_duel_enable 1
and then change level to cs_office


-----------

The part of creating "duel matches", keep check who wins and so on, is lot of work.
And I don't know how Hide and Seek mod works. How this plugin work with that.
Attached Files
File Type: sp Get Plugin or Get Source (asd.sp - 34 views - 4.8 KB)
Bacardi is offline
r14170
Veteran Member
Join Date: Dec 2009
Old 03-07-2023 , 22:36   Re: Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #5

Hey, thanks for the reply and for trying!

It did work but it really does not fit my server as I don't even run cs_office
r14170 is offline
Earendil
Senior Member
Join Date: Jan 2020
Location: Spain
Old 03-17-2023 , 08:03   Re: Need help with Knife Round Duels plugin (used CHAT GPT)
Reply With Quote #6

Use ChatGPT to make small pieces of code, or get simple algorythms to solve a very concrete problem, never a full working plugin, because you will get a piece of text with tons of errors. And always check very deeply the code provided, ChatGPT is not a programmer, it doesn't give you a perfect solution. If you want a full plugin, ask a true programmer.

I used ChatGPT to solve small problems that I found while programming, but using the code provided very carefully and checking there are no errors.
__________________
>>My plugins<<
>>GitHub<<

Last edited by Earendil; 03-17-2023 at 08:04.
Earendil is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode