From 4d48cd65de5c07f02de9b3eb3d30bacdf601e85c Mon Sep 17 00:00:00 2001 From: richard Date: Thu, 18 Jun 2009 03:33:09 +0200 Subject: [PATCH] Made a admin command for refreshing class data on one or more players. Updated infect module to use new reload function. Fixed typo in command description. Known issue: Models isn't always restored on zr_human. If "default" is used, there's practically no model change. Possible solution: Store path in a buffer when the player join a team and select a model. Then read from that buffer when "default" is used. --- src/zr/infect.inc | 2 +- src/zr/playerclasses/classcommands.inc | 58 +++++++++++++++++++++++++- src/zr/playerclasses/classevents.inc | 17 +++++++- src/zr/playerclasses/playerclasses.inc | 27 ++++++++++++ 4 files changed, 99 insertions(+), 5 deletions(-) diff --git a/src/zr/infect.inc b/src/zr/infect.inc index dd5d461..6ad4ae7 100644 --- a/src/zr/infect.inc +++ b/src/zr/infect.inc @@ -694,7 +694,7 @@ InfectZombieToHuman(client, bool:respawn = false, bool:protect = false) TranslationPrintToChat(client, "Infect human"); // Forward event to modules. - ClassOnClientInfected(client, false); + ClassReloadPlayer(client); RoundEndOnClientInfected(); ZTeleOnClientInfected(client); diff --git a/src/zr/playerclasses/classcommands.inc b/src/zr/playerclasses/classcommands.inc index 23e3e86..79ca7b8 100644 --- a/src/zr/playerclasses/classcommands.inc +++ b/src/zr/playerclasses/classcommands.inc @@ -34,7 +34,8 @@ ClassOnCommandsCreate() RegConsoleCmd("zr_class_dump", ClassDumpCommand, "Dumps class data at a specified index in the specified cache. Usage: zr_class_dump "); RegConsoleCmd("zr_class_dump_multipliers", ClassDumpMultipliersCommand, "Dumps class attribute multipliers for the specified team. Usage: zr_class_dump_multipliers <\"zombies\"|\"humans\">"); RegAdminCmd("zr_class_modify", ClassModifyCommand, ADMFLAG_CONFIG, "Modify class data on one or more classes. Usage: zr_class_modify [is_multiplier]"); - RegAdminCmd("zr_class_set_multiplier", ClassSetMultiplierCommand, ADMFLAG_CONFIG, "Sets the multiplier on a class attribute. Usage: zr_class_set multiplier <\"zombies\"|\"humans\"> "); + RegAdminCmd("zr_class_set_multiplier", ClassSetMultiplierCommand, ADMFLAG_CONFIG, "Sets the multiplier on a class attribute. Usage: zr_class_set_multiplier <\"zombies\"|\"humans\"> "); + RegAdminCmd("zr_class_reload", ClassReloadCommand, ADMFLAG_GENERIC, "Refreshes the player cache and reloads class attributes on one or more players. Usage: zr_class_reload "); } /** @@ -483,7 +484,7 @@ public Action:ClassSetMultiplierCommand(client, argc) if (argc < 3) { // Write syntax info. - StrCat(syntax, sizeof(syntax), "Sets the multiplier on a class attribute. Usage: zr_class_set multiplier <\"zombies\"|\"humans\"> \n\n"); + StrCat(syntax, sizeof(syntax), "Sets the multiplier on a class attribute. Usage: zr_class_set_multiplier <\"zombies\"|\"humans\"> \n\n"); StrCat(syntax, sizeof(syntax), "Valid attributes:\n----------------------------------------\n"); StrCat(syntax, sizeof(syntax), "napalm_time\nhealth\nhealth_regen_interval\nhealth_regen_amount\nhealth_infect_gain\nspeed\nknockback\njump_height\njump_distance"); ReplyToCommand(client, syntax); @@ -538,6 +539,59 @@ public Action:ClassSetMultiplierCommand(client, argc) return Plugin_Handled; } +/** + * Command callback. (zr_class_reload) + * Dumps class data at a specified index in the specified cache. + * + * @param client The client index. + * @param argc Argument count. + */ +public Action:ClassReloadCommand(client, argc) +{ + decl String:arg[MAX_TARGET_LENGTH]; + decl String:targetname[MAX_TARGET_LENGTH]; + new targetlist[MAXPLAYERS + 1]; + new targetcount; + new bool:tn_is_ml; + + if (argc < 1) + { + // Write syntax info. + ReplyToCommand(client, "Refreshes the player cache and reloads class attributes on one or more players. Usage: zr_class_reload "); + + return Plugin_Handled; + } + + // Get the target string. + GetCmdArg(1, arg, sizeof(arg)); + + // Get target clients. + if ((targetcount = ProcessTargetString(arg, client, targetlist, sizeof(targetlist), 0, targetname, sizeof(targetname), tn_is_ml)) <= 0) + { + // Failed to get targets. + ReplyToTargetError(client, targetcount); + return Plugin_Handled; + } + + // Loop through each target. + for (new target = 0; target < targetcount; target++) + { + ClassReloadPlayer(targetlist[target]); + } + + // Check phrase format. + if (tn_is_ml) + { + ReplyToCommand(client, "Refreshed cache to %t.", targetname); + } + else + { + ReplyToCommand(client, "Refreshed cache to %s.", targetname); + } + + return Plugin_Handled; +} + /** * Modify class boolean attribute on a class. * diff --git a/src/zr/playerclasses/classevents.inc b/src/zr/playerclasses/classevents.inc index a2733ca..3772f88 100644 --- a/src/zr/playerclasses/classevents.inc +++ b/src/zr/playerclasses/classevents.inc @@ -18,8 +18,7 @@ */ /** - * To be called when a client connect to the server. - * (OnClientPutInServer) + * Called when a client connects to the server (OnClientPutInServer). */ ClassClientInit(client) { @@ -45,6 +44,9 @@ ClassOnModulesLoaded() ClassClientSetDefaultIndexes(); } +/** + * Called a client disconnects. + */ ClassOnClientDisconnect(client) { // Disable class attributes with timers. @@ -127,6 +129,12 @@ ClassOnClientSpawn(client) ClassOverlayOnClientSpawn(client); } +/** + * Client died. Stops timers and reset certain attributes. Call this event to + * clean up class related stuff. + * + * @param client The client index. + */ ClassOnClientDeath(client) { // Disable class attributes with timers. @@ -139,6 +147,11 @@ ClassOnClientDeath(client) ClassOverlayOnClientDeath(client); } +/** + * Client got infected. Reloads class attributes. + * + * @param client The client index. + */ ClassOnClientInfected(client, bool:motherzombie = false) { new classindex = ClassGetActiveIndex(client); diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index e799f20..afea944 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -717,6 +717,33 @@ bool:ClassReloadPlayerCache(client, classindex, cachetype = ZR_CLASS_CACHE_MODIF return true; } +/** + * Refresh the specified player's cache and re-apply attributes. + * + * @param client The client index. + * @return True if successful, false otherwise. + */ +bool:ClassReloadPlayer(client) +{ + new activeclass; + + // Get active class index. + activeclass = ClassGetActiveIndex(client); + + // Validate index. + if (activeclass < 0) + { + return false; + } + + // Refresh cache and re-apply attributes. + ClassOnClientDeath(client); // Dummy event to clean up stuff. + ClassReloadPlayerCache(client, activeclass); + ClassApplyAttributes(client); + + return true; +} + /** * Reset all class attribute multipliers to 1.0. */