Is there anyway I can use the createShipment( ply, args ) function to make an entity create a shipment of, for example, weapon_crowbar(s)?
This is the function
[CODE]local function createShipment(ply, args)
local id = tonumber(args) or -1
local ent = Entity(id)
ent = IsValid(ent) and ent or ply:GetEyeTrace().Entity
if not IsValid(ent) or ent:GetClass() ~= "spawned_weapon" or ent.PlayerUse == false then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("invalid_x", "argument", ""))
return
end
local pos = ent:GetPos()
if pos:Distance(ply:GetShootPos()) > 130 or not pos:isInSight({ent, ply} , ply) then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("distance_too_big"))
return
end
ent.PlayerUse = false
local shipID
for k,v in pairs(CustomShipments) do
if v.entity == ent:GetWeaponClass() then
shipID = k
break
end
end
if not shipID then
DarkRP.notify(ply, 1, 4, DarkRP.getPhrase("unable", "/makeshipment", ""))
return
end
local crate = ents.Create(CustomShipments[shipID].shipmentClass or "spawned_shipment")
crate.SID = ply.SID
crate:SetPos(ent:GetPos())
crate.nodupe = true
crate:SetContents(shipID, ent.dt.amount)
crate:Spawn()
crate:SetPlayer(ply)
crate.clip1 = ent.clip1
crate.clip2 = ent.clip2
crate.ammoadd = ent.ammoadd or 0
SafeRemoveEntity(ent)
local phys = crate:GetPhysicsObject()
phys:Wake()
end
DarkRP.defineChatCommand("makeshipment", createShipment, 0.3)[/CODE]
I want to have an entity do
[CODE]function ENT:Use( activator, caller )
--Create ak47 shipment
end
[/CODE]
What are the args in the createShipment function and how do I use them?
Thanks.
I got this:
[lua]
local function makeShipment(ply, args)
if args == "" then return end
local found
local foundKey
for k,v in pairs(CustomShipments) do
if args == v.entity then
found = v
foundKey = k
end
end
local crate = ents.Create(found.shipmentClass or "spawned_shipment")
crate.SID = ply.SID
crate:Setowning_ent(ply)
crate:SetContents(foundKey, found.amount)
crate:SetPos(ply:GetEyeTrace().HitPos + Vector(0,0,50))
crate.nodupe = true
crate.ammoadd = found.spareammo
crate.clip1 = found.clip1
crate.clip2 = found.clip2
crate:Spawn()
crate:SetPlayer(ply)
if found.shipmodel then
crate:SetModel(found.shipmodel)
crate:PhysicsInit(SOLID_VPHYSICS)
crate:SetMoveType(MOVETYPE_VPHYSICS)
crate:SetSolid(SOLID_VPHYSICS)
end
local phys = crate:GetPhysicsObject()
phys:Wake()
if found.weight then
phys:SetMass(found.weight)
end
if CustomShipments[foundKey].onBought then
CustomShipments[foundKey].onBought(ply, CustomShipments[foundKey], crate)
end
hook.Call("playerBoughtShipment", nil, ply, CustomShipments[foundKey], crate, price)
end
[/lua]
The only thing you need to do is something like this:
[lua]
function ENT:Use( activator, caller )
makeShipment(activator, "weapon_crowbar")
end
[/lua]
[editline]13th June 2014[/editline]
And the crowbar shipment must be registerend on the DarkRP shipments for this to work!!!!!
[QUOTE=GGG KILLER;45096506]I got this:
[lua]
local function makeShipment(ply, args)
if args == "" then return end
local found
local foundKey
for k,v in pairs(CustomShipments) do
if args == v.entity then
found = v
foundKey = k
end
end
local crate = ents.Create(found.shipmentClass or "spawned_shipment")
crate.SID = ply.SID
crate:Setowning_ent(ply)
crate:SetContents(foundKey, found.amount)
crate:SetPos(ply:GetEyeTrace().HitPos + Vector(0,0,50))
crate.nodupe = true
crate.ammoadd = found.spareammo
crate.clip1 = found.clip1
crate.clip2 = found.clip2
crate:Spawn()
crate:SetPlayer(ply)
if found.shipmodel then
crate:SetModel(found.shipmodel)
crate:PhysicsInit(SOLID_VPHYSICS)
crate:SetMoveType(MOVETYPE_VPHYSICS)
crate:SetSolid(SOLID_VPHYSICS)
end
local phys = crate:GetPhysicsObject()
phys:Wake()
if found.weight then
phys:SetMass(found.weight)
end
if CustomShipments[foundKey].onBought then
CustomShipments[foundKey].onBought(ply, CustomShipments[foundKey], crate)
end
hook.Call("playerBoughtShipment", nil, ply, CustomShipments[foundKey], crate, price)
end
[/lua]
The only thing you need to do is something like this:
[lua]
function ENT:Use( activator, caller )
makeShipment(activator, "weapon_crowbar")
end
[/lua]
[editline]13th June 2014[/editline]
And the crowbar shipment must be registerend on the DarkRP shipments for this to work!!!!![/QUOTE]
Thank you very much, I found a way to spawn them using the shipment table ids but this is very inconvienient. You helped me a lot!!!
Sorry, you need to Log In to post a reply to this thread.