Fixes.
author[furrycat] <furrycat@furryclan.net>
Sat, 23 May 2009 17:25:59 +0000 (18:25 +0100)
committer[furrycat] <furrycat@furryclan.net>
Mon, 1 Jun 2009 22:01:22 +0000 (18:01 -0400)
Fixed message logged when ammo is despawned.
Compiler food.

death_exploit.sp
limited_weapons.sp

index 8d3f870..9bb4ead 100755 (executable)
@@ -4,6 +4,8 @@
 /* Array to track players who are dead. */\r
 new dead[MAXPLAYERS];\r
 \r
+new Handle:death_hp;\r
+\r
 public Plugin:myinfo = {\r
   name = "Death exploit",\r
   author = "furrycat",\r
@@ -19,6 +21,9 @@ public OnPluginStart() {
     SetFailState("This mod is for Left 4 Dead only.");\r
   }\r
 \r
+  /* Set up cvars. */\r
+  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);\r
+\r
   /* Hooks. */\r
   HookEvent("player_first_spawn", player_first_spawn_callback);\r
   HookEvent("player_transitioned", player_transitioned_callback);\r
@@ -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) {\r
   for (new i = 1; i <= MaxClients; i++) {\r
     if (! dead[i]) continue;\r
-    SetEntityHealth(i, 1);\r
-    LogMessage("Set %L health to 1.  Player was dead before transition.", i);\r
+    SetEntityHealth(i, float:death_hp);\r
+    LogMessage("Set %L health to %f.  Player was dead before transition.", i, float:death_hp);\r
   }\r
 }\r
 \r
index 01b6c36..5794ced 100755 (executable)
@@ -5,9 +5,8 @@ new Handle:despawn_weapons;
 new Handle:despawn_ammo;\r
 \r
 /* Array to track players grabbed ammo. */\r
-new grabbed_ammo[MAXPLAYERS];\r
-#define NAME_BUFFER_LEN 32\r
-new namebuffer[NAME_BUFFER_LEN];\r
+new bool:grabbed_ammo[MAXPLAYERS];\r
+new String:namebuffer[32];\r
 /* XXX: Surely this should be enough for ammo spawners. */\r
 #define NUM_AMMO_ENTITIES 32\r
 new ammo_entities[NUM_AMMO_ENTITIES];\r
@@ -40,6 +39,15 @@ public OnPluginStart() {
   HookEvent("ammo_pickup", ammo_pickup_callback);\r
 }\r
 \r
+/* Helper to get the client from an event. */\r
+public event_client(Handle:event) {\r
+  new userid = GetEventInt(event, "userid");\r
+  new client = GetClientOfUserId(userid);\r
+\r
+  if (client < 1 || client > MaxClients) return 0;\r
+  return client;\r
+}\r
+\r
 /* A player picked up an item from a spawner. */\r
 public spawner_give_item_callback(Handle:event, const String:name[], bool:dontBroadcast) {\r
   /* Remove item spawner as soon as it has given an item. */\r
@@ -48,7 +56,7 @@ public spawner_give_item_callback(Handle:event, const String:name[], bool:dontBr
   new spawner = GetEventInt(event, "spawner");\r
   if (! IsValidEntity(spawner)) return;\r
 \r
-  GetEdictClassname(spawner, namebuffer, NAME_BUFFER_LEN);\r
+  GetEdictClassname(spawner, namebuffer, sizeof(namebuffer));\r
 \r
   LogMessage("Removing %s (%d) after use.", namebuffer, spawner);\r
   RemoveEdict(spawner);\r
@@ -63,10 +71,12 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast
   new count = GetConVarInt(despawn_ammo);\r
   if (! count) return;\r
 \r
-  new userid = GetEventInt(event, "userid");\r
-  new was_ammo = grabbed_ammo[userid];\r
+  new client = event_client(event);\r
+  if (! client) return;\r
+\r
+  new bool:was_ammo = grabbed_ammo[client];\r
   /* Forget that this player interacted with anything. */\r
-  grabbed_ammo[userid] = 0;\r
+  grabbed_ammo[client] = false;\r
 \r
   new spawner = GetEventInt(event, "targetid");\r
   if (! IsValidEntity(spawner)) return;\r
@@ -74,7 +84,7 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast
   if (! was_ammo) return;\r
 \r
   /* Check this is an ammo spawner.  Surely it must be. */\r
-  GetEdictClassname(spawner, namebuffer, NAME_BUFFER_LEN);\r
+  GetEdictClassname(spawner, namebuffer, sizeof(namebuffer));\r
   if (strcmp(namebuffer, "weapon_ammo_spawn")) return;\r
 \r
   /* How many times? */\r
@@ -85,7 +95,7 @@ public player_use_callback(Handle:event, const String:name[], bool:dontBroadcast
   ammo_counts[index] = used;\r
 \r
   if (used >= count) {\r
-    LogMessage("Removing %s (%d) after %d use(s).", namebuffer, used, spawner);\r
+    LogMessage("Removing %s (%d) after %d use(s).", namebuffer, spawner, used);\r
     RemoveEdict(spawner);\r
 \r
     /* Free the index in the entities array. */\r
@@ -100,13 +110,14 @@ public ammo_pickup_callback(Handle:event, const String:name[], bool:dontBroadcas
   new count = GetConVarInt(despawn_ammo);\r
   if (! count) return;\r
 \r
-  new userid = GetEventInt(event, "userid");\r
+  new client = event_client(event);\r
+  if (! client) return;\r
 \r
-  grabbed_ammo[userid] = 1;\r
+  grabbed_ammo[client] = true;\r
 }\r
 \r
 /* Cheap hash-alike. */\r
-public int:get_ammo_index(int:entity) {\r
+public get_ammo_index(entity) {\r
   new i;\r
   new count;\r
   for (i = 0; i < NUM_AMMO_ENTITIES; i++) {\r
@@ -132,8 +143,7 @@ public int:get_ammo_index(int:entity) {
 \r
 public OnMapStart() {\r
   /* Zero out the ammo counts. */\r
-  new i;\r
-  for (i = 0; i < NUM_AMMO_ENTITIES; i++) {\r
+  for (new i = 0; i < NUM_AMMO_ENTITIES; i++) {\r
     ammo_entities[i] = 0;\r
     ammo_counts[i] = 0;\r
   }\r