Quote:
Originally Posted by Powerlord
When is this code running? If it's OnMapStart, that's why it's failing; the game disconnects all players between map changes even between maps in the same campaign.
|
No, It's on public event_witch_harasser_set(Handle:event, const String:name[], bool:dontBroadcast).
And after testing several times, Im getting different runtime errors. It seems sourcemod is bugged.
full code:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
#define PLUGIN_VERSION "1.0.0"
#define MAXCLIENTS GetMaxClients()
#define IS_VALID_CLIENT(%1) (%1 > 0 && %1 <= MaxClients)
#define IS_CONNECTED_INGAME(%1) (IsClientConnected(%1) && IsClientInGame(%1))
#define IS_SURVIVOR(%1) (GetClientTeam(%1) == 2)
#define IS_INFECTED(%1) (GetClientTeam(%1) == 3)
#define IS_VALID_INGAME(%1) (IS_VALID_CLIENT(%1) && IS_CONNECTED_INGAME(%1))
#define IS_VALID_SURVIVOR(%1) (IS_VALID_INGAME(%1) && IS_SURVIVOR(%1))
#define IS_VALID_INFECTED(%1) (IS_VALID_INGAME(%1) && IS_INFECTED(%1))
#define IS_SURVIVOR_ALIVE(%1) (IS_VALID_SURVIVOR(%1) && IsPlayerAlive(%1))
#define IS_INFECTED_ALIVE(%1) (IS_VALID_INFECTED(%1) && IsPlayerAlive(%1))
#define IS_SURVIVOR_DEAD(%1) (IS_VALID_SURVIVOR(%1) && !IsPlayerAlive(%1))
#define IS_INFECTED_DEAD(%1) (IS_VALID_INFECTED(%1) && !IsPlayerAlive(%1))
new Handle:l4d_random_witcher_enable;
new Handle:l4d_random_witcher_take_alive;
new Handle:l4d_random_witcher_take_dead;
public Plugin:myinfo =
{
name = "Random Witch target",
author = "Axel Juan Nieves",
description = "Makes startled witch think other person startled her",
version = PLUGIN_VERSION,
url = ""
};
public OnPluginStart()
{
// Require Left 4 Dead 1/2
decl String:game_name[64];
GetGameFolderName(game_name, sizeof(game_name));
if (StrContains(game_name, "left4dead")<0)
{
SetFailState("Use this in Left 4 Dead 1/2 only.");
}
// Create convars
CreateConVar("l4d_random_witcher_version ", PLUGIN_VERSION, "", 0|FCVAR_DONTRECORD);
l4d_random_witcher_enable = CreateConVar("l4d_random_witcher_enable", "1", "Enable/Disable this plugin.", 0);
l4d_random_witcher_take_alive = CreateConVar("l4d_random_witcher_take_alive", "1", "Witch can take alive players", 0);
l4d_random_witcher_take_dead = CreateConVar("l4d_random_witcher_take_dead", "1", "Witch can take dead players", 0);
AutoExecConfig(true, "l4d_random_witcher");
HookEvent("witch_harasser_set", event_witch_harasser_set, EventHookMode_Pre);
}
public event_witch_harasser_set(Handle:event, const String:name[], bool:dontBroadcast)
{
if ( !GetConVarInt(l4d_random_witcher_enable) )
return;
new witch_id = GetEventInt(event, "witchid");
new witch_target = GetClientOfUserId(GetEventInt(event, "userid"));
if (witch_id == 0)
return;
if (!IS_VALID_SURVIVOR(witch_target))
return;
new possible_clients[MAXCLIENTS+1];
new max_index = 0;
for (new i=1; i<=MAXCLIENTS; i++)
{
if (!IsClientConnected(i))
{
PrintToChatAll("Client(%i) 77", i);
continue;
}
if (!IsClientInGame(i))
{
PrintToChatAll("Client(%i) 82", i);
continue;
}
if (GetClientTeam(GetClientUserId(i))!=2)
{
//PrintToChatAll("Client(%i) Team(%i) 87", i, GetClientTeam(i));
continue;
}
if (!IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_alive) )
{
//PrintToChatAll("Client(%i) 92", i);
continue;
}
if (IsPlayerAlive(i) && GetConVarInt(l4d_random_witcher_take_dead) )
{
//PrintToChatAll("Client(%i) 97", i);
continue;
}
possible_clients[max_index] = i;
PrintToChatAll("Client(%i) collected", i);
max_index++;
}
new client = GetRandomInt(0, max_index-1);
new new_target;
if (!client) new_target = 0;
else if ( IS_CONNECTED_INGAME(client) )
new_target = GetClientUserId(witch_target);
else
new_target = 0;
PrintToChatAll("Old target(%i). New target(%i)", witch_target, new_target);
PrintToChatAll("Ammount collected: %i", max_index);
//event = CreateEvent("witch_harasser_set");
SetEventInt(event, "userid", new_target);
SetEventInt(event, "witchid", witch_id);
//FireEvent(event2);
}
I am getting problems with IsClientInGame.
Id "10" returns TRUE and then GetClientTeam returns runtime error because id 10 is not connected.
But it was supposed IsClientInGame(10) would never return TRUE.
It's a very simple plugin that is making my head hurt.