-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAmmo.sp
53 lines (40 loc) · 1.5 KB
/
Ammo.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright (C) 2023 Katsute | Licensed under CC BY-NC-SA 4.0
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
float time;
ConVar timeCV;
public Plugin myinfo = {
name = "Ammo Box Despawn",
author = "Katsute",
description = "Set ammo box despawn time",
version = "1.0",
url = "https://github.com/KatsuteTF/Ammo-Box-Despawn"
}
public void OnPluginStart(){
timeCV = CreateConVar("tf_dropped_ammo_lifetime", "30", "How long dropped ammo should remain on the map", 0, true, 0.0, true, 30.0);
timeCV.AddChangeHook(OnConvarChanged);
time = timeCV.FloatValue;
HookEvent("player_death", OnPlayerDeath);
}
public void OnConvarChanged(const ConVar convar, const char[] oldValue, const char[] newValue){
if(convar == timeCV)
time = StringToFloat(newValue);
}
public void OnPlayerDeath(const Event event, const char[] name, const bool dontBroadcast){
int client = GetClientOfUserId(event.GetInt("userid"));
if(time == 30)
return;
int ent = -1;
while((ent = FindEntityByClassname(ent, "tf_ammo_pack")) != -1)
if(GetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity") == client)
if(time == 0)
AcceptEntityInput(ent, "Kill");
else
CreateTimer(time, OnPlayerDeathDelayed, ent, TIMER_FLAG_NO_MAPCHANGE);
}
public Action OnPlayerDeathDelayed(const Handle timer, const int ent){
if(IsValidEntity(ent))
AcceptEntityInput(ent, "Kill");
return Plugin_Continue;
}