Hi gubka, will be nice if you can make a countdown for STUCK because people abuses of it.
For example, press STUCK and after 5 or 10 seconds teleport it. Here the code:
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <zombieplague>
#pragma newdecls required
/**
* Record plugin info.
**/
public Plugin UnStuck =
{
name = "[ZP] Addon: UnStuck",
author = "qubka (Nikita Ushakov)",
description = "Addon for unstucking player and teleport them on respawn point",
version = "1.0",
url = "https://forums.alliedmods.net/showthread.php?t=290657"
}
// Array to store spawn origin
float gOrigin[MAXPLAYERS+1][3];
/**
* Plugin is loading.
**/
public void OnPluginStart(/*void*/)
{
// Create a command
RegConsoleCmd("zstuck", Command_Unstuck, "Unstuck player from the another entity.");
// Hook spawn event
HookEvent("player_spawn", EventPlayerSpawn, EventHookMode_Post);
}
/**
* Handles the zstuck command. Unstuck player from the another entity.
*
* @param clientIndex The client index.
* @param iArguments The number of arguments that were in the argument string.
**/
public Action Command_Unstuck(int clientIndex, int iArguments)
{
#pragma unused clientIndex
// Validate client
if(!IsPlayerExist(clientIndex))
{
return;
}
/*
* Checks to see if a player would collide with MASK_SOLID. (i.e. they would be stuck)
* Inflates player mins/maxs a little bit for better protection against sticking.
* Thanks to Andersso for the basis of this function.
*/
// Initialize vector variables
float flOrigin[3];
float flMax[3];
float flMin[3];
// Get client's location
GetClientAbsOrigin(clientIndex, flOrigin);
// Get the client's min and max size vector
GetClientMins(clientIndex, flMin);
GetClientMaxs(clientIndex, flMax);
// Starts up a new trace hull using a global trace result and a customized trace ray filter
TR_TraceHullFilter(flOrigin, flOrigin, flMin, flMax, MASK_SOLID, FilterStuck, clientIndex);
// Returns if there was any kind of collision along the trace ray
if(TR_DidHit())
{
// Teleport player back on the previus spawn point
//TeleportEntity(clientIndex, gOrigin[clientIndex], NULL_VECTOR, NULL_VECTOR);
CreateTimer(5.0, teleport, clientIndex);
PrintToChat(clientIndex, "\x04[ZOMBIE PLAGUE]\x03 in 5 seconds you will be teleported.");
}
else
{
// Emit fail sound
ClientCommand(clientIndex, "play buttons/button11.wav");
}
}
public Action teleport(Handle hTimer, any clientIndex)
{
TeleportEntity(clientIndex, gOrigin[clientIndex], NULL_VECTOR, NULL_VECTOR);
}
/**
* Event callback (player_spawn)
* The player is spawning.
*
* @param gEventHook The event handle.
* @param gEventName The name of the event.
* @dontBroadcast If true, event is broadcasted to all clients, false if not.
**/
public Action EventPlayerSpawn(Event gEventHook, const char[] gEventName, bool dontBroadcast)
{
// Get real player index from event key
int clientIndex = GetClientOfUserId(GetEventInt(gEventHook, "userid"));
#pragma unused clientIndex
// Validate client
if(!IsPlayerExist(clientIndex))
{
return;
}
// Get client's position
GetClientAbsOrigin(clientIndex, gOrigin[clientIndex]);
}
/*
* Trace filtering functions
*/
/**
* Trace filter.
*
* @param clientIndex The client index.
* @param contentsMask The contents mask.
* @param victimIndex The victim index.
**/
public bool FilterStuck(int clientIndex, int contentsMask, any victimIndex)
{
return (clientIndex != victimIndex);
}
I tested that code and works perfectly.
Here i make a new extra item:
https://forums.alliedmods.net/showthread.php?t=294249 look it!