Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ gms_base_entity.lua
- AddCSLuaFile();
- ENT.Type = "anim";
- ENT.Base = "base_gmodentity";
- ENT.PrintName = "GMS Base Entity";
- ENT.Author = "Stranded Team";
- ENT.Spawnable = false;
- ENT.Model = "models/props/de_inferno/ClayOven.mdl";
- function ENT:Initialize()
- if ( self.Color ) then
- self:SetColor( self.Color );
- end
- self:SetModel( self.Model );
- self:SetMoveType( MOVETYPE_VPHYSICS );
- self:SetSolid( SOLID_VPHYSICS );
- if SERVER then
- self:PhysicsInit( SOLID_VPHYSICS );
- if ( self.DoWake ) then
- self:PhysWake();
- end
- if ( self.DoFreeze ) then
- self:Freeze();
- end
- end
- local phys = self:GetPhysicsObject();
- if ( IsValid( phys ) ) then
- phys:RecheckCollisionFilter();
- end
- self:OnInitialize();
- end
- function ENT:OnInitialize()
- end
- if ( CLIENT ) then return end
- function ENT:Use( ply )
- if ( !ply:KeyPressed( IN_USE ) ) then return; end
- self:OnUse( ply );
- end
- function ENT:Wake()
- local phys = self:GetPhysicsObject();
- if ( IsValid( phys ) ) then
- phys:Wake();
- end
- end
- function ENT:Freeze()
- local phys = self:GetPhysicsObject();
- if ( IsValid( phys ) ) then
- phys:EnableMotion( false );
- end
- end
- function ENT:OnTakeDamage( dmg )
- self:TakePhysicsDamage( dmg );
- end
- function ENT:OnUse( ply )
- end
- $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ gms_plant.lua
- AddCSLuaFile()
- ENT.Type = "anim";
- ENT.Base = "gms_base_entity";
- ENT.PrintName = "Plant";
- ENT.Model = "models/weapons/w_bugbait.mdl";
- ENT.Color = Color(0, 255, 0, 255);
- ENT.DoWake = true;
- ENT.DoFreeze = true;
- concommand.Add("gms_plant",
- function ( ply, cmd, args )
- if not IsValid(ply) and ply:IsAdmin() and cmd ~= "gms_plant" then return end;
- net.Start("gms_plant");
- net.WriteTable({ pos = ply:GetEyeTrace().HitPos, plant = args[1] });
- net.SendToServer();
- end,
- function ( cmd, args )
- args = string.Trim( args ); -- Remove any spaces before or after.
- args = string.lower( args );
- local tbl = {};
- for k, v in pairs( GMS.Plants ) do
- local plant = k;
- if string.find(string.lower( plant ), args ) then
- plant = "\"" .. plant .. "\""; -- We put quotes around it in case players have spaces in their names.
- plant = "gms_plant " .. plant; -- We also need to put the cmd before for it to work properly.
- table.insert( tbl, plant );
- else
- print("args not found" .. k .. " " .. args);
- end
- end
- return tbl;
- end,
- "Plants a plant.");
- if CLIENT then
- return;
- end
- util.AddNetworkString("gms_plant");
- net.Receive("gms_plant", function(len, ply)
- local data = net.ReadTable();
- local plant = ents.Create("gms_plant");
- plant:SetPos(data.pos);
- plant:SetUp(GMS.Plants[data.plant], ply);
- plant:Spawn();
- end);
- function ENT:OnInitialize()
- self:SetRenderMode(RENDERMODE_TRANSALPHA);
- end
- function ENT:SetUp(plant, planter)
- self.plant = plant;
- if planter then
- if plant.name ~= "tree" then
- planter:SetNWInt("plants", planter:GetNWInt("plants") + 1);
- end
- self:SetOwner(planter);
- end
- timer.Simple(plant.gestation, function() self:Grow() end);
- end
- function ENT:CreateFruit()
- local plant = self.plant;
- local fruit = ents.Create("prop_physics");
- fruit:SetAngles( Angle(0, math.random(0, 360), 0) );
- fruit:SetModel(self.plant.fruit);
- local x, y, z = plant.fruitSpread[1], plant.fruitSpread[2], plant.fruitSpread[3];
- local pos = self.plant.fruitAnchor + Vector(math.random(x*-1, x), math.random(y*-1, y), math.random(z*-1, z));
- fruit:SetPos(self:GetPos() + pos);
- fruit:Spawn();
- fruit:SetParent(self);
- fruit:SetOwner(self:GetOwner());
- fruit.PhysgunDisabled = true;
- function fruit:Use(activator, caller)
- self:Use(activator, caller);
- end
- end
- function ENT:Grow()
- local owner = self:GetOwner();
- self.Color = Color(255, 255, 255, 255);
- self.Model = self.plant.base;
- self:Initialize();
- local num = 5;
- if IsValid(owner) then
- num = num + math.random(owner:GetSkills()["farming"] or 0);
- end
- for i = 1, num, 1 do
- self:CreateFruit();
- UTIL:Log("Added Fruit! " .. i .. " of " .. num);
- end
- end
- function ENT:Use(activator, caller)
- if IsValid(caller) and caller:IsPlayer() then
- caller:Eat(self.plant);
- self:GetChildren()[math.random(#self:GetChildren())]:Remove();
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement