From 093f5363c4f613f1c9975baeb69067cae0cd5341 Mon Sep 17 00:00:00 2001 From: "[furrycat]" Date: Sat, 23 May 2009 18:25:59 +0100 Subject: [PATCH] Fixes. Fixed message logged when ammo is despawned. Compiler food. --- death_exploit.sp | 9 +++++++-- limited_weapons.sp | 38 ++++++++++++++++++++++++-------------- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/death_exploit.sp b/death_exploit.sp index 8d3f870..9bb4ead 100755 --- a/death_exploit.sp +++ b/death_exploit.sp @@ -4,6 +4,8 @@ /* Array to track players who are dead. */ new dead[MAXPLAYERS]; +new Handle:death_hp; + public Plugin:myinfo = { name = "Death exploit", author = "furrycat", @@ -19,6 +21,9 @@ public OnPluginStart() { SetFailState("This mod is for Left 4 Dead only."); } + /* Set up cvars. */ + death_hp = CreateConVar("death_hitpoints", "1", "Hitpoints for players who were dead at the end of the last map.", FCVAR_NONE, true, 0.0, true, 100.0); + /* Hooks. */ HookEvent("player_first_spawn", player_first_spawn_callback); HookEvent("player_transitioned", player_transitioned_callback); @@ -47,8 +52,8 @@ public player_transitioned_callback(Handle:event, const String:name[], bool:dont public round_freeze_end_callback(Handle:event, const String:name[], bool:dontBroadcast) { for (new i = 1; i <= MaxClients; i++) { if (! dead[i]) continue; - SetEntityHealth(i, 1); - LogMessage("Set %L health to 1. Player was dead before transition.", i); + SetEntityHealth(i, float:death_hp); + LogMessage("Set %L health to %f. Player was dead before transition.", i, float:death_hp); } } diff --git a/limited_weapons.sp b/limited_weapons.sp index 01b6c36..5794ced 100755 --- a/limited_weapons.sp +++ b/limited_weapons.sp @@ -5,9 +5,8 @@ new Handle:despawn_weapons; new Handle:despawn_ammo; /* Array to track players grabbed ammo. */ -new grabbed_ammo[MAXPLAYERS]; -#define NAME_BUFFER_LEN 32 -new namebuffer[NAME_BUFFER_LEN]; +new bool:grabbed_ammo[MAXPLAYERS]; +new String:namebuffer[32]; /* XXX: Surely this should be enough for ammo spawners. */ #define NUM_AMMO_ENTITIES 32 new ammo_entities[NUM_AMMO_ENTITIES]; @@ -40,6 +39,15 @@ public OnPluginStart() { HookEvent("ammo_pickup", ammo_pickup_callback); } +/* Helper to get the client from an event. */ +public event_client(Handle:event) { + new userid = GetEventInt(event, "userid"); + new client = GetClientOfUserId(userid); + + if (client < 1 || client > MaxClients) return 0; + return client; +} + /* A player picked up an item from a spawner. */ public spawner_give_item_callback(Handle:event, const String:name[], bool:dontBroadcast) { /* Remove item spawner as soon as it has given an item. */ @@ -48,7 +56,7 @@ public spawner_give_item_callback(Handle:event, const String:name[], bool:dontBr new spawner = GetEventInt(event, "spawner"); if (! IsValidEntity(spawner)) return; - GetEdictClassname(spawner, namebuffer, NAME_BUFFER_LEN); + GetEdictClassname(spawner, namebuffer, sizeof(namebuffer)); LogMessage("Removing %s (%d) after use.", namebuffer, spawner); RemoveEdict(spawner); @@ -63,10 +71,12 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast new count = GetConVarInt(despawn_ammo); if (! count) return; - new userid = GetEventInt(event, "userid"); - new was_ammo = grabbed_ammo[userid]; + new client = event_client(event); + if (! client) return; + + new bool:was_ammo = grabbed_ammo[client]; /* Forget that this player interacted with anything. */ - grabbed_ammo[userid] = 0; + grabbed_ammo[client] = false; new spawner = GetEventInt(event, "targetid"); if (! IsValidEntity(spawner)) return; @@ -74,7 +84,7 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast if (! was_ammo) return; /* Check this is an ammo spawner. Surely it must be. */ - GetEdictClassname(spawner, namebuffer, NAME_BUFFER_LEN); + GetEdictClassname(spawner, namebuffer, sizeof(namebuffer)); if (strcmp(namebuffer, "weapon_ammo_spawn")) return; /* How many times? */ @@ -85,7 +95,7 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast ammo_counts[index] = used; if (used >= count) { - LogMessage("Removing %s (%d) after %d use(s).", namebuffer, used, spawner); + LogMessage("Removing %s (%d) after %d use(s).", namebuffer, spawner, used); RemoveEdict(spawner); /* Free the index in the entities array. */ @@ -100,13 +110,14 @@ public ammo_pickup_callback(Handle:event, const String:name[], bool:dontBroadcas new count = GetConVarInt(despawn_ammo); if (! count) return; - new userid = GetEventInt(event, "userid"); + new client = event_client(event); + if (! client) return; - grabbed_ammo[userid] = 1; + grabbed_ammo[client] = true; } /* Cheap hash-alike. */ -public int:get_ammo_index(int:entity) { +public get_ammo_index(entity) { new i; new count; for (i = 0; i < NUM_AMMO_ENTITIES; i++) { @@ -132,8 +143,7 @@ public int:get_ammo_index(int:entity) { public OnMapStart() { /* Zero out the ammo counts. */ - new i; - for (i = 0; i < NUM_AMMO_ENTITIES; i++) { + for (new i = 0; i < NUM_AMMO_ENTITIES; i++) { ammo_entities[i] = 0; ammo_counts[i] = 0; } -- 2.7.4