Are there any functions that are called when a player spawns a turret, gate, etc. with a gmod_tool/Duplicator, or any way to detect if a turret is spawned? If so, how? I got a point system in a gamemode, so im interessted in removing some points when a player spawns a turret.
It’s quite simple, you need to use a hook to detect when a player spawns a SENT. You can add as many checks as you want for the other entity types.
Here are a few useful links :
http://wiki.garrysmod.com/?title=Gamemode.PlayerSpawnSENT ( The detection hook)
http://wiki.garrysmod.com/?title=Hook.Add (How to add a hook)
http://luabin.foszor.com/code/gamemodes/sandbox/entities/entities (The class names of the basic gmod entities)
And an example :
[lua]function TurretDetection( ply, sent_type )
if sent_type == "gmod_turret" then // checks if it's a turret pl:PrintMessage(HUD_PRINTCENTER,"You lose 5 points for spawning a turret!") ply.Score = ply.Score - 5 end
hook.Add( “PlayerSpawnSENT”, “TurretDetection”, TurretDetection )[/lua]
Also if for some reasons you want to disable the spawning of an object (Say if the player’s score is too low) simply add “return false” without the quotation marks at the end of your if.
Well that’s what i call help! Thankyou! Got it working!