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

Adaptation of the plugin to sm 1.10


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
szogun
Senior Member
Join Date: Apr 2016
Old 12-02-2019 , 10:54   Adaptation of the plugin to sm 1.10
Reply With Quote #1

Can you help me adapt the plugin to version 1.10 for, because after changing it the server will crash


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

#pragma semicolon                1
#pragma newdecls                required

#define MAX_PLAYERS                64

#define TEAM_CT                    2
#define TEAM_TT                    3

public Plugin myinfo =
{
    
name "Knife Round",
    
author "Maciej Wrzesinski",
    
description "Plugin sets up an additional knife round after warmup ends",
    
version "1.3",
    
url "https://github.com/maciej-wrzesinski/"
};

bool g_bKnifeRoundEnded false;

int g_iRoundNumber 0;
int g_iWonTeam 0;

int iClientsNumWinners 0;
int iClientsWinnersID[MAX_PLAYERS 1];
int iClientsWinnersDecision[MAX_PLAYERS 1];

ConVar cvInfo;
ConVar cvTime;
ConVar cvVote;
ConVar cvAllowAllTalk;
ConVar cvBuyTimeNormal;
ConVar cvBuyTimeImmunity;
ConVar cvTalkDead;
ConVar cvTalkLiving;

int        g_iCvarInfo;
float    g_fCvarRoundTime;
float    g_fCvarVoteTime;
int        g_iCvarAllowAllTalk;
float    g_fCvarBuyTimeNormal;
float    g_fCvarBuyTimeImmunity;
int        g_iCvarTalkDead;
int        g_iCvarTalkLiving;

Handle g_hHUD;

public 
void OnPluginStart()
{
    
HookEvent("round_start"RoundStart);
    
HookEvent("round_end"RoundEnd);
    
HookEvent("player_spawn"PlayerSpawn);
    
    
cvInfo CreateConVar("knifer_info""2""How should messages be displayed? (0 - none, 1 - chat, 2 - HUD)"_true0.0true2.0);
    
cvTime CreateConVar("knifer_roundtime""60.0""How much time should knife round take? (0.5 to 60.0 minutes)"_true0.5true60.0);
    
cvVote CreateConVar("knifer_votetime""10.0""How much time should vote take? (5 to 20 seconds)"_true5.0true20.0);
    
cvAllowAllTalk CreateConVar("knifer_alltalk""1""Should there be alltalk enabled while knife round? (1 - enabled, 0 - disabled)"_true0.0true1.0);
    
    
cvBuyTimeNormal FindConVar("mp_buytime");
    
cvBuyTimeImmunity FindConVar("mp_buy_during_immunity");
    
cvTalkDead FindConVar("sv_talk_enemy_dead");
    
cvTalkLiving FindConVar("sv_talk_enemy_living");
    
    
g_bKnifeRoundEnded false;
    
g_iRoundNumber 0;
    
    
g_hHUD CreateHudSynchronizer();
    
    
AutoExecConfig(true"knife_round");
    
LoadTranslations("knife_round.phrases");
}

public 
void OnConfigsExecuted()
{
    
g_iCvarInfo GetConVarInt(cvInfo);
    
g_fCvarRoundTime GetConVarFloat(cvTime);
    
g_fCvarVoteTime GetConVarFloat(cvVote);
    
g_iCvarAllowAllTalk GetConVarInt(cvAllowAllTalk);
    
    
g_fCvarBuyTimeNormal GetConVarFloat(cvBuyTimeNormal);
    
g_fCvarBuyTimeImmunity GetConVarFloat(cvBuyTimeImmunity);
    
g_iCvarTalkDead GetConVarInt(cvTalkDead);
    
g_iCvarTalkLiving GetConVarInt(cvTalkLiving);
}

public 
void OnMapStart()
{
    
g_bKnifeRoundEnded false;
    
g_iRoundNumber 0;
}

public 
void OnMapEnd()
{
    
g_bKnifeRoundEnded false;
    
g_iRoundNumber 0;
}

public 
Action PlayerSpawn(Handle event, const char[] namebool dontBroadcast)
{
    if (
g_iRoundNumber == && g_bKnifeRoundEnded == false)
        
StripOnePlayerWeapons(GetClientOfUserId(GetEventInt(event"userid")));
}

public 
Action RoundStart(Handle event, const char[] namebool dontBroadcast)
{
    if (
GetClientCountInTeams() < || GameRules_GetProp("m_bWarmupPeriod"))
    {
        
g_iRoundNumber 0;
        
g_bKnifeRoundEnded false;
        return;
    }
    
    if (
g_bKnifeRoundEnded)
        return;
    
    
    
g_iRoundNumber++;
    
    if (
g_iRoundNumber == 1)
        
PrepareForKnifeRound();
    
    else if(
g_iRoundNumber == && g_bKnifeRoundEnded == false//round after warmup = knife round
    
{
        
        
#if defined UNLOAD_KENTO_RANKME
        
ServerCommand("sm plugins unload kento_rankme");
#endif
        
        
        
CreateTimer(0.5TimerStripWeapons);
        
        
char cTempTextHUD[256];
        
Format(cTempTextHUDsizeof(cTempTextHUD), "%t""Knife_Start");
        
SendTextToAll(cTempTextHUD);
    }
}

public 
Action RoundEnd(Handle event, const char[] namebool dontBroadcast)
{
    if (
GetClientCountInTeams() < || GameRules_GetProp("m_bWarmupPeriod"))
    {
        
g_iRoundNumber 0;
        
g_bKnifeRoundEnded false;
        return;
    }
    
    if (
g_bKnifeRoundEnded)
        return;
    
    if (
g_iRoundNumber == 2//end of knife round
    
{
        
        
#if 
        
ServerCommand("sm plugins load kento_rankme");
#endif
        
        
        
g_bKnifeRoundEnded true;
        
AfterKnifeRound();
        
        
g_iWonTeam GetEventInt(event"winner");
        if (
g_iWonTeam != TEAM_CT && g_iWonTeam != TEAM_TT)
        {
            
char cTempTextHUD[256];
            
Format(cTempTextHUDsizeof(cTempTextHUD), "%t""Win_None");
            
SendTextToAll(cTempTextHUD);
            
            
RestartLastTime();
        }
        else
            
MakeVote();
    }
}

stock void MakeVote()
{
    
char cTempTextHUD[256];
    
Format(cTempTextHUDsizeof(cTempTextHUD), "%t""Voting_Start");
    
SendTextToAll(cTempTextHUD);
    
    
iClientsNumWinners 0;
    for (
int i 1;<= MAX_PLAYERS;i++) //counting winning guys to show them a menu
    
        
if (IsClientValid(i) && !IsClientSourceTV(i))
        
            if (
GetClientTeam(i) == g_iWonTeam)
            {
                
iClientsWinnersID[iClientsNumWinners] = i;
                ++
iClientsNumWinners;
            }
    
    
Handle hMenu CreateMenu(ShowVotingMenuHandle);
    
char cTempBuffer[128];
    
Format(cTempBuffersizeof(cTempBuffer), "%t""Menu_Title");
    
SetMenuTitle(hMenucTempBuffer);
    
    
AddMenuItem(hMenu"CT""CT");
    
AddMenuItem(hMenu"TT""TT");
    
    
SetMenuExitButton(hMenufalse);
    
SetMenuExitBackButton(hMenufalse);
    for(
int i 0iClientsNumWinnersi++)
    
DisplayMenu(hMenuiClientsWinnersID[i], RoundFloat(g_fCvarVoteTime));
    
CreateTimer(g_fCvarVoteTimeEndTheVote);
}

public 
int ShowVotingMenuHandle(Handle hMenuMenuAction actionint clientint choose)
{
    if(
action == MenuAction_End)delete hMenu;
    else if (
action == MenuAction_Select)
    {
        
choose += 2;
        if (
choose == TEAM_CT)
            
iClientsWinnersDecision[client] = TEAM_CT;
        else if (
choose == TEAM_TT)
            
iClientsWinnersDecision[client] = TEAM_TT;
    }


public 
Action EndTheVote(Handle hTimer)
{
    
int iCTNum 0;
    
int iTTNum 0;
    for (
int i 1<= MAX_PLAYERSi++) //counting winning guys to show them a menu
    
        
if (IsClientValid(i) && !IsClientSourceTV(i))
        
            switch(
iClientsWinnersDecision[i])
            {
                case 
TEAM_CT: { ++iCTNum; }
                case 
TEAM_TT: { ++iTTNum; }
            }
    
    
int iWantedTeam 0;
    
bool bDoSwap false;
    
    if (
iCTNum >= iTTNum)
        
iWantedTeam TEAM_CT;
    else
        
iWantedTeam TEAM_TT;
    
    
g_iWonTeam g_iWonTeam == TEAM_CT TEAM_TT TEAM_CT;
    
    
    if (
g_iWonTeam != iWantedTeam)
        
bDoSwap true;
    
    
    if (
bDoSwap)
    {
        
char cTempTextHUD[256];
        
Format(cTempTextHUDsizeof(cTempTextHUD), "%t""Winning_Swap");
        
SendTextToAll(cTempTextHUD);
        
        
RestartSwapLastTime();
    }
    else
    {
        
char cTempTextHUD[256];
        
Format(cTempTextHUDsizeof(cTempTextHUD), "%t""Winning_Stay");
        
SendTextToAll(cTempTextHUD);
        
        
RestartLastTime();
    }
}

stock void PrepareForKnifeRound()
{
    if (
g_iCvarAllowAllTalk)
    {
        
ServerCommand("sv_talk_enemy_dead 1");
        
ServerCommand("sv_talk_enemy_living 1");
    }
    
ServerCommand("mp_roundtime %f"g_fCvarRoundTime);
    
ServerCommand("mp_roundtime_defuse %f"g_fCvarRoundTime);
    
ServerCommand("mp_buytime 0");
    
ServerCommand("mp_buy_during_immunity 0");
    
ServerCommand("mp_startmoney 0");
    
ServerCommand("mp_restartgame 1");
}

stock void AfterKnifeRound()
{
    if (
g_iCvarAllowAllTalk)
    {
        
ServerCommand("sv_talk_enemy_dead %i"g_iCvarTalkDead);
        
ServerCommand("sv_talk_enemy_living %i"g_iCvarTalkLiving);
    }
    
ServerCommand("mp_roundtime 1.92");
    
ServerCommand("mp_roundtime_defuse 1.92");
    
ServerCommand("mp_pause_match");
}

stock void RestartLastTime()
{
    
ServerCommand("mp_buytime %f"g_fCvarBuyTimeNormal);
    
ServerCommand("mp_buy_during_immunity %f"g_fCvarBuyTimeImmunity);
    
ServerCommand("mp_startmoney 800");
    
ServerCommand("mp_unpause_match");
    
ServerCommand("mp_restartgame 1");
}

stock void RestartSwapLastTime()
{
    
ServerCommand("mp_buytime %f"g_fCvarBuyTimeNormal);
    
ServerCommand("mp_buy_during_immunity %f"g_fCvarBuyTimeImmunity);
    
ServerCommand("mp_startmoney 800");
    
ServerCommand("mp_unpause_match");
    
ServerCommand("mp_swapteams");
}

public 
Action TimerStripWeapons(Handle timer)
{
    
StripAllPlayersWeapons();
}

stock void StripAllPlayersWeapons()
{
    for (
int i 1<= MAX_PLAYERSi++)
        
StripOnePlayerWeapons(i);
}

stock void StripOnePlayerWeapons(int client)
{
    if (
IsClientValid(client) && IsPlayerAlive(client))
    {
        
int iTempWeapon = -1;
        for (
int i 05i++)
            if ((
iTempWeapon GetPlayerWeaponSlot(clienti)) != -1)
                if (
IsValidEntity(iTempWeapon))
                {
                    --
i;
                    
SafeRemoveWeapon(clientiTempWeapon);
                }
        
        
GivePlayerItem(client"weapon_knife");
        
ClientCommand(client"slot3");
    }
}

/*
    https://forums.alliedmods.net/archive/index.php/t-288614.html
    thanks for SafeRemoveWeapon stock
*/

stock bool SafeRemoveWeapon(int clientint weapon)
{
    if (!
IsValidEntity(weapon) || !IsValidEdict(weapon))
        return 
false;
    
    if (!
HasEntProp(weaponProp_Send"m_hOwnerEntity"))
        return 
false;
    
    
int iOwnerEntity GetEntPropEnt(weaponProp_Send"m_hOwnerEntity");
    
    if (
iOwnerEntity != client)
        
SetEntPropEnt(weaponProp_Send"m_hOwnerEntity"client);
    
    
CS_DropWeapon(clientweaponfalse);
    
    if (
HasEntProp(weaponProp_Send"m_hWeaponWorldModel"))
    {
        
int iWorldModel GetEntPropEnt(weaponProp_Send"m_hWeaponWorldModel");
        
        if (
IsValidEdict(iWorldModel) && IsValidEntity(iWorldModel) && !AcceptEntityInput(iWorldModel"Kill"))
            return 
false;
    }
    
    if (!
AcceptEntityInput(weapon"Kill"))
        return 
false;
    
    return 
true;
}

stock bool IsClientValid(int client)
{
    return (
client && client <= MAX_PLAYERS && IsClientInGame(client));
}

stock int GetClientCountInTeams()
{
    
int iTempSum 0;
    for (
int i 1<= MAX_PLAYERSi++)
        if (
IsClientValid(i) && IsClientAuthorized(i) && !IsClientSourceTV(i) && (GetClientTeam(i) == TEAM_CT || GetClientTeam(i) == TEAM_TT))
            ++
iTempSum;
    
    return 
iTempSum;
}

stock void SendTextToAll(char[] text)
{
    if (
g_iCvarInfo == 1)
        
PrintToChatAll(text);
    else if (
g_iCvarInfo == 2)
    {
        
Handle hData CreateDataPack();
        
WritePackString(hDatatext);
        
        
CreateTimer(2.0FixHUDmsghData);
    }
}

public 
Action FixHUDmsg(Handle hTimerHandle hData)
{
    
ResetPack(hData);
    
    
char cTempText[256];
    
ReadPackString(hDatacTempTextsizeof(cTempText));
    
    for (
int i 1<= MAX_PLAYERSi++)
        if (
IsClientValid(i))
        {
            
SetHudTextParams(-1.0, -1.04.025525525520000.00.00.0);
            
ShowSyncHudText(ig_hHUDcTempText);
        }

szogun is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-02-2019 , 17:49   Re: Adaptation of the plugin to sm 1.10
Reply With Quote #2

Try to comment this line

Spoiler
__________________

Last edited by Marttt; 12-02-2019 at 17:50.
Marttt is offline
szogun
Senior Member
Join Date: Apr 2016
Old 12-03-2019 , 08:20   Re: Adaptation of the plugin to sm 1.10
Reply With Quote #3

For what purpose?
The problem is not in disabling / enabling the kento rankme plugin

As I noticed, the plugin has a problem to correctly vote for the team
szogun is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 12-03-2019 , 14:30   Re: Adaptation of the plugin to sm 1.10
Reply With Quote #4

Sorry but the code snippet you shared doesn't even compile in my SM 1.10 because of this lines
I had to comment to make it run. So I thought that it could be the issue.

The information you provided is not that helpful.

Quote:
after changing it the server will crash
BTW in case it is really that line here is the commented code attached.
Attached Files
File Type: sp Get Plugin or Get Source (pluginsm.sp - 113 views - 11.7 KB)
__________________

Last edited by Marttt; 12-03-2019 at 14:40.
Marttt is offline
szogun
Senior Member
Join Date: Apr 2016
Old 12-03-2019 , 15:23   Re: Adaptation of the plugin to sm 1.10
Reply With Quote #5

The plugin compiles correctly, it only informs about the old menu structure

HTML Code:
//// knife_round.sp
//
// knife_round.sp(221) : warning 234: symbol "IsValidHandle" is marked as deprec
ated: Do not use this function.
//
//
// Code size:            10856 bytes
// Data size:             4372 bytes
// Stack/heap size:      16384 bytes
// Total requirements:   31612 bytes
//
// 1 Warning.
//
// Compilation Time: 0,3 sec
// ----------------------------------------
Attached Files
File Type: sp Get Plugin or Get Source (knife_round.sp - 108 views - 10.4 KB)
szogun 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 22:21.


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