• Having an entity touch another entity?
    4 replies, posted
So I am currently trying to make an entity that will touch another entity to make that first one disappear and give you money for it. I'll paste the code for the two entities down below. The First Entity function ENT:Initialize() self:SetModel("models/props_junk/cardboard_box003a.mdl") self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) self:SetUseType(SIMPLE_USE) self:SetTrigger(true) self.damage = 100 local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end end function ENT:OnTakeDamage(dmg)     self.damage = (self.damage or 100) - dmg:GetDamage()     if self.damage <= 0 then             self:Remove()         end end The Second Entity util.AddNetworkString("received") function ENT:Initialize() self:SetModel( "models/Humans/Group01/Male_04.mdl" ) self:SetHullType( HULL_HUMAN ) self:SetHullSizeNormal () self:SetNPCState ( NPC_STATE_SCRIPT ) self:SetSolid( SOLID_BBOX ) self:CapabilitiesAdd( CAP_ANIMATEDFACE ) self:SetUseType( SIMPLE_USE ) self:DropToFloor() self:SetTrigger(true) end function ENT:StartTouch(entity) if entity:GetClass() == "deliverysg" then net.Start("received") net.Send(caller) else end end net.Receive( "received", function(name, caller) caller:addMoney(125) caller:SendLua([[ chat.AddText( Color(255, 255, 255), "Thanks! Don't tell anyone about this!") ]]) end) I've been changing it around and currently there are no errors from what I last saw however, when moving the first entity into the second it doesn't do anything.
caller is nil dont use a net, it's entirely unnecessary received is a super generic net that will be overwritten name, caller are not the parameters for net.receive's callback
I purposely didn't add in anything to make the entity disappear for testing purposes to see if it'll give the player money or not. Also, how would I go about doing it then if not to use a net? Because in the ENT:StartTouch won't use any other parameters other than entity itself.
you can use this: https://wiki.garrysmod.com/page/Entity/NetworkVar example: ENT.Type = "anim" ENT.Base = "base_gmodentity" ENT.PrintName = "Cooker" ENT.Spawnable = true ENT.Category = "Crazy Cooking Addon" function ENT:SetupDataTables()     self:NetworkVar("Int",0,"finishBakingTime")     self:NetworkVar("Bool",1,"isBaking") --Network Variables are used for syncing variables between server and client instead of using NetMesh(?) end AddCSLuaFile("shared.lua") include("shared.lua") resource.AddFile("addons/cooking_addon/sound/ding.wav") function ENT:Initialize()         util.PrecacheSound("addons/cooking_addon/sound/ding.mp3")         self:SetModel("models/props_wasteland/kitchen_stove002a.mdl")         self:PhysicsInit(SOLID_VPHYSICS)         self:SetMoveType(MOVETYPE_VPHYSICS)         self:SetSolid(SOLID_VPHYSICS)         local phys = self:GetPhysicsObject()         if (phys:IsValid()) then         phys:Wake()     end              self:SetfinishBakingTime(CurTime())     self:SetisBaking(false) end function ENT:StartTouch(ent)     if ent:GetClass() == "dough" and !self:GetisBaking() then      ent:Remove()      self:SetisBaking(true)      self:SetfinishBakingTime(CurTime() + 5)               end end function ENT:Think()     if self:GetisBaking() then         self:StartLoopingSound("ambient/fire/fire_small1.wav") else         self:StopLoopingSound(0)     end     if self:GetisBaking() == true then         if self:GetfinishBakingTime() <= CurTime() then                 self:SetisBaking(false)                 if self:GetisBaking() == false then                                          self:EmitSound("ding.wav") print("Sound Emitted!")                 end                 local bread = ents.Create("bread")                                  bread:SetPos(self:GetPos() + Vector(0,25,0))                 bread:Spawn()                                  end             end         end
net.Send(caller) like said in the first post you need to define caller in this line. If the owner of the npc entity is the one you want to receive the cash then you need to do something like ent.Owner = pl before you spawn it then net.Send(self.Owner) After you define who the net message is being sent to, it should work fine.
Sorry, you need to Log In to post a reply to this thread.