[CODE]
if (dmg:GetAttacker():GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
addMoney(1000)
end
[/CODE]
I'm trying to make it so if the owner of the entity destroys the entity it would say "You have destoryed your own printer!" and anyone else that destroys the entity will recieve the message "LOLOOLOL" and money.
What's wrong with it? Can you post the full code (including the hook/function)
Also, I don't believe self:Getowning_ent() is an actual function. You're also missing the class for addMoney(). Is this a bunch of copypasta?
Try this
[CODE]
function ENT:OnTakeDamage(dmg)
self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage <= 0 then
if (dmg:GetAttacker() == self:GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
addMoney(1000)
end
self:Remove()
end
end
[/CODE]
Assuming this was the same thing you were trying to do in your previous thread
By the way, as said before, Getowning_ent isn't a function and the addMoney thing is missing a class
No its not a copypasta and self:Getowning_ent is a darkrp command which returns the owner's entity. and I didn't know what class I would use for ".addMoney" because I never defined it. I'm trying to ask if anyone would rewrite it into working format
[CODE]
function ENT:Initialize()
self:SetModel("models/props_c17/consolebox03a.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
self.damage = 100
end
function ENT:OnTakeDamage(dmg)
self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage <= 0 then
if (dmg:GetAttacker():GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
(IDKWHATCLASS).addMoney(1000)
end
self:Remove()
end
end
[/CODE]
I'm not really sure because "GetOwner" and "IsPlayer" will give me the same result "You have destoryed your own printer!" when I tested it
[CODE]
function ENT:Initialize()
self:SetModel("models/props_c17/consolebox03a.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then phys:Wake() end
self.damage = 100
end
function ENT:OnTakeDamage(dmg)
self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage <= 0 then
if (dmg:GetAttacker() == self:GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
self:GetOwner():addMoney(1000)
end
self:Remove()
end
end
[/CODE]
Based on my previous post
This makes it so if the owner destroys their printer it just tells them that they did, then if someone else destroyed it, they get given money.
Note I have no idea if any functions here are even mildly being used correctly, so if there are problems with this, I don't actually know why
Ya it semi work but I wanted to define Owner and Player differently
What do you mean? The owner IS a player...
How do you want to define them???
[editline]31st January 2016[/editline]
Actually, it might not be working because you didn't show what your [URL="[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/ENTITY/SpawnFunction]ENTITY/SpawnFunction[/url]"]ENTITY:SpawnFunction[/URL] was. You need to set the owner in that (I think)
The owner of the entity is a player and the attacker is a different player.
If the owner destroys it he gets nothing.
If the the attacker(different player) destroys it, he will get money.
Why would the other player (the attacker) get money from destroying it when it does the following:
[CODE]
self:GetOwner():addMoney(1000)
[/CODE]
That clearly gives the OWNER money, assuming the owner is properly defined as the OWNER of the entity. Are you testing this in single player, because if you are, obviously it would give you money because you're both the attacker and the owner.
What do you want to happen? The owner to get money if he destroys the printer? The attacker to get money?
[editline]31st January 2016[/editline]
OH, do you mean you want the attacker to get money for destroying the printer?
[editline]31st January 2016[/editline]
If so, try this:
[CODE]
if (dmg:GetAttacker() == self:GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
dmg:GetAttacker():addMoney(1000)
end
[/CODE]
[QUOTE=MPan1;49640975]Why would the other player (the attacker) get money from destroying it when it does the following:
[CODE]
self:GetOwner():AddMoney(1000)
[/CODE]
That clearly gives the OWNER money, assuming the owner is properly defined as the OWNER of the entity. Are you testing this in single player, because if you are, obviously it would give you money because you're both the attacker and the owner.
What do you want to happen? The owner to get money if he destroys the printer? The attacker to get money?
[editline]31st January 2016[/editline]
OH, do you mean you want the attacker to get money for destroying the printer?
[editline]31st January 2016[/editline]
If so, try this:
[CODE]
if (dmg:GetAttacker() == self:GetOwner()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "You have destoryed your own printer!")
elseif (dmg:GetAttacker():IsPlayer()) then
DarkRP.notify(self:Getowning_ent(), 1, 4, "LOLOLLOLOLO");
dmg:GetAttacker():AddMoney(1000)
end
[/CODE][/QUOTE]
I didn't see that you change the calls for Add money.
I want the attacker to get the money when he destroy the printer.
Btw I just tried the script out again the one u just posted ^^
And all I got was "LOLOOLOLLOL" either if a attacker destroyed it or the owner
Lua Error: [ERROR] addons/darkrpmodification-master/lua/entities/1_moneyprinter/init.lua:44: attempt to call method 'AddMoney' (a nil value) 1. unknown - addons/darkrpmodification-
^^^^
idk what happend, u did define the calls that receives money
I removed the money part, but it still says "LOLOLOLOLOLL" after the owner destroys it
Change AddMoney to addMoney
I thought it had a capital cause I was looking in the [URL="http://wiki.darkrp.com/index.php/DarkRP.Player.AddMoney"]DarkRP wiki[/URL]... shows how much I know about DarkRP
[editline]31st January 2016[/editline]
Updated my previous posts
I still got "LOLOOLOLOLOLOLL" when the owner destroyed it.
Lua Error: [ERROR] addons/darkrpmodification-master/lua/entities/1_moneyprinter/init.lua:64: attempt to call method 'CreateMoneybag' (a nil value) 1. unknown - addons/darkrpmodification-master/lua/entities/1_moneyprinter/init.lua:64
:/
Thanks a lot though
[editline]31st January 2016[/editline]
I have fixed it :goodjob:
TO
[CODE]
if (dmg:GetAttacker() == self:GetOwner()) then
[/CODE]
[CODE]
if (dmg:GetAttacker() == self:Getowning_ent()) then
[/CODE]
Sorry, you need to Log In to post a reply to this thread.