AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved [TF2] Merasmus code cleanup (https://forums.alliedmods.net/showthread.php?t=339738)

PC Gamer 09-29-2022 01:11

[TF2] Merasmus code cleanup
 
3 Attachment(s)
Can you recommend any code cleanup or enhancement for this plugin?

I'm in the process of cleaning up Halloween plugins in preparation for Scream Fortress. This plugin works just fine as-is. However, if you have any tips for code cleanup or improvement I'd love to hear them. I'm eager to learn.

Current plugin functionality:
Target player becomes Merasmus the Wizard. Changes to gray team and can attack players on RED and BLU team. Changes to sniper class with Merasmus player model. Removes all weapons and is given a melee weapon. Can cast 500 fireball spells. Can cast unlimited lightning spells. Can launch nearby players very high into air. Can release bombs that damage nearby players. Has extremely enhanced attributes with damage resistances. Melee attacks have increased range and instantly kill and turns victim to gold. Ambient sounds are played while Merasmus is alive.

Command: !bewizard (target)

Plugin dependency: TF2Attributes by the talented nosoop. Here's a link: https://github.com/nosoop/tf2attributes

Installation:
Place bewizard.txt file in your /sourcemod/gamedata/ folder
Place bewizard.smx file in your /sourcemod/plugins/ folder
Change map

Video of BeWizard Plugin:

nosoop 09-29-2022 06:23

Re: [TF2] Merasmus code cleanup
 
Here's a review:
  • You can remove public from non-global forward callbacks such as OnPlayerActivate and Event_DeathPre. It's been a few major versions since that was necessary (SM 1.7, I think?)
  • You can simplify the fixed vector initialization:
    Code:

    float vecc[] = { 1.0, 1.0, 1.5 };
    TeleportEntity(k, NULL_VECTOR, NULL_VECTOR, vecc);

    You might be able to put the braced initializer directly into TeleportEntity without a tag mismatch; I keep forgetting if that's been fixed in SM 1.11 and don't feel like setting up an environment to test.
  • The strings that are part of a set could be moved to an array:
    Code:

    char HELLFIRE_SOUNDS[][] = {
        HELLFIRE,
        HELLFIRE2,
        HELLFIRE3,
    };

    Normally I'd suggest putting the strings there directly, but some of them are reused in Command_GetmsRandom.
  • I'd suggest using GetURandomInt over GetRandomInt just to avoid depending on the game's own random stream. It looks like you already do that with GetURandomFloat.
  • Use guard clauses to return early on failed IsValidEntity checks.
  • Rename variables for consistency, but the globals in particular should all have a prefix to make it obvious what scope they have and to minimize the risk of variable shadowing, even though the compiler does warn you about that.
  • ParticleIndex should use an entity reference EntIndexToEntRef. You can use the value in most places that accept entity indices. You may also want to use a client-sized array to store that state and ensure that calls to BuildParticle clean up previous particles.

Grey83 09-29-2022 07:32

Re: [TF2] Merasmus code cleanup
 
1 Attachment(s)
PHP Code:

//// bewizard 1.1.sp
//
// Code size:            38268 bytes
// Data size:            12876 bytes
// Stack/heap size:      16384 bytes
// Total requirements:   67528 bytes
//
// Compilation Time: 0,28 sec
// ----------------------------------------

//// bewizard 1.2.0.sp
//
// Code size:            31976 bytes
// Data size:            10948 bytes
// Stack/heap size:      16384 bytes
// Total requirements:   59308 bytes
//
// Compilation Time: 0,27 sec
// ---------------------------------------- 


PC Gamer 10-04-2022 06:10

Re: [TF2] Merasmus code cleanup
 
Solved with input from nosoop and Grey83. Thanks!


All times are GMT -4. The time now is 21:03.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.