How do I give someone points for pointshop by using an entity?

I added an XP system to my server, and I want it where when the person buys a level 99 book, it gives them 2000 points for pointshop.
How do I go about adding this?

I still need help with this.

[lua]
function ENT:Use( activator, caller ) – when the entity is used (+use)
if ( activator:IsPlayer() ) then – check if the entity using it, is a player
activator:PS_GivePoints(2000) – I have no idea if running this will actually work, but it’s using the pointshop function on the entity using the other entity
end
end
[/lua]

That’s what you asked for, but it’ll give them 2k every single time they press e…
(Have never dabbled with Lua before, so don’t take it as being working but it’s pretty much there I hope)

So you should just add

Player:PS_GivePoints(2000)

To your buying function…

This doesn’t work.
I just need it where if I use the book, I’ll get 2,000 points.

Do you get any errors, where did you put it.

I added it to this:
[lua]DarkRP.createEntity(“Prestige Mode”, {
level = 99,
GiveXPAmountOnUse = -99999999999999,
ent = “xpbook”,
model = “models/props_lab/binderbluelabel.mdl”,
price = 10000000,
max = 20,
cmd = “buy99book”,
allowed = {TEAM_SCHOLAR}
})[/lua]

[lua]
DarkRP.createEntity(“Prestige Mode”, {
level = 99,
GiveXPAmountOnUse = -99999999999999,
ent = “xpbook”,
model = “models/props_lab/binderbluelabel.mdl”,
price = 10000000,
max = 20,
cmd = “buy99book”,
allowed = {TEAM_SCHOLAR},
function ENT:Use( activator, caller ) – when the entity is used (+use)
if ( activator:IsPlayer() ) then – check if the entity using it, is a player
activator:PS_GivePoints(2000) – I have no idea if running this will actually work, but it’s using the pointshop function on the entity using the other entity
end
end
})
[/lua]

Try that? Maybe?

Got an error.
[lua][ERROR] addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:303: ‘(’ expected near ‘ENT’

  1. unknown - addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:0[/lua]

-snip- figuring this out wait a min

Error:
[lua][ERROR] addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:303: ‘)’ expected near ‘:’

  1. unknown - addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:0[/lua]

Man, I don’t know.

If there’s a way to get the player buying the entity, we could just run

Buyer:PS_GivePoints(2000)

But…

Thanks for trying bud.
Anyone else have any ideas?

I’m no coder but you could do something like
[lua]
function ENT:Use( ply )
ply:PS_GivePoints(2000)
end
[/lua]
Not saying to do exactly that but it should be something like that :-/

[editline]3rd May 2014[/editline]

If that doesn’t work try replacing ply with self.Player

I got this error:
[lua][ERROR] addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:303: ‘)’ expected near ‘:’

  1. unknown - addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:0[/lua]

[lua]
function givePointsOnBuy( ply, tbl, ent )
if ( ent == “xpbook” ) then
ply:PS_GivePoints(2000)
end
end
hook.Add( “playerBoughtCustomEntity”, “givePSPointsForEntity”, givePointsOnBuy( ply, tbl, ent ) )
[/lua]

[editline]5th May 2014[/editline]

That’s the function and hook we need and that should work. Only ‘iffy’ part is the conditional

[editline]5th May 2014[/editline]

This’ll need to go into autorun / server

Should be

[lua]
function givePointsOnBuy( ply, tbl, ent )
if ( ent == “xpbook” ) then
ply:PS_GivePoints(2000)
end
end
hook.Add( “playerBoughtCustomEntity”, “givePSPointsForEntity”, givePointsOnBuy )
[/lua]

When inserting the function in a hook, you don’t need the arguments.

Thank you :slight_smile:

Do I create a new file in lua > autorun > server with that?

Yes.

Okay, I created that file and added the code but I get this error:
[lua][ERROR] addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:303: ‘(’ expected near ‘ENT’

  1. unknown - addons/darkrpmodification/lua/darkrp_customthings/shipments.lua:0[/lua]