Event chest_capture Problems

dycemandyceman Senior
edited October 2012 in Scripting
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>

new Zones[3][1];
new TeamChests[3];

public Plugin:myinfo =
	name = "PVK Wars",
	author = "Unknown",
	description = "<- Description ->",
	version = "1.0",
	url = "<- URL ->"

public OnPluginStart(){
HookEvent("chest_capture", OnCapture)
PrintToServer("PVK Wars Loaded");
public Action:OnCapture(Handle:event, String:name[], bool:dontBroadcast){

new client = GetEventInt(event, "userid");

/* if(IsClientInGame(client) && !IsFakeClient(client) && IsClientConnected(client)){
  PrintToChatAll("Client: %i", client);
  if(GetClientTeam(client) == 4){
   TeamChests[2] = TeamChests[2] +1;
   PrintToChatAll("Team Chest Count: %i", TeamChests[2]);

  TeamChests[2] = TeamChests[2] +1;
  PrintToChatAll("Team Chest Count: %i, Team: %i", TeamChests[2], GetClientTeam(client));

When I capture a chest it doesn't use my client id. I think it is using one above my ID. If I was to delete the below line from the code then the server screams Client 2 isn't ingame.

Edit: Notice that the event is getting the index above yours. You have to minus 1 from the client index when your using this event.


  • MadKatMadKat Senior
    edited October 2012
    I see your edit, but you are still going to run into problems down the road without a fix. When you work with SourceMod, you need to be aware of the difference between a userid and a client id. Userid is a unique id for the player on your server, where client id can be considered between 1 and the max number of players. A player may have a different client id every time.

    If you need the client id, you need this line in your event:

    new client = GetClientOfUserId(GetEventInt(event, "userid"));
    Programmer, Swashbuckler
    Author of PVKII Randomizer
    Author of PVKII WeaponsMaster
Sign In or Register to comment.