Hi, I have a problem/need help here when making *Talking* Portal Turret NPC..
1.Need help with making Portal Turret NPC disabled, retired & search sound script.
2.Timer.Destroy doesn't work on the script.
[I]Timer Error: entities/npc_portal_turret_floor/init.lua:30: Tried to use a NULL entity![/I]
3.Need help with Don't use Portal Turret Auto Search Sound when disabled.
I created a Timer that repeats every 15 seconds.. ([U]Portal Turret Auto Search Sound[/U])
[B]Init.lua Script :[/B]
[lua]
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
ENT.DeploySound = NULL
ENT.AutoSearchSound = NULL
util.PrecacheModel( "models/props/turret_01.mdl" )
function ENT:SpawnFunction( ply, tr )
if ( not tr.Hit ) then return end
local SpawnPos = tr.HitPos + tr.HitNormal
local SpawnAng = ply:GetAimVector( ):Angle( ); SpawnAng.p = 0; SpawnAng.r = 0; SpawnAng.y = ( SpawnAng.y+0 ) % 360
local turret = ents.Create( "npc_turret_floor" )
turret:SetModel( "models/props/turret_01.mdl" )
turret:SetPos( SpawnPos )
turret:SetAngles( SpawnAng )
turret:SetKeyValue( "targetname", "npc_portal_turret_floor" )
turret:Spawn( )
turret:Activate( )
self.DeploySound = CreateSound( turret, "npc/turret_floor/turret_deploy_".. math.random( 1,6 ) ..".wav" )
self.DeploySound:Play( )
function AutoSearchSoundScript( ply )
self.AutoSearchSound = CreateSound( turret, "npc/turret_floor/turret_autosearch_".. math.random( 1,6 ) ..".wav" )
self.AutoSearchSound:Play( )
end
timer.Create( "AutoSearch", 15, 0, AutoSearchSoundScript, ply )
return turret
end
function ENT:Initialize()
self:SetParent( turret )
end
function ENT:OnRemove()
if turret && turret != NULL && turret != nil then
turret:Remove()
timer.Destroy( "AutoSearch" )
end
end
[/lua]
Am i doing it wrong or? :smile:
[IMG]http://i.tinyuploads.com/020Lsa.jpg[/IMG]
It doesn't work..
[I]Timer Error: attempt to call a nil value[/I]
Shows every 15 seconds. If i'm using that.
[editline]4th August 2013[/editline]
Please can someone help me?
I will add your name on the addons if you helped me :3
[QUOTE=matyas;41706785][lua]timer.Create( "AutoSearch", 15, 0, AutoSearchSoundScript, ply )[/lua]
I think it's:
[lua]timer.Create( "AutoSearch", 15, 0, AutoSearchSoundScript(ply) )[/lua][/QUOTE]
[lua]timer.Create( "AutoSearch", 15, 0, function() AutoSearchSoundScript(ply) end )[/lua]
Sometimes, you just need that (I know, function inside a function). Not really sure why, but it has worked many times for me.
This is how I would do it.
[lua]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
ENT.DeploySound = NULL
ENT.AutoSearchSound = NULL
util.PrecacheModel( "models/props/turret_01.mdl" )
function ENT:SpawnFunction( ply, tr )
if (!tr.Hit) then return end
local SpawnPos = tr.HitPos + tr.HitNormal
local SpawnAng = ply:GetAimVector( ):Angle( ); SpawnAng.p = 0; SpawnAng.r = 0; SpawnAng.y = ( SpawnAng.y+0 ) % 360
local turret = ents.Create( "npc_turret_floor" )
turret:SetModel( "models/props/turret_01.mdl" )
turret:SetPos( SpawnPos )
turret:SetAngles( SpawnAng )
turret:SetKeyValue( "targetname", "npc_portal_turret_floor" )
turret:Spawn( )
turret:Activate( )
self.DeploySound = CreateSound( turret, "npc/turret_floor/turret_deploy_".. math.random( 1,6 ) ..".wav" )
self.DeploySound:Play( )
timer.Adjust( "AutoSearch", 15, 0, function()
self.AutoSearchSound = CreateSound( turret, "npc/turret_floor/turret_autosearch_".. math.random( 1,6 ) ..".wav" )
self.AutoSearchSound:Play( )
end)
return turret
end
function ENT:Initialize()
self:SetParent( turret )
end
function ENT:OnRemove()
if timer.Exists( "AutoSearch" ) then
timer.Destroy( "AutoSearch" )
end
if turret and turret != NULL and turret != nil then
turret:Remove()
self.DeploySound:Stop()
self.AutoSearchSound:Stop()
self.DeploySound = nil
self.AutoSearchSound = nil
end
end[/lua]
Sorry, you need to Log In to post a reply to this thread.