Hey Guys!
I'm currently coding a Garry's Mod RP Gamemode. I am attempting to make a Door Bell, I have everything working except the sound is not emitting.
Here's my code:
[B][U]
INIT.LUA[/U][/B]
[code]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
function ENT:Initialize()
self:SetModel("models/hunter/blocks/cube025x025x025.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
self:SetUseType(SIMPLE_USE) --Makes it so you cant hold down use and get a ton of ammo.
local phys = self:GetPhysicsObject() -- Phys == all our physics
if(IsValid(phys)) then--If physics are valid, turn them on.
phys:Wake()
end
self:SetHealth(self.BaseHealth) --self points to whatever entitiy is being initialized
end
function ENT:SpawnFunction(ply, tr, ClassName)--Player, Location in front of player, and class name.
--Will be removed when we add it to our shop.
if(!tr.Hit) then return end--If front of them isnt hitting anything it wont spawn.
local entCount = ply:GetNWInt(ClassName .. "count")--Looks for classname network integer, then with count
if(entCount < self.Limit) then
local SpawnPos = ply:GetShootPos() + ply:GetForward() * 80--Sets pos infront of player(the shoot posistion), then gets vector by doing getforward, and puts in far infrom with *80.
self.Owner = ply
local ent = ents.Create(ClassName)-- cReate ammodispenser
ent:SetPos(SpawnPos)
ent:Spawn()
ent:Activate()
ply:SetNWInt(ClassName .. "count", entCount + 1)
return ent
end
return
end
function ENT:Use(activator, caller)--Activator = person using it. PROBLEM IS HERE <<<<<<
Entity:EmitSound( "vo/npc/male01/moan01.wav", soundLevel=75, pitchPercent=100, volume=1, channel=CHAN_AUTO) -- <<<<<<<<<
activator:ChatPrint("fuck dis")
return
end
function ENT:Think()
--Called Every tick
end
function ENT:OnTakeDamage(damage)
self:SetHealth(self:Health() - damage:GetDamage())--Sets your health to whatever your health is minus the amount of damage.
if(self:Health() <= 0) then
self:Remove()
end
end
function ENT:OnRemove()
local Owner = self.Owner
local ClassName = self:GetClass()
local entCount = Owner:GetNWInt(ClassName .. "count")
Owner:SetNWInt(ClassName .. "count", entCount - 1)
end
[/code]
[B][U]SHARED.LUA[/U][/B]
[code]
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.Catergory = "Buildings"
ENT.Limit = 3
ENT.BaseHealth = 100
ENT.Owner = nil
ENT.PrintName = "DoorBell"
ENT.Author = "Symclin"
ENT.Purpose = "Ring a Bell"
ENT.Instructions = "Place and Use"
ENT.Spawnable = true
ENT.AdminSpawnable = false
[/code]
[B][U]CL_INIT.LUA[/U][/B]
[code]
include("shared.lua")
function ENT:Draw()
self:DrawModel()
end
[/code]
[B][U]Error im Getting:[/U][/B]
[code]
[ERROR] gamemodes/test/entities/entities/doorbell/init.lua:58: ')' expected near '='
1. unknown - gamemodes/test/entities/entities/doorbell/init.lua:0
[/code]
(FUCK DIS Does print in chat, emit does not make sound.)
[CODE]Entity:EmitSound("vo/npc/male01/moan01.wav",75,100,1,CHAN_AUTO)[/CODE]
Only identify what the variables are when it is a table.
What line is line 58?
[QUOTE=BillyOnWiiU;49370381][CODE]Entity:EmitSound("vo/npc/male01/moan01.wav",75,100,1,CHAN_AUTO)[/CODE]
Only identify what the variables are when it is a table.[/QUOTE]
[code]
Entity:EmitSound("vo/npc/male01/moan01.wav")
[/code]
So is this correct?
[editline]22nd December 2015[/editline]
[QUOTE=Skere_;49370395]What line is line 58?[/QUOTE]
Its the line in the function use function, it has comment saying --PROBLEM HERE
[QUOTE=Symclin;49370538]So is this correct?[/QUOTE]
Why don't you try it?
[QUOTE=BillyOnWiiU;49370610]Why don't you try it?[/QUOTE]
Still didn't work, I'm getting the exact same answer.
Thanks for the help though!
[QUOTE]Entity:EmitSound("vo/npc/male01/moan01.wav")[/QUOTE]
Here there is no Entity variable.
You have to use self instead.
[QUOTE]self:EmitSound("vo/npc/male01/moan01.wav")[/QUOTE]
[QUOTE=Myrage2000;49374297]Here there is no Entity variable.
You have to use self instead.[/QUOTE]
Thank you very much, this worked!!!
Could you explain why I use self instead? Is it just because ent isn't defined?
[QUOTE=Symclin;49376958]Thank you very much, this worked!!!
Could you explain why I use self instead? Is it just because ent isn't defined?[/QUOTE]
ENT:OnTakeDamage
You don't have to define it again
Sorry, you need to Log In to post a reply to this thread.