Jumping Bathtub
From GMod Wiki
Lua: Jumping Bath SENT |
Description: | A continuation of Ricky's Example SENT. |
Original Author: | Ricky26 |
Created: | 1st December 2006 |
Contents |
Folder Structure
The files for the entity must go in garrysmod/gamemodes/gamemode/entities/entities/entity name/.
Our entity name will be prop_jumper, and we will put it in sandbox.
Note: If you want to have this in all your game modes, put this in lua/entities. (You may have to create this folder, it may not be there by default)
Client Side
cl_init.lua
include('shared.lua') --[[--------------------------------------------------------- Name: Draw Purpose: Draw the model in-game. Remember, the things you render first will be underneath! ---------------------------------------------------------]] function ENT:Draw() -- self.BaseClass.Draw(self) -- We want to override rendering, so don't call baseclass. -- Use this when you need to add to the rendering. self:DrawEntityOutline( 1.0 ) -- Draw an outline of 1 world unit. self:DrawModel() -- Draw the model. if(self:GetNetworkedBool("bouncing")) then -- If the bath is in the air then AddWorldTip( self:EntIndex(), "Boing", 0.5, self:GetPos(), self ) -- Add an example tip. end -- endif end
Server Side
init.lua
AddCSLuaFile( "cl_init.lua" ) -- Make sure clientside AddCSLuaFile( "shared.lua" ) -- and shared scripts are sent. include('shared.lua') function ENT:SpawnFunction(ply, tr) -- Spawn function needed to make it appear on the spawn menu if (!tr.HitWorld) then return end local ent = ents.Create("prop_jumper") -- Create the entity ent:SetPos(tr.HitPos + Vector(0, 0, 50)) -- Set it to spawn 50 units over the spot you aim at when spawning it ent:Spawn() -- Spawn it return ent -- You need to return the entity to make it work end function ENT:Initialize() self:SetModel( "models/props_interiors/BathTub01a.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics self:SetSolid( SOLID_VPHYSICS ) -- Toolbox self:SetNetworkedBool("bouncing", false, false) -- Make sure the message doesn't show on the client. local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end function ENT:Use( activator, caller ) if ( !activator:IsPlayer() ) then return end local phys = self:GetPhysicsObject() if(phys:IsValid()) then phys:ApplyForceOffset( Vector( 0, 0, 500 ), Vector( 0, 0, 0) ) -- Apply a physics impulse to the physics object. self:NextThink( CurTime() ) -- Make sure that Think() is called. self:SetNetworkedBool("bouncing", true, true) -- Tell the clients we are in the air. end return end function ENT:Think() local phys = self:GetPhysicsObject() if( self:GetNetworkedBool("bouncing") and phys:IsAsleep() ) then -- If the variable is set and we are on the ground self:SetNetworkedBool("bouncing", false, false) -- Tell the client to hide the message end end
shared.lua
ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Jumping bath" ENT.Author = "Ricky26" ENT.Contact = "Don't" ENT.Purpose = "Exemplar material" ENT.Instructions = "Use with care. Always handle with gloves."