Question about swep [DarkRP]

How to get another player’s money for a primary attack, I wrote a scrape, but I do not think that it will work:


SWEP.PrintName = "Check player money"

SWEP.Author = "dj-34"
SWEP.Contact = "VK"
SWEP.Purpose = ""
SWEP.Instructions = "left mouse button to check player's money."

SWEP.Category = "Other"

SWEP.Spawnable= true
SWEP.AdminSpawnable= true
SWEP.AdminOnly = false

SWEP.ViewModelFOV = 63
SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"
SWEP.ViewModelFlip = false

SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

SWEP.Slot = 6
SWEP.SlotPos = 1

SWEP.UseHands = false

SWEP.HoldType = "Pistol"

SWEP.DrawCrosshair = true

SWEP.DrawAmmo = false

SWEP.ReloadSound = ""

SWEP.Base = "weapon_base"

function SWEP.PrimaryAttack()
	print(ply:getDarkRPVar( money ))
end





function SWEP:PrimaryAttack()
	local target = self.Owner:GetEyeTrace().Entity
	if target:IsPlayer() then
		print(target:getDarkRPVar( "money" ))
	end
end


You can add distance checks so that you cant check players money from longer distances if you need to

Thanks, I think it works! I have a problem, I can not spawn weapon, nothing happens when I click on the icon, I have the admin rights. What’s wrong?

[editline]30th July 2017[/editline]

Full code:


AddCSLuaFile("shared.lua")

if CLIENT then
SWEP.PrintName = "MonChecker"
SWEP.Category = "Other"
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 63
SWEP.ViewModelFlip = false
SWEP.CSMuzzleFlashes = false
end

SWEP.Spawnable= true
SWEP.AdminSpawnable= true
SWEP.AdminOnly = false
SWEP.Author = "dj-34"
SWEP.Contact = "VK"
SWEP.Purpose = ""
SWEP.Instructions = "Left mouse button."

SWEP.ViewModel = "models/weapons/v_pistol.mdl"
SWEP.WorldModel = "models/weapons/w_pistol.mdl"

SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

SWEP.Slot = 6
SWEP.SlotPos = 1

SWEP.UseHands = false

SWEP.HoldType = "pistol"

SWEP.ReloadSound = ""

SWEP.Base = "weapon_base"

function SWEP:PrimaryAttack()
	local target = self.Owner:GetEyeTrace().Entity
	if target:IsPlayer() then
		print("This player has" .. target:getDarkRPVar( "money" ) .. "money.")
	end
end

surface.CreateFont( "TextFont", {
	font = "Arial",
	size = 16,
	weight = 500, 
} )

function SWEP:HUDPaint()
draw.RoundedBox( 6, ScrW / 2, ScrH / 2, 270, 20, Color( 25, 25, 25, 255 ))
draw.SimpleText("Use LMB", "TextFont", ScrW() / 2, ScrH() / 2, Color(255, 255, 255, 255), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER)
end