Hi.
We rely on the entity "Gunlab" to spawn a prop instead of a weapon.
The problem is that the prop who is spawned is considered a "WorldProp" and we can't attribute it to a player.
Someone there a sense of why?
There is the LUA code :
1 function ENT:createProp()
2 self.Once = false
3 local prop = ents.Create("prop_physics")
4 prop:SetModel("models/props_c17/Lockers001a.mdl")
5 local propPos = self.Entity:GetPos()
6 prop:SetPos(Vector(propPos.x, propPos.y, propPos.z + 50))
7 prop:Spawn()
8 prop:SetOwner(self.Owner)
9 self.sparking = false
10 end
Thanxs in advance
I'm tryed that :
[lua]
function ENT:Use(activator, ply)
local owner = self.Entity.dt.owning_ent
local discounted = math.ceil(185 * 0.88)
local cash = self:SalePrice(activator)
if not activator:CanAfford(self:SalePrice(activator)) then
Notify(activator, 1, 3, "")
return ""
end
local diff = (self:SalePrice(activator) - self:SalePrice(owner))
if diff < 0 and not owner:CanAfford(math.abs(diff)) then
Notify(activator, 1, 3, "")
return ""
end
self.sparking = true
if not self.Once then
self.Once = true
activator:AddMoney(cash * -1)
Notify(activator, 1, 3, "" .. CUR .. tostring(cash) .. "")
if activator ~= owner then
local gain = 0
if owner:Team() == TEAM_GUN then
gain = math.floor(self.dt.price - discounted)
else
gain = math.floor(self.dt.price - 185)
end
if gain == 0 then
Notify(owner, 1, 3, "")
else
owner:AddMoney(gain)
local word = ""
if gain < 0 then word = "" end
Notify(owner, 1, 3, "" .. word .. "" .. CUR .. tostring(math.abs(gain)) .. "")
end
end
end
timer.Create(self.Entity:EntIndex() .. "prop_physics", 1, 1, self.createProp, self)
end
function ENT:createProp()
self.Once = false
local prop = ents.Create("prop_physics")
prop:SetModel("models/props_c17/Lockers001a.mdl")
local propPos = self.Entity:GetPos()
prop:SetPos(Vector(propPos.x, propPos.y, propPos.z + 50))
prop:Spawn()
prop:SetNWEntity("owner", ply)
self.sparking = false
end
[/lua]
It doesn't work ... The prop who is spawned is always "world prop".
We are newbies in LUA scripting :s
[QUOTE=Elarion-Cie;24968324]I'm tryed that :
[lua]
function ENT:Use(activator, ply)
local owner = self.Entity.dt.owning_ent
local discounted = math.ceil(185 * 0.88)
local cash = self:SalePrice(activator)
if not activator:CanAfford(self:SalePrice(activator)) then
Notify(activator, 1, 3, "")
return ""
end
local diff = (self:SalePrice(activator) - self:SalePrice(owner))
if diff < 0 and not owner:CanAfford(math.abs(diff)) then
Notify(activator, 1, 3, "")
return ""
end
self.sparking = true
if not self.Once then
self.Once = true
activator:AddMoney(cash * -1)
Notify(activator, 1, 3, "" .. CUR .. tostring(cash) .. "")
if activator ~= owner then
local gain = 0
if owner:Team() == TEAM_GUN then
gain = math.floor(self.dt.price - discounted)
else
gain = math.floor(self.dt.price - 185)
end
if gain == 0 then
Notify(owner, 1, 3, "")
else
owner:AddMoney(gain)
local word = ""
if gain < 0 then word = "" end
Notify(owner, 1, 3, "" .. word .. "" .. CUR .. tostring(math.abs(gain)) .. "")
end
end
end
timer.Create(self.Entity:EntIndex() .. "prop_physics", 1, 1, self.createProp, self)
end
function ENT:createProp()
self.Once = false
local prop = ents.Create("prop_physics")
prop:SetModel("models/props_c17/Lockers001a.mdl")
local propPos = self.Entity:GetPos()
prop:SetPos(Vector(propPos.x, propPos.y, propPos.z + 50))
prop:Spawn()
prop:SetNWEntity("owner", ply)
self.sparking = false
end
[/lua]
It doesn't work ... The prop who is spawned is always "world prop".
We are newbies in LUA scripting :s[/QUOTE]
I think some prop protections use the undo table to figure out which player an entity belongs to. Regardless of whether this fixes your problem or not, you should still add it to the undo table. Try adding this code from the wiki:
[lua]
undo.Create("prop")
undo.AddEntity(prop)
undo.SetPlayer(ply)
undo.Finish()
[/lua]
Make sure you pass the player entity to your createProp function.
And how can i pass the player entity to this function ?
[QUOTE=Elarion-Cie;24988982]And how can i pass the player entity to this function ?[/QUOTE]
Change this line:
[lua]
timer.Create(self.Entity:EntIndex() .. "prop_physics", 1, 1, self.createProp, self)
[/lua]
to:
[lua]
timer.Create(self.Entity:EntIndex() .. "prop_physics", 1, 1, self.createProp, self, ply)
[/lua]
and define your function like this:
[lua]
function ENT:createProp(ply)
[/lua]
Sorry, you need to Log In to post a reply to this thread.