I forgot to add checks that ensured the player entity was valid before trying to decrement their total stacker entities when an entity was removed. If the player has disconnected before the entity was removed, removing it later would cause a relatively harmless, yet annoying error. This should now be resolved.
The other fix addresses the possibility that the TotalStackerEnts field does not get created on the player when they initially spawn. If for some reason it failed, trying to decrement the player's total stacker entity count would cause an error and break things in a bad way. This pull request also addresses this problem.
Bug fixes:
- Duplicating props that were spawned from the Stacker tool with colors and materials now actually saves the colors and materials
New features:
- Added stacker_max_total and stacker_set_maxtotal (bad names, sorry)
These cvars control the total number of props that can be spawned out by the stacker at any give time. For example, setting it to 30 means players can only spawn 30 total props with the stacker tool before being blocked. They must deleted their old props before they can create any more. An error message is printed to their chat when they exceed this limit. This should address issue #4.
By default the value is set to -1 (no limit) so that it doesn't interfere with servers that don't want a hard limit.
More comments:
L308 - L359
L612
L618
L651
L653
L655
L665
L682
L685 - L686
L688 - L689
L725 - L726
I don't particularly know what reasoning I had for making the for-loop continue if one of the prop check hooks failed. If any single one of the props fails a check, it should follow that all of the remaining props to be created in the stack would also fail.
For example, when a player hits the prop limit, this should no longer needlessly create and check props that would fail after the prop limit was initially hit.
Usually, external prop protections should be in charge of limiting
tools. Unfortunately, as many prop protections greatly differ and may
not easily allow editing, I've decided to include a time delay setting
for stacker that will prevent players from spamming the stacker tool too
quickly.
The default delay is 0, which is normal behavior (you can use stacker as
fast as you want). If you want there to be a 2 second delay between
using stacker, you can use stacker_delay 3 from the server console, or
stacker_set_delay 3 if you are a server admin.
The nocollide functionality should now complete in !(N-1) ops as
compared to N^2.
Got rid of unnecessary parameters within the StackerCalcPos function.
Added stacker_force_freeze/weld/nocollide so that server
operators/admins can force stacked props to be spawned
frozen/welded/nocollided.
Options should now be cased consistently ("Foo bar", not "Foo Bar")
Stacker direction options now use the enums (should automatically be
coerced to strings)
Got rid of the advanced options warning label. Not really needed at this
point.
Some players have brought it to my attention that clicking the Reset
button for the rotation/offsets while having halos disabled will
automatically enable the halos again.
I realize now that if a user has changed these options, they most likely
don't want them to be reset every time they clear the offsets and
rotations.
As a result, I am taking them out of the list of options to reset. If
enough people would still like a way to reset the options, I can make a
secondary button to reset them.
For some reason, the way the gmod_tool was coded causes tool functions
like TOOL:Init() to be called on EVERY client when ANY client respawns.
It pretty much made using halos in PreDrawHalos unreliable.
Instead, I've unfortunately moved the halos back into TOOL:Think(),
which means there will be a large FPS drop when using halos. Sorry :/
Added stacker_stayinworld and stacker_set_stayinworld for server owners
that want to restrict stacker so that props MUST be spawned inside of
the world. Apparently some DarkRP server(s) crash(es) when many props
are spawned in the world and then are unfrozen.
The old behavior was cheap and only nocollided the previous entity with
the current entity -- not a true nocollide since every other entity
would still collide with it.
The new behavior will loop through each entity and nocollide it with
every other entity, so none of them collide with any other entity in the
stack.
Moved GhostStack to self.GhostStack
Added TOOL:Deploy
Added TOOL:OnRemove (gmod_tool doesn't appear to call this though...)
Added TOOL:OnDrop (same as above?)
Hopefully fixed the PreDrawHalos spam randomly when a player dies/drops
toolgun/etc
Fixed the strangest crash with weld/nocollide constraints ever...
I didn't realize it at the time but if your
StackerEntity/PlayerSpawnedProp hooks try to do anything with the
entity's physics object, it would error out because I hadn't actually
spawned the entity yet. My mistake.
PlayerSpawnProp returns true if the player is allowed to spawn this
prop, so we should check only if it returns false to block it.
PlayerSpawnedProp doesn't return anything (nil) so we should check if
they return anything other than nil to block it.
Also, PlayerSpawnedProp already calls ply:AddCount, so we no longer need
to use it (otherwise it would make the gamemode think you have twice as
many props spawned out as you do).
Typically _ is used in Lua to signify that we are choosing to skip some
parameter. This is fine as long as no other scripts have accidentally
(forgetting to localize) or purposefully set _ to a value, e.g.
_ = true
In this specific case, if _ is true, it will cause construct.SetPhysProp
to horribly break.
- Added support for physics properties (gravity and physics material
using the Physical Properties tool) (toggle using the "Apply Physical
Properties" option)
- Added support for weight (toggle using the "Apply Physical Properties"
option)
- Thoroughly cleaned up and optimized more problem areas (ghost stack)
- Moved halo functionality from TOOL:Think() to PreDrawHalos hook
(TOOL:Think is called way more often than it needs to be to render
halos)
- Removed net messages for sending ghost stack to client (entirely
unneeded)
- Removed server involvement in TOOL:Think() (entirely unneeded)
- Cleaned up TOOL:Think() and prevented doing redundant work on the
ghosted stack
- Cleaned up TOOL:LeftClick() by separating optional functionality like
materials and colors into their own functions
- Added official support for external prop protections/anti-spam addons
by calling hook.Run( "StackerEntity", ent, owner ) directly after a
stacked entity has been created.
If a prop has multiple skins, the stacked props will now use the same skin as the original prop.
Before this, the stacked props would default to the first skin only.