#if defined _Couch_included #endinput #endif #define _Couch_included // Chat prefix shared by the whole couch plugin set. The trailing colour code tints the token that // follows it (a name or value); messages switch back with \x01. PREFIX_PLAIN is for console // replies, which don't render colour codes. #define PREFIX "\x07CD853F[Couch] \x04" #define PREFIX_PLAIN "[Couch]" // Non-negative integer with a comma every three digits: 1532 -> "1,532". stock void FormatThousands(int value, char[] buffer, int maxlen) { char sDigits[16]; int len = IntToString(value, sDigits, sizeof(sDigits)); int out = 0; for (int i = 0; i < len && out < maxlen - 1; i++) { // A comma goes before every digit that starts a new group of three from the right. if (i > 0 && (len - i) % 3 == 0) buffer[out++] = ','; if (out < maxlen - 1) buffer[out++] = sDigits[i]; } buffer[out] = '\0'; } // How a player moved the couch, passed to Couch_OnCouchInteraction. enum CouchMethod { CouchMethod_Bullet, // Gunfire; weapon is the gun, e.g. "ak47". CouchMethod_Knife, // weapon is "knife". CouchMethod_Grenade, // weapon is "hegrenade". CouchMethod_Use, // +use; weapon is empty. CouchMethod_Other // Any other damage credited to a player; weapon is the inflictor's classname. }; // The core defines COUCH_CORE; it creates the forwards and natives itself. #if !defined COUCH_CORE /** * Called after the couch has been created, for admin spawns and round-start respawns. * * @param couch Entity index of the new couch. */ forward void Couch_OnCouchSpawned(int couch); /** * Called once the couch entity is gone, for whatever reason. Couch_IsPlaced() tells whether * it will come back at the next round start. */ forward void Couch_OnCouchRemoved(); /** * Called for every hit the couch accepts from a player. Shotguns report once per pellet. * * @param couch Entity index of the couch. * @param attacker Client index of the player who dealt the damage. * @param damage Damage dealt by this hit. */ forward void Couch_OnCouchDamaged(int couch, int attacker, float damage); /** * Called for every hit or +use the couch accepts from a player, saying how it was moved. Hits * fire alongside Couch_OnCouchDamaged, so shotguns report once per pellet. * * @param couch Entity index of the couch. * @param client Client index of the player. * @param method How the couch was moved. * @param weapon Weapon without its "weapon_" prefix, see CouchMethod. */ forward void Couch_OnCouchInteraction(int couch, int client, CouchMethod method, const char[] weapon); /** * Called when a hit or +use from a blocked client is refused. Fires per pellet, so rate-limit anything you send. * * @param couch Entity index of the couch. * @param client Client index of the blocked player. */ forward void Couch_OnClientBlocked(int couch, int client); /** * Called whenever the couch's HP changes: zombie hits, regen ticks, admin sets, resets to full * on spawn and round start, and when the HP feature is switched on or off. * * @param couch Entity index of the couch, or -1 if the feature was switched off while there was none. * @param hp Current HP. * @param maxhp Maximum HP, sm_couch_hp_max. */ forward void Couch_OnCouchHpChanged(int couch, int hp, int maxhp); /** * Called when the couch's HP reaches 0, before the humans are killed and the couch is removed. * Couch_OnCouchRemoved follows. * * @param couch Entity index of the couch; still valid during this call. * @param attacker Client index of the zombie whose hit broke it, or 0 when an admin set the HP to 0. */ forward void Couch_OnCouchBroken(int couch, int attacker); /** * @return Entity index of the couch, or -1 if there is none. */ native int Couch_GetCouch(); /** * Whether an admin has placed a couch this map. While true the couch respawns at the placed * spot every round start. * * @return True if a placement is remembered. */ native bool Couch_IsPlaced(); /** * Spawns the couch where the client is aiming, replacing any existing couch. The spot becomes * the respawn point. * * @param client Client whose crosshair places the couch. Must be in game. * @return Entity index of the couch, or -1 on failure. */ native int Couch_Spawn(int client); /** * Teleports the couch to where the client is aiming. The respawn point is left as it was. * * @param client Client whose crosshair places the couch. Must be in game. * @return True on success, false if there is no couch. */ native bool Couch_Bring(int client); /** * Teleports the client onto the couch, or beside it when the top is blocked. The client keeps * their view angles and arrives with no velocity. * * @param client Client to teleport. Must be in game. * @return True on success, false if there is no couch. */ native bool Couch_Goto(int client); /** * Removes the couch and forgets its placement. * * @return True if a couch or a placement was removed. */ native bool Couch_Remove(); /** * Whether the colour cycle and light are on. Mirrors sm_couch_effect. */ native bool Couch_IsEffectEnabled(); /** * Switches the colour cycle and light on or off. Writes sm_couch_effect. */ native void Couch_SetEffectEnabled(bool enabled); /** * Whether the sm_beacon-style rings on the couch are on. Mirrors sm_couch_beacon. */ native bool Couch_IsBeaconEnabled(); /** * Switches the beacon rings on or off. Writes sm_couch_beacon. */ native void Couch_SetBeaconEnabled(bool enabled); /** * Whether only pistols and knives may move the couch. Mirrors sm_couch_pistol_only. */ native bool Couch_IsPistolOnly(); /** * Restricts couch movement to pistols and knives, or lifts the restriction. Writes sm_couch_pistol_only. */ native void Couch_SetPistolOnly(bool enabled); /** * Whether players may push the couch by holding +use on it. Mirrors sm_allow_couch_use. */ native bool Couch_IsUseAllowed(); /** * Allows or forbids pushing the couch with +use; when forbidden it can only be shot. Writes sm_allow_couch_use. */ native void Couch_SetUseAllowed(bool allowed); /** * Blocks or unblocks a client from the couch: their hits are refused and their body can't push * it. The flag is per slot and cleared on disconnect and map start; the caller owns persistence. * * @param client Client to block or unblock. Must be in game. * @param blocked True to block, false to lift the block. */ native void Couch_SetClientBlocked(int client, bool blocked); /** * Whether the client is currently blocked from the couch. * * @param client Client index. * @return True if blocked. */ native bool Couch_IsClientBlocked(int client); /** * Whether couch HP is on: zombie hits wear the couch down and at 0 HP it breaks, killing every * human. Mirrors sm_couch_hp. */ native bool Couch_IsHpEnabled(); /** * Switches couch HP on or off. Turning it on sets the HP to full. Writes sm_couch_hp. */ native void Couch_SetHpEnabled(bool enabled); /** * @return Current couch HP, or 0 if there is no couch. */ native int Couch_GetHp(); /** * Sets the couch's HP, clamped to 0..Couch_GetMaxHp(). Setting 0 breaks the couch as a zombie * hit would, provided the HP feature is on and a couch exists. * * @param hp New HP. */ native void Couch_SetHp(int hp); /** * @return Maximum couch HP. Mirrors sm_couch_hp_max. */ native int Couch_GetMaxHp(); /** * Sets the maximum couch HP. A couch at full HP stays full; otherwise the HP is clamped to the * new maximum. Writes sm_couch_hp_max. * * @param maxhp New maximum, at least 1. */ native void Couch_SetMaxHp(int maxhp); public SharedPlugin __pl_Couch = { name = "Couch", file = "Couch.smx", #if defined REQUIRE_PLUGIN required = 1 #else required = 0 #endif }; #if !defined REQUIRE_PLUGIN public void __pl_Couch_SetNTVOptional() { MarkNativeAsOptional("Couch_GetCouch"); MarkNativeAsOptional("Couch_IsPlaced"); MarkNativeAsOptional("Couch_Spawn"); MarkNativeAsOptional("Couch_Bring"); MarkNativeAsOptional("Couch_Goto"); MarkNativeAsOptional("Couch_Remove"); MarkNativeAsOptional("Couch_IsEffectEnabled"); MarkNativeAsOptional("Couch_SetEffectEnabled"); MarkNativeAsOptional("Couch_IsBeaconEnabled"); MarkNativeAsOptional("Couch_SetBeaconEnabled"); MarkNativeAsOptional("Couch_IsPistolOnly"); MarkNativeAsOptional("Couch_SetPistolOnly"); MarkNativeAsOptional("Couch_IsUseAllowed"); MarkNativeAsOptional("Couch_SetUseAllowed"); MarkNativeAsOptional("Couch_SetClientBlocked"); MarkNativeAsOptional("Couch_IsClientBlocked"); MarkNativeAsOptional("Couch_IsHpEnabled"); MarkNativeAsOptional("Couch_SetHpEnabled"); MarkNativeAsOptional("Couch_GetHp"); MarkNativeAsOptional("Couch_SetHp"); MarkNativeAsOptional("Couch_GetMaxHp"); MarkNativeAsOptional("Couch_SetMaxHp"); } #endif #endif // COUCH_CORE