Entity with Console Command

Ok, I don’t know much LUA coding, but I would like a entity that it has a model of a book, if you press ‘E’ on it will run a console command which is:

workbench_addrecipe_C “Glock” “models/weapons/w_pist_glock18.mdl” “weapon_glock2” “Log” 1 “” 0 “” 0 “” 0

I would appreciate this a lot, thanks.

Not an expert coder either, but I think it would be:


function ENT:Use()
ply:ConCommand("workbench_addrecipe_C "Glock" "models/weapons/w_pist_glock18.mdl" "weapon_glock2" "Log" 1 "" 0 "" 0 "" 0")
end 

Where would I put this?

It most likely wont work, but put it in the entities init.lua (I think).

[editline]19th March 2011[/editline]

Yay, I got boxed by two people who didn’t bother to tell me why I’m wrong.

Hah, you’re using my Medieval Entities mod? :stuck_out_tongue:

Your string in the ConCommand is incorrect. It would be more like this:
[lua]
function ENT:Use()
ply:ConCommand(‘workbench_addrecipe_C “Glock” “models/weapons/w_pist_glock18.mdl” “weapon_glock2” “Log” 1 “” 0 “” 0 “” 0’)
end
[/lua]

Idiots don’t know Lua.

Define ply, you can’t just use it in a function without declaring it in the function parameters.

Calm down:
[lua]
function ENT:Use(a, c)
a:ConCommand(‘workbench_addrecipe_C “Glock” “models/weapons/w_pist_glock18.mdl” “weapon_glock2” “Log” 1 “” 0 “” 0 “” 0’)
end
[/lua]
Happy?

Also FYI you can use it without declaring it in the function perimeters it just has to be declared somewhere.

[lua]function ENT:Initialize()
self:SetUseType(“SIMPLE_USE”)
end

function ENT:Use( act, call)
if act:IsPlayer() then
act:ConCommand(“COMMAND HERE”)
end
end
[/Lua]

That will work.