• My lua wont work
    10 replies, posted
Ok, I have made something similar to a moneyprinter and put it into gamemodes/darkrp/gamemodes/entities and added it to the addentities.lua so that it can be bought from the f4 menu. However when I go into singleplayer I get this error message " Folder=entities/drugplant Couldn't register Scripted Entity drugplant - the Type field is empty!" Also when I try to spawn the entity I get this error message "ERROR: GAMEMODE:'PlayerSay' Failed: darkrp\gamemode\main.lua:1129: Tried to use a NULL entity! Error: hook->PlayerSay returned a non-string!" Does anyone know what could be causing this?
We can't tell what is causing the error if we can't see the code.
Ah, ok. I jsut thought that you might be able to get a clue from the error message. Well here's my init.lua: [lua] -- DrugPlant made by BrutalBarnard AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") self.level = 1 -- General stuff function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") -- model self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.damage = 100 -- Health for enity end -- initialise entity function ENT:ontakedamage (dmg) self.damage = self.damage - dmg:getdamage() if self.damage <= 0 then self:destruct() self:remove() end end -- sets when on 0 hpor less that the entity is removed function ENT:Destruct() local vpoint = self:getpos() local effectdata = effectdata() effectdata:setstart(vPoint) effectdata:setorigin(vpoint) effectdata:setscale(1) util.effect("explosion", effectdata) notify(self:getNWEntity("owning_ent"), 1,4, "Your drug plant has died") end -- sets explosion animation and notifies owner of plant death. --function selldirect() -- Set player money((level * 1000)+500) -- ENT:Destruct() --end -- Makes sell function for 1=i,10 do function setlevel(level) self.level = level end wait 18000 then self.level= (level)+1 end -- sets plant level and increases teh plant's level every 3 minutes function menu() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 200, 250 ) DermaPanel:SetTitle( "Drug plant menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaButton = vgui.Create( "Sell" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Sell plant for $"...(level * 1000) +500 ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () sellcash() end local DermaButton = vgui.Create( "Destroy" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Destroy Drug Plant"() DermaButton:SetPos( 25, 100 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ENT:Destruct() end end -- Derma menu function sellcash() local moneybag = ents.Create("prop_physics") moneybag:SetModel("models/props/cs_assault/money.mdl") moneybag.ShareGravgun = true moneybag:SetPos(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15)) moneybag.nodupe = true moneybag:Spawn() moneybag:GetTable().MoneyBag = true amount = ((level * 1000)+500) end moneybag:GetTable().Amount = amount printmore(self) end [/lua]
[noparse][lua][/lua][/noparse] No idea about your problem though.
[QUOTE=Disseminate;19487081][noparse][lua][/lua][/noparse] No idea about your problem though.[/QUOTE] Thanks. Well I figured out one possible issue. "wait" is a console command isn't it, not Lua. I've made a new timer and will test that in a second.
Look further up your console for another error to do with the drugplant entity. Okay, there are several problems with the code. - Be careful, Lua is completely case-sensitive. A lot of those functions you called don't exist because they're in the wrong case. - Some of those functions you defined need to be (eg) ENT:sellcash rather than just sellcash. - That's right, you can't use console commands in Lua just by typing them in. You can execute console commands in Lua, sure, but I know what you're trying to do with that timer and it's not how you do it. - The menu should be in a clientside script. None of the VGUI functions exist serverside, and how is the script supposed to know who's going to open the menu? I could go on and list more problems, but to be honest I don't think you're at the level of making scripted entities. Have a look at the [url=http://wiki.garrysmod.com/?title=Lua_Tutorial_Series]Lua Tutorial Series[/url] and build up your knowledge.
Well I just changed the init.lua to this [lua] -- DrugPlant made by BrutalBarnard AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") self.level = 1 -- General stuff function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") -- model self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.damage = 100 -- Health for enity end -- initialise entity function ENT:ontakedamage (dmg) self.damage = self.damage - dmg:getdamage() if self.damage <= 0 then self:destruct() self:remove() end end -- sets when on 0 hpor less that the entity is removed function ENT:Destruct() local vpoint = self:getpos() local effectdata = effectdata() effectdata:setstart(vPoint) effectdata:setorigin(vpoint) effectdata:setscale(1) util.effect("explosion", effectdata) notify(self:getNWEntity("owning_ent"), 1,4, "Your drug plant has died") end -- sets explosion animation and notifies owner of plant death. --function selldirect() -- Set player money((level * 1000)+500) -- ENT:Destruct() --end -- Makes sell function function setlevel() self.level = (self.level) + 1 end for i=1, 7 do simple.timer(180, setlevel) end -- sets plant level and increases the plant's level every 3 minutes up to a maximum of 7 times. Max level 8 function menu() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 200, 250 ) DermaPanel:SetTitle( "Drug plant menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaButton = vgui.Create( "Sell" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Sell plant for $" ... (level * 1000) +500 ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () sellcash() end local DermaButton = vgui.Create( "Destroy" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Destroy Drug Plant"() DermaButton:SetPos( 25, 100 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ENT:Destruct() end end -- Derma menu function sellcash() local moneybag = ents.Create("prop_physics") moneybag:SetModel("models/props/cs_assault/money.mdl") moneybag.ShareGravgun = true moneybag:SetPos(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15)) moneybag.nodupe = true moneybag:Spawn() moneybag:GetTable().MoneyBag = true amount = ((self.level * 1000)+500) end moneybag:GetTable().Amount = amount printmore(self) end [/lua] And I got this error message "entities/drugplant/init.lua:76: ')' expected near '...'"
[lua] -- DrugPlant made by BrutalBarnard AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") ENT.level = 1 -- General stuff function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") -- model self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.damage = 100 -- Health for enity timer.Create( self:EntIndex() .. "LevelTimer", 180, 7, self.setlevel, self ); end -- initialise entity function ENT:OnTakeDamage(dmg) self.damage = self.damage - dmg:GetDamage() if self.damage <= 0 then self:Destruct() self:Remove() end end -- sets when on 0 hpor less that the entity is removed function ENT:Destruct() local vpoint = self:GetPos() local effectdata = EffectData() effectdata:SetStart(vpoint) effectdata:SetOrigin(vpoint) effectdata:SetScale(1) util.Effect("explosion", effectdata) self:GetNWEntity("owning_ent"):PrintMessage( 3, "Your drug plant has died" ) end -- sets explosion animation and notifies owner of plant death. --function selldirect() -- Set player money((level * 1000)+500) -- ENT:Destruct() --end -- Makes sell function function ENT:setlevel() self.level = self.level + 1 end --[[ Everything to do with derma should be in cl_init or shared on the client. Not fixing any of this right now function menu() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 200, 250 ) DermaPanel:SetTitle( "Drug plant menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaButton = vgui.Create( "Sell" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Sell plant for $" ... (level * 1000) +500 ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () sellcash() end local DermaButton = vgui.Create( "Destroy" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Destroy Drug Plant"() DermaButton:SetPos( 25, 100 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ENT:Destruct() end end -- Derma menu --]] function sellcash() local moneybag = ents.Create("prop_physics") moneybag:SetModel("models/props/cs_assault/money.mdl") moneybag.ShareGravgun = true moneybag:SetPos(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15)) moneybag.nodupe = true moneybag:Spawn() --[[ What's this supposed to do? The code's too mangled for me to read. moneybag:GetTable().MoneyBag = true amount = ((self.level * 1000)+500) end moneybag:GetTable().Amount = amount --]] --What are you trying to do with "printmore"? --printmore(self) end [/lua] Capitalization/function errors, mangled code.
Ok, so do I put the derma stuff in the cl_init? Also as for the printmore, I was looking at the moneyprinter code and tried to modify that section so that it would work here. However it seems not to have. How would you give money to the player? Is there a way to directly give it to them into their wallet or would I have to print the money? This is for DarkRP by the way.
Beats me, never glanced at darkRP
Ok, so I've changed it and this is what I have now. The entity spawns, but it doesn't do anything. Also I get a console error "entities/drugplant/init.lua:56: attempt to call field 'simple' (a nil value)" The drug plant is supposed to be start at level 1 and every 3 minutes get up a rank. Every rank makes the plant sell for $1000 when it is sold via the derma menu. However it does nothing. What can I do with the derma to make it work? Put it in cl_init? Also the entity is indestructible, whereas I'm trying to make it autodestruct when it takes more than 100 damage. Here's my updated code. [lua] -- DrugPlant made by BrutalBarnard AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") self={} self.level = 1 -- General stuff function ENT:Initialize() self:SetModel("models/props_c17/consolebox01a.mdl") -- model self:PhysicsInit(SOLID_VPHYSICS) self:SetMoveType(MOVETYPE_VPHYSICS) self:SetSolid(SOLID_VPHYSICS) local phys = self:GetPhysicsObject() if phys:IsValid() then phys:Wake() end self.damage = 100 -- Health for enity end -- initialise entity function ENT:ontakedamage (dmg) self.damage = self.damage - dmg:getdamage() if self.damage <= 0 then self:destruct() self:remove() end end -- sets when on 0 hpor less that the entity is removed function ENT:Destruct() local vpoint = self:getpos() local effectdata = effectdata() effectdata:setstart(vPoint) effectdata:setorigin(vpoint) effectdata:setscale(1) util.effect("explosion", effectdata) notify(self:getNWEntity("owning_ent"), 1,4, "Your drug plant has died") end -- sets explosion animation and notifies owner of plant death. --function selldirect() -- Set player money((level * 1000)+500) -- ENT:Destruct() --end -- Makes sell function function setlevel() self.level = (self.level) + 1 end for i=1, 7 do timer.simple(180, setlevel) end -- sets plant level and increases the plant's level every 3 minutes up to a maximum of 7 times. Max level 8 function menu() local DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 50,50 ) DermaPanel:SetSize( 200, 250 ) DermaPanel:SetTitle( "Drug plant menu" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetMouseInputEnabled(true) DermaPanel:SetKeyboardInputEnabled(true) DermaPanel:MakePopup() local DermaButton = vgui.Create( "Sell" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Sell plant for $" .. (level * 1000) +500 ) DermaButton:SetPos( 25, 50 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () sellcash() end local DermaButton = vgui.Create( "Destroy" ) DermaButton:SetParent( DermaPanel ) DermaButton:SetText( "Destroy Drug Plant")() DermaButton:SetPos( 25, 100 ) DermaButton:SetSize( 150, 50 ) DermaButton.DoClick = function () ENT:Destruct() end end -- Derma menu function sellcash() local moneybag = ents.Create("prop_physics") moneybag:SetModel("models/props/cs_assault/money.mdl") moneybag.ShareGravgun = true moneybag:SetPos(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15)) moneybag.nodupe = true moneybag:Spawn() amount = ((self.level * 1000)+500) end [/lua] Here is something which is similar which I want to make. This creates money every so often and occasionally sets fire and explodes. Maybe I can adapt the moneyprinting method to my purpose? I don't really understand lines 68 to 88 which is what I need. [lua] -- RRPX Money Printer reworked for DarkRP by philxyz AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") 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() if phys:IsValid() then phys:Wake() end self.sparking = false self.damage = 100 self.IsMoneyPrinter = true timer.Simple(30, self.CreateMoneybag, self) end function ENT:OnTakeDamage(dmg) if self.burningup then return end self.damage = self.damage - 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) Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your money printer has exploded!") end function ENT:BurstIntoFlames() Notify(self:GetNWEntity("owning_ent"), 1, 4, "Your money printer is overheating!") self.burningup = true local burntime = math.random(8, 18) self:Ignite(burntime, 0) timer.Simple(burntime, self.Fireball, self) end function ENT:Fireball() 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.IsMoneyPrinter then v:Ignite(math.random(5, 22), 0) end end self:Remove() end local function PrintMore(ent) if ValidEntity(ent) then ent.sparking = true timer.Simple(3, ent.CreateMoneybag, ent) end end function ENT:CreateMoneybag() if not ValidEntity(self) then return end if self:IsOnFire() then return end local MoneyPos = self:GetPos() if math.random(1, 22) == 3 then self:BurstIntoFlames() end local moneybag = ents.Create("prop_physics") moneybag:SetModel("models/props/cs_assault/money.mdl") moneybag.ShareGravgun = true moneybag:SetPos(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15)) moneybag.nodupe = true moneybag:Spawn() moneybag:GetTable().MoneyBag = true local amount = GetGlobalInt("mprintamount") if amount == 0 then amount = 250 end moneybag:GetTable().Amount = amount self.sparking = false timer.Simple(math.random(100, 350), PrintMore, self) end function ENT:Think() 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) end [/lua]
Sorry, you need to Log In to post a reply to this thread.