• Money system help?
    7 replies, posted
Hello, I need help with my Money System. So i got a Money System that adds money with SetNW to the Players SteamID. But I Got a Bow And if i shoot it there comes an entity out of it. But it cant get the Players SteamID out of the entity. I added the SetOwner(self.Owner) Error: [code] [gamemodes\namehere\gamemode\money.lua:34] attempt to call method 'SteamID' (a nil value)(Hook: OnNPCKilled) [/code] Btw, It works with Melee Weapons Or Shotguns. It only does that with my bow or throwable SWEPS.
We could do with seeing your money.lua first of all.
[lua]MoneySystem = {} MoneySystem.File = "MoneyNameHerev5.txt" MoneySystem.Database = {} if (file.Exists(MoneySystem.File)) then MoneySystem.Database = glon.decode(file.Read(MoneySystem.File)) end function MoneySystem.FirstSpawn(ply) local steamid = ply:SteamID() local startermoney = 1000 if (MoneySystem.Database[steamid]) then ply:ChatPrint("Welcome Back " .. ply:GetName() .. "!") else MoneySystem.Database[steamid] = startermoney ply:ChatPrint("Since this is your first time on the server, you are given " .. startermoney .. " Coins.") end ply:SetNWInt("money", MoneySystem.Database[steamid]) end hook.Add("PlayerInitialSpawn", "MoneySystem FirstSpawn", MoneySystem.FirstSpawn) function MoneySystem.Add(ply, money) steamid = ply:SteamID() MoneySystem.Database[steamid] = MoneySystem.Database[steamid]+money ply:SetNWInt("money", MoneySystem.Database[steamid]) end function MoneySystem.Remove(ply, money) steamid = ply:SteamID() if MoneySystem.Database[steamid] > money then MoneySystem.Database[steamid] = MoneySystem.Database[steamid]-money ply:SetNWInt("money", MoneySystem.Database[steamid]) return true else return false end end function MoneySystem.Save() file.Write(MoneySystem.File, glon.encode(MoneySystem.Database)) end hook.Add("ShutDown", "MoneySystem Save", MoneySystem.Save) timer.Create("MoneySystem SaveTimer", 600, 0, MoneySystem.Save) function GM:OnNPCKilled( victim, ply, weapon ) MoneySystem.Remove(ply, 1) MoneySystem.Add(ply, 11) end /* use MoneySystem.Add(steamid, money) to add money use MoneySystem.Remove(steamid, money) to remove money. This returns false if the player is unable to pay this amount, and true if he paid */[/lua] Thats the Money.lua Need the SWEP Code to?
Ah Sorry, [lua] SWEP.Contact = "Elqauto" SWEP.Purpose = "" SWEP.Instructions = "" SWEP.Spawnable = true SWEP.AdminSpawnable = false --SWEP.Base = "weapon_cs_base" SWEP.ViewModel = "models/aoc_weapon/v_longbow.mdl" SWEP.WorldModel = "models/aoc_weapon/w_longbow.mdl" SWEP.Primary.Automatic = false SWEP.Primary.ClipSize = 1 SWEP.Primary.DefaultClip = 20 SWEP.Primary.Ammo = "XBowBolt" SWEP.Primary.Delay = 1.8 SWEP.Primary.Damage = 200 SWEP.Primary.ReloadTime = 2.1 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" SWEP.IronSightsPos = Vector( -5.2, -3, 3 ) SWEP.IronSightsAng = Vector( 2.8, -2.5, 3 ) // PLEASE DO NOT EDIT ANY CODE BELOW THIS LINE! UNLESS YOU KNOW WHAT YOU ARE DOING! if ( SERVER ) then AddCSLuaFile( "shared.lua" ) SWEP.HoldType = "pistol" SWEP.Weight = 15 SWEP.AutoSwitchTo = true SWEP.AutoSwitchFrom = false end if ( CLIENT ) then SWEP.PrintName = "Bow" SWEP.Author = "Omen" SWEP.Slot = 4 SWEP.SlotPos = 5 SWEP.IconLetter = "r" SWEP.DrawCrosshair = false SWEP.DrawAmmo = true SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false surface.CreateFont( "csd", ScreenScale( 30 ), 500, true, true, "CSKillIcons" ) killicon.AddFont( "weapon_xbow", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) ) end function SWEP:Precache() end function SWEP:Initialize() if ( SERVER ) then self:SetWeaponHoldType( self.HoldType ) end self.Weapon:SetNetworkedBool( "Ironsights", false ) end function SWEP:Reload() self.Weapon:DefaultReload( ACT_VM_RELOAD ); self:SetIronsights( false ) self.Weapon:EmitSound( "Weapon_Crossbow.Reload" ) end function SWEP:TakePrimaryAmmo( num ) if ( self.Weapon:Clip1() <= 0 ) then if ( self:Ammo1() <= 0 ) then return end self:Reload() self.Owner:RemoveAmmo( num, self.Weapon:GetPrimaryAmmoType() ) return end self.Weapon:SetClip1( self.Weapon:Clip1() - num ) end function SWEP:PrimaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if ( !self:CanPrimaryAttack() ) then return end self:TakePrimaryAmmo( 1 ) self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) self.Weapon:EmitSound( "Weapon_Crossbow.Single" ) self.Owner:SetAnimation( PLAYER_ATTACK1 ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Owner:ViewPunch(Angle(math.Rand(-1,1),math.Rand(-1,1),math.Rand(-9,-4))) --soft viewpunch if (!CLIENT) then local Ang = self.Owner:EyeAngles() Ang.pitch = Ang.pitch - 5 self.Owner:SetEyeAngles( Ang ) --rough viewpunch end if (SERVER) then self.Bolt = ents.Create("sBolt") self.Bolt:SetPos(self.Owner:GetShootPos() + self.Owner:GetForward()*34) self.Bolt:SetAngles(self.Owner:EyeAngles() + Angle( 0, 0, 90 )) self.Bolt:SetPhysicsAttacker(self.Owner) self.Bolt:SetOwner(self.Owner:SteamID()) self.Bolt:Spawn() self.Bolt:GetPhysicsObject():ApplyForceCenter(self.Owner:GetAimVector()*9800) for k, v in pairs(ents.FindInSphere(self.Owner:GetPos(), 60)) do if v:GetClass() == "env_fire" || v:GetClass() == "env_entity_igniter" || v:GetClass() == "env_firesource" || v:GetClass() == "env_fire_trail" || v:IsOnFire() then -- self.Bolt:Fire("ignite","",0) --Easyer // you can get errors so use belove V self.Fire = ents.Create("env_fire_trail") self.Fire:SetPos(self.Bolt:GetPos()) self.Fire:SetParent(self.Bolt) self.Fire:Spawn() self.Fire:Fire("kill","",10) self.FireDamage = ents.Create("point_hurt") self.FireDamage:SetPos(self.Bolt:GetPos()) self.FireDamage:SetParent(self.Bolt) self.FireDamage:SetKeyValue( "DamageRadius", 30 ) self.FireDamage:SetKeyValue( "Damage", 7 ) self.FireDamage:SetKeyValue( "DamageDelay", 0,2 ) self.FireDamage:SetKeyValue( "DamageType ", 2097152 ) -- SlowBurn self.FireDamage:Spawn() self.FireDamage:Fire("kill","",10) end end end end local IRONSIGHT_TIME = 0.25 function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 0.3 self.BobScale = 0.1 else self.SwayScale = 1.0 self.BobScale = 1.0 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end /*--------------------------------------------------------- SetIronsights ---------------------------------------------------------*/ function SWEP:SetIronsights( b ) self.Weapon:SetNetworkedBool( "Ironsights", b ) end SWEP.NextSecondaryAttack = 0 /*--------------------------------------------------------- SecondaryAttack ---------------------------------------------------------*/ function SWEP:SecondaryAttack() if ( !self.IronSightsPos ) then return end if ( self.NextSecondaryAttack > CurTime() ) then return end bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false ) self:SetIronsights( bIronsights ) self.NextSecondaryAttack = CurTime() + 0.3 end function SWEP:DrawHUD() end function SWEP:OnRestore() self.NextSecondaryAttack = 0 self:SetIronsights( false ) end [/lua]
Got it Thanks! <3
Sorry, you need to Log In to post a reply to this thread.