im working on a gamemode and i came across a problem. I want a spawned entity to be destroyed and drop 3 other entites of a diffrent type when leftclick with a custom swep
i got it to function but it throws me this error:
[ERROR] gamemodes/the scavengers/entities/weapons/multitool/shared.lua:40: attempt to call global 'spawnm' (a nil value)
1. unknown - gamemodes/the scavengers/entities/weapons/multitool/shared.lua:40
here is me code
the multitool shared.lua:
[CODE]//General Variables\\
SWEP.DrawCrosshair = true
SWEP.Weight = 3
SWEP.ViewModel = "models/weapons/v_hands.mdl"
SWEP.WorldModel = ""
SWEP.HoldType = "melee"
SWEP.ViewModelFOV = 64
SWEP.Slot = 0
SWEP.Purpose = ""
SWEP.AutoSwitchTo = false
SWEP.Contact = "ewmiter@gmail.com"
SWEP.Author = "ewmiter"
SWEP.FiresUnderwater = false
SWEP.Spawnable = false
SWEP.AdminSpawnable = false
SWEP.SlotPos = 0
SWEP.Instructions = "do stuff"
SWEP.AutoSwitchFrom = false
SWEP.base = "weapon_base"
SWEP.Category = "The Scavengers"
SWEP.DrawAmmo = true
SWEP.PrintName = "MultiTool"
//SWEP:Initialize()\\
function SWEP:Initialize()
if ( SERVER ) then
self:SetWeaponHoldType( "normal" )
end
end
function isbace(ent)
if ent[2] == washingm then
return true
else
return false
end
end
function SWEP:PrimaryAttack()
local ent = self.Owner:GetEyeTrace().Entity
if ent:GetPos():Distance(self.Owner:GetPos()) < 100 and isbace(ent) then
spawnm(ent)
end
//print(ent)
end
[/CODE]
init.lua for gamemode:
[CODE]AddCSLuaFile("cl_init.lua")
include("shared.lua")
playerMod = {
"models/player/Group01/Male_01.mdl",
"models/player/Group01/Male_02.mdl",
"models/player/Group01/Male_03.mdl",
"models/player/Group01/Male_04.mdl",
"models/player/Group01/Male_05.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_06.mdl",
"models/player/Group01/Male_07.mdl",
"models/player/Group01/Male_08.mdl",
}
function GM:PlayerSpawn(pl)
pl:Give("weapon_physcannon")
pl:Give("MultiTool")
pl:SetModel(table.Random(playerMod))
end
function GM:ShowTeam(pl)
ent = ents.Create("washingm")
ent:SetPos(pl:GetPos() + Vector(0, 0, 150))
ent:Spawn()
ent:Activate()
PrintMessage(HUD_PRINTTALK, "it is working")
end
function metalsheat(entity, times)
for i = 1, times do
local ent = ents.Create("metalsheat")
ent:SetPos(Vector(tostring(entity)) + Vector(0,0,70))
ent:Spawn()
ent:Activate()
print(tostring(Ent))
end
end
function spawnm(ent)
if ent:IsValid() then
metalsheat(ent:GetPos(), 3)
ent:Remove()
end
end[/CODE]
sorry if this makes no sense
Shared is shared ( CLIENT and SERVER ) while init is SERVER only... Your function exists on the server, but the code calling it is clientside. Update the function so that if ( SERVER ) then ... end wraps the call.
thank you so much, i have been trying troubleshoot this problem for 3 days and you fixed it
Sorry, you need to Log In to post a reply to this thread.