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

sm_setspawn help


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Michael Westen
Junior Member
Join Date: May 2015
Old 06-24-2015 , 18:00   sm_setspawn help
Reply With Quote #1

Hi, I'm trying to add an event to the Set Spawn plugin so that when a player changes class in Tf2, it clears their spawn. But I keep getting error 100 function prototypes do not match on lines 31 and 155.

Code:
#include <sourcemod>
#include <sdktools>
#pragma semicolon 1

#define PLUGIN_VERSION "1.13"

new bool:pSpawnSet[MAXPLAYERS+1];
new Float:pSpawn[MAXPLAYERS+1][3];

new Handle:cEnabled;

public Plugin:myinfo = 
{
	name = "Player Spawns",
	author = "noodleboy347",
	description = "Sets player spawns",
	version = PLUGIN_VERSION,
	url = "http://www.frozencubes.com"
}

public OnPluginStart()
{
	RegConsoleCmd("sm_setspawn", Command_Setspawn);
	RegConsoleCmd("sm_clearspawn", Command_Clearspawn);
	RegAdminCmd("sm_setplayerspawn", Command_Setplayerspawn, ADMFLAG_GENERIC);
	RegAdminCmd("sm_clearplayerspawn", Command_Clearplayerspawn, ADMFLAG_GENERIC);
	CreateConVar("sm_playerspawns_version", PLUGIN_VERSION, "Player Spawns plugin version", FCVAR_NOTIFY);
	cEnabled = CreateConVar("sm_playerspawns_enable", "1", "Enables plugin");
	HookConVarChange(cEnabled, Cvar_Toggle);
	HookEvent("player_spawn", Event_Spawn);
	HookEvent("player_team", Event_TeamsChange);
}

public Cvar_Toggle(Handle:cvar, const String:oldVal[], const String:newVal[])
{
	if(StringToInt(newVal) == 0)
	{
		for(new i=1; i < GetMaxClients(); i++)
		{
			pSpawnSet[i] = false;
		}
	}
}

public OnClientPostAdminCheck(client)
{
	pSpawnSet[client] = false;
}

public Action:Command_Setspawn(client, args)
{
	if(GetConVarBool(cEnabled) && IsPlayerAlive(client))
	{
		GetClientAbsOrigin(client, pSpawn[client]);
		pSpawnSet[client] = true;
		ReplyToCommand(client, "[SM] Spawn location set.");
	}
	return Plugin_Handled;
}

public Action:Command_Clearspawn(client, args)
{
	if(GetConVarBool(cEnabled))
	{
		if(!pSpawnSet[client])
			ReplyToCommand(client, "[SM] You haven't set your spawn yet.");
		else
		{
			ReplyToCommand(client, "[SM] Spawn location cleared.");
			pSpawnSet[client] = false;
		}
	}
	return Plugin_Handled;
}

public Action:Command_Setplayerspawn(client, args)
{
	if(GetConVarBool(cEnabled))
	{
		if(args != 1)
		{
			ReplyToCommand(client, "[SM] Usage: sm_setplayerspawn <player>");
			return Plugin_Handled;
		}
		decl String:arg[64];
		GetCmdArg(1, arg, sizeof(arg));
		decl String:target_name[MAX_TARGET_LENGTH];
		decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
		if((target_count = ProcessTargetString(
				arg,
				client, 
				target_list, 
				MAXPLAYERS, 
				0,
				target_name,
				sizeof(target_name),
				tn_is_ml)) <= 0)
		{
			ReplyToTargetError(client, target_count);
			return Plugin_Handled;
		}
		for(new i = 0; i < target_count; i++)
		{
			GetClientAbsOrigin(client, pSpawn[target_list[i]]);
			pSpawnSet[target_list[i]] = true;
		}
		if(tn_is_ml)
			ShowActivity2(client, "[SM]", "Set the spawn of %s", target_name);
		else
			ShowActivity2(client, "[SM]", "Set the spawn of %s", target_name);
	}
	return Plugin_Handled;	
}

public Action:Command_Clearplayerspawn(client, args)
{
	if(GetConVarBool(cEnabled))
	{
		if(args != 1)
		{
			ReplyToCommand(client, "[SM] Usage: sm_clearplayerspawn <player>");
			return Plugin_Handled;
		}
		decl String:arg[64];
		GetCmdArg(1, arg, sizeof(arg));
		decl String:target_name[MAX_TARGET_LENGTH];
		decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
		if((target_count = ProcessTargetString(
				arg,
				client, 
				target_list, 
				MAXPLAYERS, 
				0,
				target_name,
				sizeof(target_name),
				tn_is_ml)) <= 0)
		{
			ReplyToTargetError(client, target_count);
			return Plugin_Handled;
		}
		for(new i = 0; i < target_count; i++)
			pSpawnSet[target_list[i]] = false;
		if(tn_is_ml)
			ShowActivity2(client, "[SM]", "Cleared the spawn of %s", target_name);
		else
			ShowActivity2(client, "[SM]", "Cleared the spawn of %s", target_name);
	}
	return Plugin_Handled;	
}

public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
	new client = GetClientOfUserId(GetEventInt(event, "userid"));
	if(pSpawnSet[client])
		CreateTimer(0.1, Timer_Spawn, client);
}

public Action:Event_TeamsChange(client, args)
{
	if(GetConVarBool(cEnabled))
	{
		pSpawnSet[client] = false;
		PrintToChat(client, "[SM] Spawn location cleared.");
	}
}

public Action:Timer_Spawn(Handle:timer, const String:name[], any:client)
{
	TeleportEntity(client, pSpawn[client], NULL_VECTOR, NULL_VECTOR);
}
The Red Text is what I added in. Anyone have any ideas or am I doing this all wrong?
Michael Westen is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 06-24-2015 , 19:31   Re: sm_setspawn help
Reply With Quote #2

First, you need to change the Event_TeamsChange signature to match what's expected for an event (as opposed to a command). Same for the timer, which doesn't have a name parameter. Also ensure you pass userids to timer callbacks instead of the client id itself.

PHP Code:
public Action:Event_Spawn(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
userid GetEventInt(event"userid");
    if(
pSpawnSet[GetClientOfUserId(userid)])
        
CreateTimer(0.1Timer_Spawnuserid);
}

public 
Action:Event_TeamsChange(Handle:event, const String:name[], bool:dontBroadcast)
{
  if(
GetConVarBool(cEnabled))
    {
    new 
client GetClientOfUserId(GetEventInt(event"userid"));
    
    if (
client >= 1)
    {
      
pSpawnSet[client] = false;
      
PrintToChat(client"[SM] Spawn location cleared.");
    }
  }
}

public 
Action:Timer_Spawn(Handle:timerany:userid)
{
  new 
client GetClientOfUserId(userid);
  if (
client >= 1)
    
TeleportEntity(clientpSpawn[client], NULL_VECTORNULL_VECTOR);

Finally, for your Cvar_Toggle function, change the following as not only does the MaxClients variable exist, but you need to include that potential last client by using <= instead of <.
PHP Code:
for(new i=1GetMaxClients(); i++) 
To:
PHP Code:
for(new i=1<= MaxClientsi++) 
__________________

Last edited by 11530; 06-24-2015 at 19:36.
11530 is offline
Michael Westen
Junior Member
Join Date: May 2015
Old 06-24-2015 , 19:53   Re: sm_setspawn help
Reply With Quote #3

It worked! Thank you so, so much you have no idea how awesome this is.

Here's the plugin if anybody else wants it. I'll also post it NoodleBoys thread too with kudos to you 11530.
Attached Files
File Type: sp Get Plugin or Get Source (setspawn.sp - 330 views - 4.5 KB)
Michael Westen is offline
Reply


Thread Tools
Display Modes

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:11.


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