Item -> Entities

Hey i need some help, with this code, how do i make so this item spawn a Entitie.


local ITEM                     = {};

ITEM.ID                     = 24;
ITEM.Reference                 = "item_radio";

ITEM.Name                     = "Old Radio";
ITEM.Description            = "stfu and lissen.";

ITEM.Weight                 = 5;
ITEM.Cost                    = 100;

ITEM.MaxStack                 = 1;

ITEM.InventoryModel         = "RADIO.mdl";
ITEM.ModelCamPos                 = Vector(66, -4, 9);
ITEM.ModelLookAt                 = Vector(0, 0, 0);
ITEM.ModelFOV                     = 70;
ITEM.WorldModel             = "models/RADIO.mdl";

ITEM.RestrictedSelling         = false; // Used for drugs and the like. So we can't sell it.

ITEM.EquipZone                 = nil;                                            
ITEM.PredictUseDrop            = true; // If this isn't true, the server will tell the client when something happens to us based on the server's OnUse

if SERVER then

    function ITEM.OnUse ( Player )        
        return false;
    end
    
    function ITEM.OnDrop ( Player )
        return true;
    end
    
    function ITEM.Equip ( Player )

    end
    
    function ITEM.Holster ( Player )

    end
    
    
end

GM:RegisterItem(ITEM);

This didn’t work, (sry im not good with Lua)




local ITEM                     = {};

ITEM.ID                     = 30;
ITEM.Reference                 = "item_radio";

ITEM.Name                     = "Radio";
ITEM.Description            = "A real working radio.";

ITEM.Weight                 = 5;
ITEM.Cost                    = 100;

ITEM.MaxStack                 = 1;

ITEM.InventoryModel         = "models/props_debris/wood_board06a.mdl";
ITEM.ModelCamPos                 = Vector(66, -4, 9);
ITEM.ModelLookAt                 = Vector(0, 0, 0);
ITEM.ModelFOV                     = 70;
ITEM.WorldModel             = "models/props_debris/wood_board06a.mdl";

ITEM.RestrictedSelling         = false; // Used for drugs and the like. So we can't sell it.

ITEM.EquipZone                 = nil;                                            
ITEM.PredictUseDrop            = true; // If this isn't true, the server will tell the client when something happens to us based on the server's OnUse

if SERVER then

    function ITEM.OnUse ( Player )        
        return false;
    end
    
    function ITEM.OnDrop ( Player )
    ent = ents.Create("npc_zombie")
        return true;
    end
    
    function ITEM.Equip ( Player )

    end
    
    function ITEM.Holster ( Player )

    end
    
else

    function ITEM.OnUse ( slotID )        
        return false;
    end
    
    function ITEM.OnDrop ( )
    ent = ents.Create("npc_zombie")
        return true;
    end
    
end

GM:RegisterItem(ITEM);


Well… You created an entity, but you didnt spawn it. Use this instead:


ent = ents.Create("npc_zombie")
ent:SetPos(<<A Vector - the position you want the entity to appear when spawned>>)
ent:SetAngles(<<An Angle - the direction you want the entity to face when spawned>>)
ent:Spawn() -- And finally spawn it at the Position and Angle you specified earlier

Here ya go. Replace the <<>> with position and angle ofcourse.

Well I think it would automatically do that, inside its base.

Maybe it’s:
[lua]
if SERVER then

function ITEM:OnUse ( Player )        
    return false;
end

function ITEM:OnDrop ( Player )
    return true;
end

function ITEM:Equip ( Player )

end

function ITEM:Holster ( Player )

end

end[/lua]

?

What shold i set? i want it to spawn infrot of me.




if SERVER then

function ITEM:OnUse ( Player )        
    return false;
end

function ITEM:OnDrop ( Player )

ent = ents.Create(“npc_zombie”)
ent:SetPos(???)
ent:SetAngles(???)
ent:Spawn()
return true;
end

function ITEM:Equip ( Player )

end

function ITEM:Holster ( Player )

end

end

Like I had said, I believe that all of that would already be done for him.

Are you using some sort of framework?

Perp2