Accesing SetPData from SWEP

Hey guys!

I’ve just started with coding in Lua, and thought it would be fun to make an EXP gamemode. At this point I’ve got my gamemode for that working, but now I want to create an EXP gun.
I use SetPData for my experience points but how do I access that function from within a SWEP?

I seem to keep having a hard time with the way the game is scripted, and how I access a certain component. Is there a tutorial for that of some sort?



No, Bad idea. Base your stats on mouse1 with a think hook or with kills.

What do you exactly mean? At the moment I do already have an EXP system, but I need help with the gun. I just want that when I shoot, it just adds EXP points

Thats exploitable. Don’t make a gun an have it add exp on primary or secondary fire.

Why not? That’s what he wants.

In a SWEP method you can access the player holding it with self.Owner. You can then use player methods such as SetPData on it.

I’ve got it working now, but GetPData and SetPData are really laggy. Is there a fix for that?

Yup, don’t use them unless necessary.

That is, you don’t have to save the xp in the database everytime it changes, you could do it say every few minutes or something similar. During that time save the xp the cheap way, something like ply.XP

And you should never have to use GetPData more then once, when the player first joins. After that you can use ply.XP to keep track of it.

Thanks mate! It was really helpfull!