This is a plugin that we made for Witch Party. It spawns 3 witches in random spots surrounding you when you defib a player.
@Silvers you need to use z_spawn_old for witches now, that changed (I think) when the steampipe update happened a couple years back.
PHP Code:
#include <sourcemod>
#include <sdktools>
public Plugin:myinfo =
{
name = "Defib witches",
author = "epilimic, purpletreefactory",
description = "Spawns witches in random points on a circle around the survivors when a defib is used.",
version = "1",
url = "http://github.com/epilimic"
}
new Handle:dw_numwitches;
new Handle:dw_spawnradius;
public OnPluginStart()
{
HookEvent("defibrillator_used", Event_Defib);
dw_numwitches = CreateConVar("dw_numwitches", "3", "Number of witches to spawn when a defib is used.");
dw_spawnradius = CreateConVar("dw_spawnradius", "100", "Radius of the circle in which witches spawn.");
}
public Action:Event_Defib(Handle:event, const String:name[], bool:dontBroadcast)
{
new numWitches = 0;
new Float:PI = 3.14159265359;
new Float:proxVal = 0.21;
new zChg = 10;
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new Float:survivorPos[3];
new Float:pos[3];
new Float:randomVals[3];
GetClientAbsOrigin(client, survivorPos);
for(new i = 0; i < 3; i++) // generate 3 random floats for witch positions
{
new Float:tmp;
new valid = -1;
while(valid == -1) // Check the proximity of the random value against previously generated values
{
tmp = GetRandomFloat(0.0, 2.0*PI);
valid = 0;
for(new j = 0; j < i; j++)
{
if(FloatAbs(tmp - randomVals[j]) < proxVal || (2*PI - FloatAbs(tmp - randomVals[j])) < proxVal)
valid = -1;
}
}
randomVals[i] = tmp;
}
while (numWitches <= GetConVarInt(dw_numwitches))
{
pos[0] = survivorPos[0] + Sine(randomVals[numWitches]) * GetConVarInt(dw_spawnradius);
pos[1] = survivorPos[1] + Cosine(randomVals[numWitches]) * GetConVarInt(dw_spawnradius);
pos[2] = survivorPos[2] + zChg;
new ent=CreateEntityByName("witch");
DispatchSpawn(ent);
//PrintToChatAll("witch #%d, %f, %f, %f", numWitches, pos[0], pos[1], pos[2]);
TeleportEntity(ent, pos, NULL_VECTOR, NULL_VECTOR);
numWitches++;
}
return Plugin_Continue;
}