SamuraiBarbi
09-09-2007, 23:29
Hey there guys. I've been having problems trying to kill timers and was hoping someone here might know what I'm probably doing incorrectly. This script borrows the idea from an evenscripts script that emits a normal heartbeat from a player while their health is above a certain number. In this case it is 30. Then once their health is at or lower than 30 the user player begins to lose health and they emit a faster paced heartbeat until their health reaches 1. I've been looking over the information available for the killtimer function but I'm silly and dun get it yet.
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
new Handle:hHeartBeatTimer[65];
public OnPluginStart()
{
HookEvent("player_spawn", HookPlayerSpawn);
HookEvent("round_end", HookRoundEnd);
HookEvent("player_death", HookPlayerDeath);
}
public Action:HookPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new userID = GetEventInt(event,"userid");
new user = GetClientOfUserId(userID);
new userTeam = GetClientTeam(user);
if (userTeam == 3)
{
hHeartBeatTimer[64] = CreateTimer(1.0, HeartBeat, user);
}
}
public Action:HookRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
new playersconnected;
playersconnected = GetMaxClients();
for (new i = 1; i <= playersconnected; i++)
{
if(IsClientInGame(i))
{
new clientTeam = GetClientTeam(i);
if (clientTeam == 3)
{
if (IsValidHandle(hHeartBeatTimer[i]))
{
PrintToChatAll("killed timer for %i",i);
KillTimer(hHeartBeatTimer[i]);
hHeartBeatTimer[i] = INVALID_HANDLE;
}
}
}
}
}
public Action:HeartBeat(Handle:timer, any:user)
{
if(IsClientInGame(user))
{
new userTeam = GetClientTeam(user);
if (userTeam == 3)
{
decl String:sound[64];
new health = GetClientHealth(user);
if (health <= 30)
{
CreateTimer(1.0, HeartBeat, user);
if (health > 1)
{
Format(sound,sizeof(sound),"km_gameplay_sounds/fastbeat.mp3");
EmitSoundToAll(sound,user);
SetEntProp(user,Prop_Send,"m_iHealth",GetClientHealth(user)-1);
}
}
if (health > 30)
{
Format(sound,sizeof(sound),"km_gameplay_sounds/slowbeat.mp3");
EmitSoundToAll(sound,user);
CreateTimer(1.0, HeartBeat, user);
}
PrintToChatAll("Do heartbeat");
}
}
}
public Action:HookPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new userid = GetEventInt(event,"userid");
new victim = GetClientOfUserId(userid);
new victimTeam = GetClientTeam(victim);
if ((victimTeam == 3))
{
if (IsValidHandle(hHeartBeatTimer[victim]))
{
PrintToChatAll("killed timer for %i",victim);
KillTimer(hHeartBeatTimer[victim]);
hHeartBeatTimer[victim] = INVALID_HANDLE;
}
}
}
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
new Handle:hHeartBeatTimer[65];
public OnPluginStart()
{
HookEvent("player_spawn", HookPlayerSpawn);
HookEvent("round_end", HookRoundEnd);
HookEvent("player_death", HookPlayerDeath);
}
public Action:HookPlayerSpawn(Handle:event, const String:name[], bool:dontBroadcast)
{
new userID = GetEventInt(event,"userid");
new user = GetClientOfUserId(userID);
new userTeam = GetClientTeam(user);
if (userTeam == 3)
{
hHeartBeatTimer[64] = CreateTimer(1.0, HeartBeat, user);
}
}
public Action:HookRoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
new playersconnected;
playersconnected = GetMaxClients();
for (new i = 1; i <= playersconnected; i++)
{
if(IsClientInGame(i))
{
new clientTeam = GetClientTeam(i);
if (clientTeam == 3)
{
if (IsValidHandle(hHeartBeatTimer[i]))
{
PrintToChatAll("killed timer for %i",i);
KillTimer(hHeartBeatTimer[i]);
hHeartBeatTimer[i] = INVALID_HANDLE;
}
}
}
}
}
public Action:HeartBeat(Handle:timer, any:user)
{
if(IsClientInGame(user))
{
new userTeam = GetClientTeam(user);
if (userTeam == 3)
{
decl String:sound[64];
new health = GetClientHealth(user);
if (health <= 30)
{
CreateTimer(1.0, HeartBeat, user);
if (health > 1)
{
Format(sound,sizeof(sound),"km_gameplay_sounds/fastbeat.mp3");
EmitSoundToAll(sound,user);
SetEntProp(user,Prop_Send,"m_iHealth",GetClientHealth(user)-1);
}
}
if (health > 30)
{
Format(sound,sizeof(sound),"km_gameplay_sounds/slowbeat.mp3");
EmitSoundToAll(sound,user);
CreateTimer(1.0, HeartBeat, user);
}
PrintToChatAll("Do heartbeat");
}
}
}
public Action:HookPlayerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new userid = GetEventInt(event,"userid");
new victim = GetClientOfUserId(userid);
new victimTeam = GetClientTeam(victim);
if ((victimTeam == 3))
{
if (IsValidHandle(hHeartBeatTimer[victim]))
{
PrintToChatAll("killed timer for %i",victim);
KillTimer(hHeartBeatTimer[victim]);
hHeartBeatTimer[victim] = INVALID_HANDLE;
}
}
}