When I declare something like self.myoptionhere in init.lua I want to be able to use this in cl_init.lua. Now when ever i call self.myoptionhere in cl_init.lua it says that I am calling a null value. Any help would be much appreciated.
Thanks!
What is self?
[QUOTE=zzaacckk;40321657]What is self?[/QUOTE]
When I self I think it means its talking about the entity itself.
init.lua:
[LUA]-- RRPX Money Printer reworked for DarkRP by philxyz
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
ENT.SeizeReward = 950
local PrintMore
local UpgradeDelay = 1
local PrinterLevel = 1
function ENT:Initialize()
self:SetModel("models/props_c17/consolebox01a.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
phys:Wake()
self.sparking = false
self.damage = 100
self.IsMoneyPrinter = true
self.PrinterLevel = 1
self.firstclick = false
timer.Simple(math.random((100 / self.PrinterLevel) + 10,(350 / self.PrinterLevel) + 10), function() PrintMore(self) end)
end
function ENT:OnTakeDamage(dmg)
if self.burningup then return end
self.damage = (self.damage or 100) - dmg:GetDamage()
if self.damage <= 0 then
local rnd = math.random(1, 10)
if rnd < 3 then
self:BurstIntoFlames()
else
self:Destruct()
self:Remove()
end
end
end
function ENT:Destruct()
local vPoint = self:GetPos()
local effectdata = EffectData()
effectdata:SetStart(vPoint)
effectdata:SetOrigin(vPoint)
effectdata:SetScale(1)
util.Effect("Explosion", effectdata)
GAMEMODE:Notify(self:Getowning_ent(), 1, 4, "Your money printer has exploded!")
end
function ENT:BurstIntoFlames()
GAMEMODE:Notify(self:Getowning_ent(), 0, 4, "Your money printer is overheating!")
self.burningup = true
local burntime = math.random(8, 18)
self:Ignite(burntime, 0)
timer.Simple(burntime, function() self:Fireball() end)
end
function ENT:Fireball()
if not self:IsOnFire() then self.burningup = false return end
local dist = math.random(20, 280) -- Explosion radius
self:Destruct()
for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do
if not v:IsPlayer() and not v:IsWeapon() and v:GetClass() ~= "predicted_viewmodel" and not v.IsMoneyPrinter then
v:Ignite(math.random(5, 22), 0)
elseif v:IsPlayer() then
local distance = v:GetPos():Distance(self:GetPos())
v:TakeDamage(distance / dist * 100, self, self)
end
end
self:Remove()
end
PrintMore = function(ent)
if not IsValid(ent) then return end
ent.sparking = true
timer.Simple(3, function()
if not IsValid(ent) then return end
ent:CreateMoneybag()
end)
end
function ENT:CreateMoneybag()
local BaseNumber = 250
if not IsValid(self) or self:IsOnFire() then return end
local MoneyPos = self:GetPos()
if math.random(1, (22 * self.PrinterLevel)) == 3 then self:BurstIntoFlames() end
local amount = 250
if amount == 0 then
amount = 250
end
if self.PrinterLevel == 1 then
amount = BaseNumber * 1
end
if self.PrinterLevel == 2 then
amount = BaseNumber * 1.5
end
if self.PrinterLevel == 3 then
amount = BaseNumber * 2.3
end
if self.PrinterLevel == 4 then
amount = BaseNumber * 3.1
end
if self.PrinterLevel == 5 then
amount = BaseNumber * 4.2
end
DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount)
self.sparking = false
timer.Simple(math.random((100 / self.PrinterLevel), (350 / self.PrinterLevel)), function() PrintMore(self) end)
end
function ENT:Use( activator, caller )
local UpgradeCost = 5000 * self.PrinterLevel + (self.PrinterLevel * 50)
if !IsValid( activator ) then
return
end
if activator.NextUpgradeTime == nil then
activator.NextUpgradeTime = 3
end
if CurTime() < activator.NextUpgradeTime then
return
end
activator.NextUpgradeTime = CurTime() + UpgradeDelay
self.firstclick = !self.firstclick
if self.PrinterLevel >= 5 then
GAMEMODE:Notify(activator, 0, 4, "Your printer is maximum upgrade!")
return
end
if self.firstclick == true then
activator:PrintMessage( HUD_PRINTTALK, "Upgrade Details: Upgrading to level: " .. self.PrinterLevel + 1 .. " for $" .. UpgradeCost .. ". Use your printer again to confirm.")
GAMEMODE:Notify(activator, 0, 4, "You initiated a upgrade! Use your printer again to confirm.")
return
end
if !activator:CanAfford(UpgradeCost) then
activator:PrintMessage( HUD_PRINTTALK, "Upgrade Details: You can't afford to buy level " .. self.PrinterLevel + 1 .. ".")
GAMEMODE:Notify(activator, 0, 4, "You cannot afford level " .. self.PrinterLevel + 1 .. ".")
return
end
self:EmitSound("items/spawn_item.wav", 85, 100)
activator:AddMoney(-UpgradeCost)
self.PrinterLevel = self.PrinterLevel + 1
activator:PrintMessage( HUD_PRINTTALK, "Upgrade Details: Upgraded to level: " .. self.PrinterLevel)
GAMEMODE:Notify(self:Getowning_ent(), 0, 4, "Printer Upgraded! Now level " .. self.PrinterLevel .. ".")
end
function ENT:Think()
if self:WaterLevel() > 0 then
self:Destruct()
self:Remove()
return
end
if not self.sparking then return end
local effectdata = EffectData()
effectdata:SetOrigin(self:GetPos())
effectdata:SetMagnitude(1)
effectdata:SetScale(1)
effectdata:SetRadius(2)
util.Effect("Sparks", effectdata)
local effectdata2 = EffectData()
effectdata2:SetOrigin(self:GetPos())
effectdata2:SetMagnitude(1)
effectdata2:SetScale(1)
effectdata2:SetRadius(2)
util.Effect("PrintUpgrade", effectdata2)
end
[/LUA]
cl_init.lua:
[LUA]include("shared.lua")
function ENT:Initialize()
end
function ENT:Draw()
self:DrawModel()
local Pos = self:GetPos()
local Ang = self:GetAngles()
local owner = self:Getowning_ent()
owner = (IsValid(owner) and owner:Nick()) or "unknown"
surface.SetFont("HUDNumber5")
local TextWidth = surface.GetTextSize("Money printer")
local TextWidth2 = surface.GetTextSize(owner)
local TextWidth3 = surface.GetTextSize("Press 'E' to upgrade!")
Ang:RotateAroundAxis(Ang:Up(), 90)
cam.Start3D2D(Pos + Ang:Up() * 11.5, Ang, 0.11)
draw.WordBox(2, -TextWidth3*0.5, -78, "Press 'E' to upgrade!", "HUDNumber5", Color(0, 0, 0, 100), Color(255,255,255,255))
draw.WordBox(2, -TextWidth*0.5, -30, "Money printer", "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
draw.WordBox(2, -TextWidth2*0.5, 18, owner, "HUDNumber5", Color(140, 0, 0, 100), Color(255,255,255,255))
cam.End3D2D()
end
--[[usermessage.Hook( "PrinterUpgradeMenu", function ()
local DermaPanel = vgui.Create( "DFrame" )
DermaPanel:SetPos( 50,50 )
DermaPanel:SetSize( 350, 150 )
DermaPanel:SetTitle( "Money Printer Upgrade Menu" )
DermaPanel:SetVisible( true )
DermaPanel:SetDraggable( true )
DermaPanel:ShowCloseButton( false )
DermaPanel:Center()
DermaPanel:MakePopup()
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel )
DermaButton:SetText( "Upgrade" )
DermaButton:SetPos( 185, 115 )
DermaButton:SetSize( 70, 25 )
DermaButton.DoClick = function ()
DermaPanel:Remove()
end
local DermaButton = vgui.Create( "DButton" )
DermaButton:SetParent( DermaPanel )
DermaButton:SetText( "Close" )
DermaButton:SetPos( 265, 115 )
DermaButton:SetSize( 70, 25 )
DermaButton.DoClick = function ()
DermaPanel:Remove()
end
local myLabel = vgui.Create("DLabel", DermaPanel)
myLabel:SetPos(86,40)
myLabel:SetColor(Color(255,255,255,255))
myLabel:SetFont("default")
myLabel:SetText("Upgrade to level nil" .. " for $nil")
myLabel:SizeToContents()
local myLabel = vgui.Create("DLabel", DermaPanel)
myLabel:SetPos(275,5)
myLabel:SetColor(Color(255,255,255,255))
myLabel:SetFont("default")
myLabel:SetText("Level: nil")
myLabel:SizeToContents()
end );
function ENT:Think()
end]]
[/LUA]
Alright if you are going to script for garrysmod you have to understand this one basic concept.
Imagine a wall between clientside (cl_init.lua) and serverside (init.lua). Now you cant walk through this "wall" unless you have special tools for the job. There are many ways to get through the wall , but you cannot just walk back and forth willy nilly. Say someone living on the server side of the wall wants to talk to someone on the client side of the wall, that person couldn't yell through because it's soundproof. So they decide to write a letter (net, usmg, networkedentity, etc), and they send it via mail carrier (the internet). In essence shit doesn't magically get from your computer to the server. And just because one side of the wall has a steak n shake doesnt mean your side does too. Which is a bloody shame.
[QUOTE=Ludicium;40322001]Alright if you are going to script for garrysmod you have to understand this one basic concept.
Imagine a wall between clientside (cl_init.lua) and serverside (init.lua). Now you cant walk through this "wall" unless you have special tools for the job. There are many ways to get through the wall , but you cannot just walk back and forth willy nilly. Say someone living on the server side of the wall wants to talk to someone on the client side of the wall, that person couldn't yell through because it's soundproof. So they decide to write a letter (net, usmg, networkedentity, etc), and they send it via mail carrier (the internet). In essence shit doesn't magically get from your computer to the server. And just because one side of the wall has a steak n shake doesnt mean your side does too. Which is a bloody shame.[/QUOTE]
Thanks man, that was very informative. I thank you for this.
Sorry, you need to Log In to post a reply to this thread.