Raised This Month: $ Target: $400
 0% 

I need help fixing this script (AGAIN)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Cyriv
Member
Join Date: Mar 2020
Old 10-24-2023 , 14:31   I need help fixing this script (AGAIN)
Reply With Quote #1

So I decided to rework the script and I'm getting some errors while compiling it and i swapped the teams of Soldier & Demoman. It's a class restricted gamemode of where Red Soldiers fight Blue Demos
I need some help fighting this if possible.
Attached Files
File Type: sp Get Plugin or Get Source (DemoVsSoldierReWork.sp - 27 views - 3.1 KB)
Cyriv is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 10-24-2023 , 16:00   Re: I need help fixing this script (AGAIN)
Reply With Quote #2

PHP Code:
#include <tf2>
#include <tf2_stocks>

ConVar g_hClassRestrict;
bool bRestrict;

public 
Plugin myinfo =
{
    
name "Team Class Restriction",
    
author "Cyriv",
    
description "A plugin that restricts the blue team to demoman and the red team to soldier",
    
version "1.0",
}

public 
void OnPluginStart()
{
    
// Register a command that can be used by admins to toggle the plugin on or off
    
RegAdminCmd("sm_classrestrict"Command_ClassRestrictADMFLAG_CONVARS"Toggle class restriction plugin");

    
// Create a global variable to store the plugin state
    
g_hClassRestrict CreateConVar("sm_classrestrict_enabled""1""Enable or disable class restriction plugin"_true_true1.0);
    
g_hClassRestrict.AddChangeHook(CVarChange);
    
bRestrict g_hClassRestrict.BoolValue;

    
// Hook the event that fires when a player spawns
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
void CVarChange(ConVar cvar, const char[] oldValue, const char[] newValue)
{
    
bRestrict cvar.BoolValue;
}

public 
Action Command_ClassRestrict(int clientint args)
{
    
PrintToChatAll("Class restriction plugin is now %s."bRestrict "enabled" "disabled");
    
SetConVarBool(g_hClassRestrict, !bRestrict);
    return 
Plugin_Handled;
}

public 
Action Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    if (!
bRestrict)
        return 
Plugin_Continue;

    
int client GetClientOfUserId(event.GetInt("userid"));
    if(!
client || !IsClientInGame(client))
        return 
Plugin_Continue;

    
// Get the player's team and class
    
TFTeam team TF2_GetClientTeam(client);
    
TFClassType class = TF2_GetPlayerClass(client);

    
// Check if the player's team and class are valid
    
if(team == TFTeam_Unassigned || team == TFTeam_Spectator || class == TFClass_Unknown)
        return 
Plugin_Continue;

    
// Check if the player's class matches the team restriction
    
if((team == TFTeam_Blue && class != TFClass_DemoMan) || (team == TFTeam_Red && class != TFClass_Soldier))
    {
        
// Force the player to change class
        
TF2_SetPlayerClass(clientteam == TFTeam_Blue TFClass_DemoMan TFClass_Soldier);

        
// Print a message to the player
        
PrintToChat(client"You can only play as %s on this team."team == TFTeam_Blue "demoman" "soldier");

        
// Return Plugin_Handled to prevent other plugins from interfering
        
return Plugin_Handled;
    }

    
// Return Plugin_Continue to allow other plugins to process the event
    
return Plugin_Continue;

__________________
Grey83 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 08:49.


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