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

[TF2] Map Prefix Checking


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fenderic
Junior Member
Join Date: Sep 2009
Old 08-11-2011 , 20:07   [TF2] Map Prefix Checking
Reply With Quote #1

hey, i'm having some trouble compiling my plugin and i was wondering if anyone could give me some insight on how to fix it.

here's the deal. i wrote my plugin and compiled it on the main website, and that worked. but then i decided to add a feature to it, which required me getting SDKHooks. Now I have SDKHooks and am trying to compile on my computer using the executable, but i am running into errors when compiling. The problem is, it's not the part i added for SDKHooks which is stopping it from compiling but its from a part of the code that worked completely fine when using the main site compiler.

I am able to compile this:
Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <tf2_stocks>

#define PLUGIN_VERSION "0.3"
public Plugin:myinfo = 
{
	name = "Glass Attack",
	author = "Fenderic",
	description = "Sniper-only deathmatch with tons of breakable glass!",
	version = PLUGIN_VERSION,
	url = "http://www.moddb.com/mods/glass-attack"
};
//CVars
new Handle:g_Cvar_GlassEnabled;


public Event_PlayerClass(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarBool(g_Cvar_GlassEnabled))
	{
		return;
	}
	new glass_user = GetClientOfUserId(GetEventInt(event, "userid"));
	new glass_user_class  = GetEventInt(event, "class");
	if(glass_user_class != 2)
	{
		TF2_SetPlayerClass(glass_user, TFClassType:2);
	}
}

public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarBool(g_Cvar_GlassEnabled))
	{
		return;
	}
	new glass_user = GetClientOfUserId(GetEventInt(event, "userid"));
	if(TF2_GetPlayerClass(glass_user) != TFClassType:7)
	{
		TF2_SetPlayerClass(glass_user, TFClassType:2);
		if(IsPlayerAlive(glass_user))
		{
			TF2_RespawnPlayer(glass_user);
		}
	}
}

public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}

public Action:OnWeaponSwitch(client, weapon)
{
    decl String:sWeapon[32];
    GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_smg"))
        return Plugin_Handled;
    
    return Plugin_Continue;
}
but i am not able to compile this:
Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <tf2_stocks>

#define PLUGIN_VERSION "0.3"
public Plugin:myinfo = 
{
	name = "Glass Attack",
	author = "Fenderic",
	description = "Sniper-only deathmatch with tons of breakable glass!",
	version = PLUGIN_VERSION,
	url = "http://www.moddb.com/mods/glass-attack"
};
//CVars
new Handle:g_Cvar_GlassEnabled;
new Handle:checkmapname = INVALID_HANDLE;


public OnPluginStart()
{
	CreateConVar("sm_glass_version", PLUGIN_VERSION, "Glass Attack version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_Cvar_GlassEnabled = CreateConVar("sm_glass_enabled", "1", "Enables the Glass Attack plugin", 0, false, 0.0, false, 0.0);
	checkmapname = CreateConVar("glass_checkmapname", "1", "Disables Glass Attack on maps that do not start with 'glass_'.", FCVAR_PLUGIN);
	enabled = GetConVarBool(enabled_cvar);
	// Check map name (if necessary).
	if (enabled && GetConVarBool(checkmapname)) {
		decl String:prefix[6];
		GetCurrentMap(prefix, sizeof(prefix));
		enabled = StrEqual(prefix, "glass_", false);
	}
	if(GetConVarBool(g_Cvar_GlassEnabled))
	{
		HookEvent("player_changeclass", Event_PlayerClass);
		HookEvent("player_spawn", Event_PlayerSpawn);
		
	}
}

public Event_PlayerClass(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarBool(g_Cvar_GlassEnabled))
	{
		return;
	}
	new glass_user = GetClientOfUserId(GetEventInt(event, "userid"));
	new glass_user_class  = GetEventInt(event, "class");
	if(glass_user_class != 2)
	{
		TF2_SetPlayerClass(glass_user, TFClassType:2);
	}
}

public Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	if(!GetConVarBool(g_Cvar_GlassEnabled))
	{
		return;
	}
	new glass_user = GetClientOfUserId(GetEventInt(event, "userid"));
	if(TF2_GetPlayerClass(glass_user) != TFClassType:7)
	{
		TF2_SetPlayerClass(glass_user, TFClassType:2);
		if(IsPlayerAlive(glass_user))
		{
			TF2_RespawnPlayer(glass_user);
		}
	}
}

public OnClientPutInServer(client)
{
    SDKHook(client, SDKHook_WeaponSwitch, OnWeaponSwitch);
}

public Action:OnWeaponSwitch(client, weapon)
{
    decl String:sWeapon[32];
    GetEdictClassname(weapon, sWeapon, sizeof(sWeapon));
    
    if(StrEqual(sWeapon, "tf_weapon_smg"))
        return Plugin_Handled;
    
    return Plugin_Continue;
The second one is the same code, except it has the added ability to turn the plugin on/off depending on map prefix.

I get this error now.
Code:
////glassattack.sp
//C:\HLServer\orangebox\tf\addons\sourcemod\scripting\glassattack.sp<25> :error 017: undefined symbol "enabled"
//C:\HLServer\orangebox\tf\addons\sourcemod\scripting\glassattack.sp<25> :error 017: undefined symbol "enabled_cvar"
//C:\HLServer\orangebox\tf\addons\sourcemod\scripting\glassattack.sp<27> :error 017: undefined symbol "enabled"
//C:\HLServer\orangebox\tf\addons\sourcemod\scripting\glassattack.sp<30> :error 017: undefined symbol "enabled"
//
// 4 Errors.
So basically, part of my plugin can only be compiled using the website compiler, and part of it can only be compiled using the executable compiler.

I was wondering if anyone has a solution to this?
maybe there would be a different way to code the following?
Code:
public OnPluginStart()
{
	CreateConVar("sm_glass_version", PLUGIN_VERSION, "Glass Attack version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
	g_Cvar_GlassEnabled = CreateConVar("sm_glass_enabled", "1", "Enables the Glass Attack plugin", 0, false, 0.0, false, 0.0);
	checkmapname = CreateConVar("glass_checkmapname", "1", "Disables Glass Attack on maps that do not start with 'glass_'.", FCVAR_PLUGIN);
	enabled = GetConVarBool(enabled_cvar);
	// Check map name (if necessary).
	if (enabled && GetConVarBool(checkmapname)) {
		decl String:prefix[6];
		GetCurrentMap(prefix, sizeof(prefix));
		enabled = StrEqual(prefix, "glass_", false);
	}
	if(GetConVarBool(g_Cvar_GlassEnabled))
	{
		HookEvent("player_changeclass", Event_PlayerClass);
		HookEvent("player_spawn", Event_PlayerSpawn);
		
	}
}
all i am trying to do is make it so that it checks for a map prefix to be there or else to not run the plugin.

Thank you very much, I'm new to this and appreciate the help!
Fenderic is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 08-11-2011 , 20:35   Re: [TF2] Map Prefix Checking
Reply With Quote #2

PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <tf2_stocks>

#define PLUGIN_VERSION "0.3"
public Plugin:myinfo 
{
    
name "Glass Attack",
    
author "Fenderic",
    
description "Sniper-only deathmatch with tons of breakable glass!",
    
version PLUGIN_VERSION,
    
url "http://www.moddb.com/mods/glass-attack"
};
//CVars
new Handle:g_Cvar_GlassEnabled;
new 
Handle:checkmapname INVALID_HANDLE;


public 
OnPluginStart()
{
    
CreateConVar("sm_glass_version"PLUGIN_VERSION"Glass Attack version"FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
    
g_Cvar_GlassEnabled CreateConVar("sm_glass_enabled""1""Enables the Glass Attack plugin"0false0.0false0.0);
    
checkmapname CreateConVar("glass_checkmapname""1""Disables Glass Attack on maps that do not start with 'glass_'."FCVAR_PLUGIN);
    new 
bool:enabled GetConVarBool(g_Cvar_GlassEnabled);
    
// Check map name (if necessary).
    
if (enabled && GetConVarBool(checkmapname)) {
        
decl String:prefix[6];
        
GetCurrentMap(prefixsizeof(prefix));
        
enabled StrEqual(prefix"glass_"false);
    }
    if(
GetConVarBool(g_Cvar_GlassEnabled))
    {
        
HookEvent("player_changeclass"Event_PlayerClass);
        
HookEvent("player_spawn"Event_PlayerSpawn);
        
    }
}

public 
Event_PlayerClass(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
GetConVarBool(g_Cvar_GlassEnabled))
    {
        return;
    }
    new 
glass_user GetClientOfUserId(GetEventInt(event"userid"));
    new 
glass_user_class  GetEventInt(event"class");
    if(
glass_user_class != 2)
    {
        
TF2_SetPlayerClass(glass_userTFClassType:2);
    }
}

public 
Event_PlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    if(!
GetConVarBool(g_Cvar_GlassEnabled))
    {
        return;
    }
    new 
glass_user GetClientOfUserId(GetEventInt(event"userid"));
    if(
TF2_GetPlayerClass(glass_user) != TFClassType:7)
    {
        
TF2_SetPlayerClass(glass_userTFClassType:2);
        if(
IsPlayerAlive(glass_user))
        {
            
TF2_RespawnPlayer(glass_user);
        }
    }
}

public 
OnClientPutInServer(client)
{
    
SDKHook(clientSDKHook_WeaponSwitchOnWeaponSwitch);
}

public 
Action:OnWeaponSwitch(clientweapon)
{
    
decl String:sWeapon[32];
    
GetEdictClassname(weaponsWeaponsizeof(sWeapon));
    
    if(
StrEqual(sWeapon"tf_weapon_smg"))
    return 
Plugin_Handled;
    
    return 
Plugin_Continue;

This line was your problem
PHP Code:
enabled GetConVarBool(enabled_cvar); 
It should have been
PHP Code:
 new bool:enabled GetConVarBool(g_Cvar_GlassEnabled); 
Also you didn't put a } at the end of one of your statements.
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
Fenderic
Junior Member
Join Date: Sep 2009
Old 08-13-2011 , 15:04   Re: [TF2] Map Prefix Checking
Reply With Quote #3

hmm, well that certainly lets it compile, but when i try to run it on my server, my console floods with errors.
it says "[SM] plugin encountered error 8: Not enough space on the stack"
then "[SM] Displaying call stack trace for plugin "glassattack.smx""
the next 4 lines are like this:
[SM] [0] Line78 C:\HLServer\.....\scripting\glassattack.sp::O nWeaponSwitch()

so i guess for some reason those 2 parts of it still do not co-operate.

oh and i was able to join the server, but i couldn't walk or switch my weapons, and it forced me to be sniper, even though i wasn't on a map with the prefix "glass_"

Maybe I should just try and check the map prefix some other way?
Fenderic is offline
AtomicStryker
Veteran Member
Join Date: Apr 2009
Location: Teutonia!!
Old 08-13-2011 , 16:20   Re: [TF2] Map Prefix Checking
Reply With Quote #4

PHP Code:
decl String:sWeapon[32]; 
Raise that string "stack" size.
AtomicStryker is offline
Fenderic
Junior Member
Join Date: Sep 2009
Old 08-14-2011 , 19:41   Re: [TF2] Map Prefix Checking
Reply With Quote #5

Quote:
Originally Posted by AtomicStryker View Post
PHP Code:
decl String:sWeapon[32]; 
Raise that string "stack" size.
I tried raising it to 64, but then whenever i try to connect, my connection times out and an Engine Error pops up on the computer i am using to host that says "ED_Alloc: no free edicts"

i feel like the problem shouldn't be with the gun blocking, but i think it is with the map prefix checking
did you mean to change this part?
Quote:
decl String:prefix[6];

Last edited by Fenderic; 08-14-2011 at 19:58.
Fenderic is offline
McFlurry
Veteran Member
Join Date: Mar 2010
Location: RemoveEdict(0);
Old 08-14-2011 , 20:35   Re: [TF2] Map Prefix Checking
Reply With Quote #6

A few problems.
1. You're checking the map on OnPluginStart(); that's wrong.
2. You're checking if the maps' name is glass_
3. enabled is only changed after you check enabled and is never used again.
4. Change if(!GetConVarBool(g_Cvar_GlassEnabled)) to if(!enabled)
__________________
McFlurry is offline
Send a message via Skype™ to McFlurry
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 13:08.


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