Raised This Month: $51 Target: $400
 12% 

Solved [TF2] Merasmus code cleanup


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 09-29-2022 , 01:11   [TF2] Merasmus code cleanup
Reply With Quote #1

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:
Attached Files
File Type: txt bewizard.txt (339 Bytes, 41 views)
File Type: sp Get Plugin or Get Source (bewizard.sp - 50 views - 38.3 KB)
File Type: smx bewizard.smx (22.6 KB, 55 views)

Last edited by PC Gamer; 10-04-2022 at 06:10.
PC Gamer is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 09-29-2022 , 06:23   Re: [TF2] Merasmus code cleanup
Reply With Quote #2

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.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)

Last edited by nosoop; 09-29-2022 at 06:24.
nosoop is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 09-29-2022 , 07:32   Re: [TF2] Merasmus code cleanup
Reply With Quote #3

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
// ---------------------------------------- 
Attached Files
File Type: sp Get Plugin or Get Source (bewizard 1.2.0.sp - 41 views - 30.9 KB)
__________________
Grey83 is offline
PC Gamer
Veteran Member
Join Date: Mar 2014
Old 10-04-2022 , 06:10   Re: [TF2] Merasmus code cleanup
Reply With Quote #4

Solved with input from nosoop and Grey83. Thanks!
PC Gamer is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 22:25.


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