AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   [TF2] Duck Piano (https://forums.alliedmods.net/showthread.php?t=316644)

Firewolf24 06-02-2019 16:54

[TF2] Duck Piano
 
1 Attachment(s)
[TF2] Duck Piano

Description:
It's a duck, it's a piano, it's a duck inside a piano!
A working piano that you can play if you try hard enough(!)

Commands:
  • sm_piano - Spawns a piano under your crosshair
  • sm_pianosound <path/to/sound.wav> - Sets a custom sound
  • sm_clearpianos - Removes all spawned pianos

Convars:
  • sm_piano_pitch - Sets the pitch range for the piano (default: 40)

Changelist:

June 2nd 2019 - 0.1
  • Initial release

PC Gamer 06-03-2019 00:38

Re: [TF2] Duck Piano
 
Tested with both .wav and .mp3 sounds. Works great. Thanks!

Dispenz0r 07-12-2019 12:51

Re: [TF2] Duck Piano
 
Code:

L 07/12/2019 - 17:15:50: [SM] Exception reported: Entity 445 (445) is not a CBaseEntity
L 07/12/2019 - 17:15:50: [SM] Blaming: duckpiano.smx
L 07/12/2019 - 17:15:50: [SM] Call stack trace:
L 07/12/2019 - 17:15:50: [SM]  [0] AcceptEntityInput
L 07/12/2019 - 17:15:50: [SM]  [1] Line 153, D:\TF2Server\steamapps\common\Team Fortress 2 Dedicated Server\tf\addons\sourcemod\scripting\duckpiano.sp::RemoveAllPianos
L 07/12/2019 - 17:15:50: [SM]  [2] Line 37, D:\TF2Server\steamapps\common\Team Fortress 2 Dedicated Server\tf\addons\sourcemod\scripting\duckpiano.sp::OnPluginEnd

Seem to be getting very similar errors such as this often

Mitchell 07-12-2019 13:55

Re: [TF2] Duck Piano
 
1 Attachment(s)
Quote:

Originally Posted by Dispenz0r (Post 2658884)
Code:

L 07/12/2019 - 17:15:50: [SM] Exception reported: Entity 445 (445) is not a CBaseEntity
L 07/12/2019 - 17:15:50: [SM] Blaming: duckpiano.smx
L 07/12/2019 - 17:15:50: [SM] Call stack trace:
L 07/12/2019 - 17:15:50: [SM]  [0] AcceptEntityInput
L 07/12/2019 - 17:15:50: [SM]  [1] Line 153, D:\TF2Server\steamapps\common\Team Fortress 2 Dedicated Server\tf\addons\sourcemod\scripting\duckpiano.sp::RemoveAllPianos
L 07/12/2019 - 17:15:50: [SM]  [2] Line 37, D:\TF2Server\steamapps\common\Team Fortress 2 Dedicated Server\tf\addons\sourcemod\scripting\duckpiano.sp::OnPluginEnd

Seem to be getting very similar errors such as this often

Because the plugin stores the piano entities as normal entity indices, which can be removed and filled in by a different entity without the plugin knowing. (i.e. on round restart all props are removed)
There's actually a lot of design flaws that you should be hesitant about putting this on a server. Clearing the pianos runs a "Kill" on the entity, while not even checking if the entity is valid or even a prop_dynamic. So it could kill logic entities or entities that will crash the server (similar to "Kill" on the player or world).
Not to mention OnPlayerRunCmd gets everyone's POV entity THEN does checks to make sure they are pressing the right button.

This plugin has some potential. I did a pretty much full redo, I formatted it to my personal code style and fixed a few things:
1. Use Entity References instead of index to store.
2. Use ArrayList instead of a hardcoded capped list.
3. Auto cleanup of the piano list once it hits the cap. (Instead of spawning in 16 pianos, round resets but the count doesn't)
4. Delete the Trace handle within the spawn command (Resource leak!)
5. Fixed the math against float values using int values. Minor nit, but should still keep this in mind when working with floats.
6. Added sanity checks to OnPlayerRunCmd before trying to get an entity they are aiming at. Also now checks if the player is alive to prevent spectators from spamming pianos.
7. Added sm_piano_max convar to constrain the amount of pianos made.
8. Added AutoExecConfig() for convars.
9. Adjusted version to conform to Semantic Versioning 2.0.0
10. Moved Precache from client connect to on MapStart.

Some features that'd be cool to have:
1. ServerCommand for maps to add in the piano themselves or a server operator to add in. "sm_piano_ex <X> <Y> <Z> [P] [Y] [R] [sound pitch] [sound file] [model?]"
2. Command that contains additional properties, such as: sm_piano [pitch] [sound file]. Which would allow better customization etc.
3. Player limits, limit how many any admin can create
4. Player leave cleanup. If an admin creates them and leaves should it remove the piano?
5. Color depending on the piano's sound pitch?

Anyways here's my UNTESTED version:

MAGNAT2645 07-13-2019 01:43

Re: [TF2] Duck Piano
 
Mitchell, your version logs error:

L 07/13/2019 - 07:52:22: [SM] Exception reported: Invalid Handle 0 (error: 4)
L 07/13/2019 - 07:52:22: [SM] Blaming: duckpiano.smx
L 07/13/2019 - 07:52:22: [SM] Call stack trace:
L 07/13/2019 - 07:52:22: [SM] [0] ArrayList.FindValue
L 07/13/2019 - 07:52:22: [SM] [1] Line 50, /home/forums/content/files/7/4/2/3/4/176317.attach::OnPlayerRunCmd

I think it's because alPianos is null by default (it can be valid only by using sm_piano command). So OnPlayerRunCmd trying to process invalid ArrayList.

Mitchell 07-13-2019 11:26

Re: [TF2] Duck Piano
 
Quote:

Originally Posted by MAGNAT2645 (Post 2658935)
Mitchell, your version logs error:

L 07/13/2019 - 07:52:22: [SM] Exception reported: Invalid Handle 0 (error: 4)
L 07/13/2019 - 07:52:22: [SM] Blaming: duckpiano.smx
L 07/13/2019 - 07:52:22: [SM] Call stack trace:
L 07/13/2019 - 07:52:22: [SM] [0] ArrayList.FindValue
L 07/13/2019 - 07:52:22: [SM] [1] Line 50, /home/forums/content/files/7/4/2/3/4/176317.attach::OnPlayerRunCmd

I think it's because alPianos is null by default (it can be valid only by using sm_piano command). So OnPlayerRunCmd trying to process invalid ArrayList.

Ya my bad I just forgot to check for null, like I said untested.
Updated to 1.1.1 in previous post

Dagothur 07-19-2019 12:49

Re: [TF2] Duck Piano
 
This is really fun, thanks for it :)

For whatever reason the IN_ATTACK2 old buttons check in OnPlayerRunCmd() doesn't work for me so I implemented rate limiting using GetGameTime(). It seemed like even though IN_ATTACK2 was being held down the bit would get set and unset (possibly related to still running SM 1.8?).

Sreaper 06-12-2020 16:07

Re: [TF2] Duck Piano
 
Setting the sound to "" will crash the server.

Code:

L 06/12/2020 - 13:11:58: Engine error: Host_Error: CEngineSoundServer::PrecacheSound:  Bad string:


All times are GMT -4. The time now is 10:49.

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