PDA

View Full Version : teamplay_round_win event problem


beatcomet
12-28-2011, 18:34
I started making a plugin that does something when a round ends but it didn't work, so I wrote a plugin to test the event :

* Plugin Template generated by Pawn Studio */

#include <sourcemod>

public Plugin:myinfo =
{
name = "New Plugin",
author = "Unknown",
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}

public OnPluginStart()
{
HookEvent("teamplay_round_win", Event_RoundWin, EventHookMode_Post);
}
public Action:Event_RoundWin(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 0; i < MAXPLAYERS; i++)
{
new Team = GetEventInt(event, "team");
if(GetClientTeam(i) == Team)
{
PrintToChat(i, "You won");
}
else
{
PrintToChat(i, "You lost");
}
}
}

of course nothing happened, can anyone help me with that?

TnTSCS
12-28-2011, 18:38
your loop should be:

for(new i=1; i <= MaxClients; i++)

Client 0 is console... true players start at 1 and end at MaxClients... and use MaxClients (http://docs.sourcemod.net/api/index.php?fastload=show&id=397&) in stead of MAXPLAYERS

Also, you should only print that message to people who are on a valid team that can win or lose

beatcomet
12-28-2011, 18:53
Thanks for the corrections but are you sure that it's going to work?

TnTSCS
12-28-2011, 19:02
You also need to properly comment out the first line or just remove it...

the following code compiles - I'm pretty sure it will print those two messages (albeit the losing message to spectators as well):


/* Plugin Template generated by Pawn Studio */

#include <sourcemod>

public Plugin:myinfo =
{
name = "New Plugin",
author = "Unknown",
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}

public OnPluginStart()
{
HookEvent("teamplay_round_win", Event_RoundWin);
}
public Event_RoundWin(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 1; i <= MaxClients; i++)
{
new Team = GetEventInt(event, "team");
if(GetClientTeam(i) == Team)
{
PrintToChat(i, "You won");
}
else
{
PrintToChat(i, "You lost");
}
}
}

I changed it to not be Event mode post... therefore, removed the Action: from the call

Dr!fter
12-28-2011, 21:07
You also need to properly comment out the first line or just remove it...

the following code compiles - I'm pretty sure it will print those two messages (albeit the losing message to spectators as well):


/* Plugin Template generated by Pawn Studio */

#include <sourcemod>

public Plugin:myinfo =
{
name = "New Plugin",
author = "Unknown",
description = "<- Description ->",
version = "1.0",
url = "<- URL ->"
}

public OnPluginStart()
{
HookEvent("teamplay_round_win", Event_RoundWin);
}
public Event_RoundWin(Handle:event, const String:name[], bool:dontBroadcast)
{
for(new i = 1; i <= MaxClients; i++)
{
new Team = GetEventInt(event, "team");
if(GetClientTeam(i) == Team)
{
PrintToChat(i, "You won");
}
else
{
PrintToChat(i, "You lost");
}
}
}

I changed it to not be Event mode post... therefore, removed the Action: from the call

You need to check that i (the client) is in game. Or else GetClientTeam will error :P

TnTSCS
12-28-2011, 21:58
You need to check that i (the client) is in game. Or else GetClientTeam will error :P

That's right... due to the loop, it will loop through all client indexes... ensuring that the client is in game is a must :)

beatcomet
12-29-2011, 06:10
What is the difference between MaxClients and MAXPLAYERS?

Tylerst
12-29-2011, 07:24
What is the difference between MaxClients and MAXPLAYERS?

MaxClients is a dynamic value that gives the maximum amount of players for the server.

MAXPLAYERS is a hard coded value of the maximum amount of players Sourcemod supports(currently 65)

beatcomet
12-29-2011, 14:54
If I will change it from MAXPLAYERS to MaxClients, will it have any effect on the plugin?

lokizito
01-01-2012, 11:48
If I will change it from MAXPLAYERS to MaxClients, will it have any effect on the plugin?
If you have a 24 slots server. there is no need to loop through all 65 possible clients. So, that is the effect on the plugin, makes it more optimized.
Also, remember to use IsClientInGame to check if the client is connected and in game otherwise the GetClientTeam will fail.