2010-11-14 15:17:19 +01:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: infect.api.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Native handlers for the ZR API. (Infect module)
|
|
|
|
*
|
2013-01-12 08:47:36 +01:00
|
|
|
* Copyright (C) 2009-2013 Greyscale, Richard Helgeby
|
2010-11-14 15:17:19 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Global forward handles.
|
|
|
|
*/
|
2019-01-23 18:48:00 +01:00
|
|
|
new Handle:g_hAPIFwdOnInfectCountdown = INVALID_HANDLE;
|
2010-11-14 15:17:19 +01:00
|
|
|
new Handle:g_hAPIFwdOnClientInfect = INVALID_HANDLE;
|
|
|
|
new Handle:g_hAPIFwdOnClientInfected = INVALID_HANDLE;
|
|
|
|
new Handle:g_hAPIFwdOnClientHuman = INVALID_HANDLE;
|
|
|
|
new Handle:g_hAPIFwdOnClientHumanPost = INVALID_HANDLE;
|
2017-08-07 16:31:20 +02:00
|
|
|
new Handle:g_hAPIFwdOnClientMotherZombieEligible = INVALID_HANDLE;
|
2010-11-14 15:17:19 +01:00
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes all natives and forwards related to infection.
|
|
|
|
*/
|
|
|
|
APIInfectInit()
|
|
|
|
{
|
|
|
|
// Infect module natives/forwards (infect.zr.inc)
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Natives
|
|
|
|
CreateNative("ZR_IsClientZombie", APIIsClientZombie);
|
|
|
|
CreateNative("ZR_IsClientHuman", APIIsClientHuman);
|
|
|
|
CreateNative("ZR_InfectClient", APIInfectClient);
|
|
|
|
CreateNative("ZR_HumanClient", APIHumanClient);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Forwards
|
2019-01-23 18:48:00 +01:00
|
|
|
g_hAPIFwdOnInfectCountdown = CreateGlobalForward("ZR_OnInfectCountdown", ET_Hook);
|
2010-11-14 15:17:19 +01:00
|
|
|
g_hAPIFwdOnClientInfect = CreateGlobalForward("ZR_OnClientInfect", ET_Hook, Param_CellByRef, Param_CellByRef, Param_CellByRef, Param_CellByRef, Param_CellByRef);
|
|
|
|
g_hAPIFwdOnClientInfected = CreateGlobalForward("ZR_OnClientInfected", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
|
|
|
g_hAPIFwdOnClientHuman = CreateGlobalForward("ZR_OnClientHuman", ET_Hook, Param_CellByRef, Param_CellByRef, Param_CellByRef);
|
|
|
|
g_hAPIFwdOnClientHumanPost = CreateGlobalForward("ZR_OnClientHumanPost", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
|
2017-08-07 16:31:20 +02:00
|
|
|
g_hAPIFwdOnClientMotherZombieEligible = CreateGlobalForward("ZR_OnClientMotherZombieEligible", ET_Hook, Param_Cell);
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native call function (ZR_IsClientInfected)
|
|
|
|
* Returns true if the client is a zombie, false if not.
|
|
|
|
*/
|
|
|
|
public APIIsClientZombie(Handle:plugin, numParams)
|
|
|
|
{
|
|
|
|
new client = GetNativeCell(1);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Validate the client index.
|
|
|
|
APIValidateClientIndex(client, Condition_True);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
return InfectIsClientInfected(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native call function (ZR_IsClientHuman)
|
|
|
|
* Returns true if the client is a human, false if not.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* bool:InfectIsClientHuman(client)
|
|
|
|
*/
|
|
|
|
public APIIsClientHuman(Handle:plugin, numParams)
|
|
|
|
{
|
|
|
|
new client = GetNativeCell(1);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Validate the client index.
|
|
|
|
APIValidateClientIndex(client, Condition_True);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
return InfectIsClientHuman(client);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native call function (ZR_InfectClient)
|
|
|
|
* Infects a client.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* native ZR_InfectClient(client, attacker = -1, bool:motherInfect = false, bool:respawnOverride = false, bool:respawn = false);
|
|
|
|
*/
|
|
|
|
public APIInfectClient(Handle:plugin, numParams)
|
|
|
|
{
|
|
|
|
new client = GetNativeCell(1);
|
|
|
|
new attacker = GetNativeCell(2);
|
|
|
|
new bool:motherInfect = bool:GetNativeCell(3);
|
|
|
|
new bool:respawnOverride = bool:GetNativeCell(4);
|
|
|
|
new bool:respawn = bool:GetNativeCell(5);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Validate the client index.
|
|
|
|
APIValidateClientIndex(client, Condition_True);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2017-10-06 13:49:11 +02:00
|
|
|
return InfectHumanToZombie(client, attacker, motherInfect, respawnOverride, respawn);
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Native call function (ZR_HumanClient)
|
|
|
|
* Turns a zombie back into a human.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* native ZR_HumanClient(client, bool:respawn = false, bool:protect = false);
|
|
|
|
*/
|
|
|
|
public APIHumanClient(Handle:plugin, numParams)
|
|
|
|
{
|
|
|
|
new client = GetNativeCell(1);
|
|
|
|
new bool:respawn = bool:GetNativeCell(2);
|
|
|
|
new bool:protect = bool:GetNativeCell(2);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Validate the client index.
|
|
|
|
APIValidateClientIndex(client, Condition_True);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2017-10-06 13:49:11 +02:00
|
|
|
return InfectZombieToHuman(client, respawn, protect);
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:48:00 +01:00
|
|
|
/**
|
|
|
|
* Called on infection timer to determine if timer should show.
|
|
|
|
*/
|
|
|
|
Action:APIOnInfectCountdown()
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnInfectCountdown);
|
|
|
|
|
|
|
|
// Get what they returned.
|
|
|
|
new Action:result;
|
|
|
|
Call_Finish(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
/**
|
|
|
|
* Called when a client is about to become a zombie.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* @param client The client to infect.
|
|
|
|
* @param attacker The attacker who did the infect.
|
|
|
|
* @param motherinfect Indicates a mother zombie infect.
|
|
|
|
* @param respawnoverride Set to true to override respawn cvar.
|
|
|
|
* @param respawn Value to override with.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respawnoverride = false, bool:respawn = false)
|
|
|
|
*/
|
|
|
|
Action:APIOnClientInfect(&client, &attacker, &bool:motherinfect, &bool:respawnoverride, &bool:respawn)
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnClientInfect);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Push the parameters.
|
|
|
|
Call_PushCellRef(client);
|
|
|
|
Call_PushCellRef(attacker);
|
|
|
|
Call_PushCellRef(motherinfect);
|
|
|
|
Call_PushCellRef(respawnoverride);
|
|
|
|
Call_PushCellRef(respawn);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Get what they returned.
|
|
|
|
new Action:result;
|
|
|
|
Call_Finish(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after a client has become a zombie.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* @param client The client to infect.
|
|
|
|
* @param attacker The attacker who did the infect.
|
|
|
|
* @param motherinfect Indicates a mother zombie infect.
|
|
|
|
* @param respawnoverride Set to true to override respawn cvar.
|
|
|
|
* @param respawn Value to override with.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* InfectHumanToZombie(client, attacker = -1, bool:motherinfect = false, bool:respawnoverride = false, bool:respawn = false)
|
|
|
|
*/
|
|
|
|
APIOnClientInfected(client, attacker, bool:motherinfect, bool:respawnoverride, bool:respawn)
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnClientInfected);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Push the parameters.
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(attacker);
|
|
|
|
Call_PushCell(motherinfect);
|
|
|
|
Call_PushCell(respawnoverride);
|
|
|
|
Call_PushCell(respawn);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Finish the call.
|
|
|
|
Call_Finish();
|
2016-08-18 06:52:00 +02:00
|
|
|
|
|
|
|
// Forward event to map.
|
|
|
|
if(!motherinfect)
|
|
|
|
{
|
|
|
|
int entity = INVALID_ENT_REFERENCE;
|
|
|
|
while((entity = FindEntityByClassname(entity, "trigger_brush")) != INVALID_ENT_REFERENCE)
|
|
|
|
{
|
|
|
|
static char sTargetname[64];
|
|
|
|
GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname));
|
|
|
|
|
2016-08-24 23:06:51 +02:00
|
|
|
if(client > 0 && StrEqual(sTargetname, "game_playerdie"))
|
2016-08-18 06:52:00 +02:00
|
|
|
AcceptEntityInput(entity, "Use", client, client);
|
2016-08-24 23:06:51 +02:00
|
|
|
else if(attacker > 0 && StrEqual(sTargetname, "game_playerkill"))
|
2016-08-18 06:52:00 +02:00
|
|
|
AcceptEntityInput(entity, "Use", attacker, attacker);
|
|
|
|
}
|
|
|
|
}
|
2010-11-14 15:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when a client is about to become a human. (Through either zr_human or admin menu)
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* @param client The client index.
|
|
|
|
* @param respawn True if the client was respawned, false if not.
|
|
|
|
* @param protect True if the client spawn protected, false if not.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* InfectZombieToHuman(client, bool:respawn = false, bool:protect = false)
|
|
|
|
*/
|
|
|
|
Action:APIOnClientHuman(&client, &bool:respawn, &bool:protect)
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnClientHuman);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Push the parameters.
|
|
|
|
Call_PushCellRef(client);
|
|
|
|
Call_PushCellRef(respawn);
|
|
|
|
Call_PushCellRef(protect);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Get what they returned.
|
|
|
|
new Action:result;
|
|
|
|
Call_Finish(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after a client has become a human. (Through either zr_human or admin menu)
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* @param client The client index.
|
|
|
|
* @param respawn True if the client was respawned, false if not.
|
|
|
|
* @param protect True if the client spawn protected, false if not.
|
2016-02-06 00:47:47 +01:00
|
|
|
*
|
2010-11-14 15:17:19 +01:00
|
|
|
* InfectZombieToHuman(client, bool:respawn = false, bool:protect = false)
|
|
|
|
*/
|
|
|
|
APIOnClientHumanPost(client, bool:respawn, bool:protect)
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnClientHumanPost);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Push the parameters.
|
|
|
|
Call_PushCell(client);
|
|
|
|
Call_PushCell(respawn);
|
|
|
|
Call_PushCell(protect);
|
2016-02-06 00:47:47 +01:00
|
|
|
|
2010-11-14 15:17:19 +01:00
|
|
|
// Finish the call.
|
|
|
|
Call_Finish();
|
|
|
|
}
|
2017-08-07 16:31:20 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called in ZRCreateEligibleClientList to determine if a client is eligible to become infected.
|
|
|
|
*
|
|
|
|
* @param client The client to check.
|
|
|
|
*/
|
|
|
|
Action:APIOnClientMotherZombieEligible(client)
|
|
|
|
{
|
|
|
|
// Start forward call.
|
|
|
|
Call_StartForward(g_hAPIFwdOnClientMotherZombieEligible);
|
|
|
|
|
|
|
|
// Push the parameters.
|
|
|
|
Call_PushCell(client);
|
|
|
|
|
|
|
|
// Get what they returned.
|
|
|
|
new Action:result;
|
|
|
|
Call_Finish(result);
|
|
|
|
return result;
|
|
|
|
}
|