• I've completed the main Lua tutorial on the basics, where now? :s
    82 replies, posted
[QUOTE=Ninel;29465391]Is there a difference between print and Msg("") in GMod lua i.e. will they appear any different when they are ran?[/QUOTE] Msg is colored depending whether it's run on client or server. It only takes one argument (?), print takes a variable number of arguments and concatenates them together with a tab as separator. Msg doesn't print a newline automatically.
[QUOTE=raBBish;29465522]It only takes one argument (?)[/QUOTE] Nope its the same as print in that respect
[QUOTE=King Flawless;29465953]Nope its the same as print in that respect[/QUOTE] Just tested, it accepts multiple arguments, but they're concatenated together without a separator.
function Msg(...) print(...) end -> Here, working Msg in lua. Actually you might want to download lua for windows, for testing things like math (minus all functions from GLua), using LuaSockets etc. Good for learning.
If someone doesn't mind downloading this and checking it out; [url]http://www.gamefront.com/files/20278151/friendly_baby.zip[/url] . It's an entity I coded which is supposed to be a baby which explodes and kills the player when it is used, I coded this as I asked an experienced coder to set a task on steam and this was his task. When I go into GMod the entity simply does not show up in the menu, I have also tried with a shared.lua file, but it didn't work either.
Post the code in lua tags I can't be fucked to download the file
Ok; init.lua: [code]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) function ENT:Initialize() self:SetModel( "models/props_c17/doll01.mdl" ) self:PhysicsInit( SOLID_VPHYSICS ) self:SetMoveType( MOVETYPE_PHYSICS ) self:SetSolid( SOLID_VPHYSICS ) local phys = self:GetPhysicsObject() if (phys:IsValid()) then phys:Wake end end function ENT:Use( activator, caller ) self.Entity:Remove() local EntityPos = self:GetPos() if (activator:IsPlayer()) then EffectData:SetOrigin( EntityPos ) EffectData:SetScale( 1 ) util.Effect( "Explosion", EffectData) Player.Kill end end function ENT:Think() end[/code] cl_init.lua: [code]include('shared.lua') function ENT:Draw() self:DrawModel() end[/code] info.txt: [code]"AddonInfo" { "name" "friendly_baby" "version" "1.0" "up_date" "" "author_name" "Ninel" "author_email" "example@hotmail.co.uk" "author_url" "" "info" "Training task for Ninel" "override" "0" }[/code] Thanks, Ninel
You have no spawn function.....
Good point, would this effect it showing up in the entities menu though? Also, where can I find the entity functions on the wiki or the page for the spawn function on the wiki? (I'm not sure how to implement it into the script, sorry).
[url]http://luabin.overvprojects.nl/?path=/lua/entities/sent_ball/[/url] look at that
[QUOTE=Ninel;29465172]I tried Msg("Message") in the demo and it didn't work.[/QUOTE] Bit late on this, but in general uppercase functions are GMod Lua functions and do not exist in standard Lua. Lowercase functions are (in general) standard Lua functions.
Ok, the entity still wont work, but there have been some mistakes which I have updated thanks to SweenyPaul; init.lua [code]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') function ENT:Initialize() self.Entity:SetModel( "models/props_c17/doll01.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end function ENT:SpawnFunction(ply, tr)//This is a standerd spawn function, you will mostly always use this if ( !tr.Hit ) then return end //checks if theres something in front of you, if there isnt dont spawn local SpawnPos = tr.HitPos + tr.HitNormal * 16 //creates a variable of the spawn position local ent = ents.Create("friendly_baby") //creates the entity ent:SetPos(SpawnPos) //Sets the spawn pos at the variable set eairler ent:Spawn() //spawn it ent:Activate() //activates it return ent //returns the entity spawned end function ENT:Use( activator, caller ) local EntityPos = self.Entity:GetPos() if (activator:IsPlayer()) then EffectData:SetOrigin( EntityPos ) EffectData:SetScale( 1 ) util.Effect( "Explosion", EffectData) activator:Kill() self.Entity:Remove() end end function ENT:Think() end[/code] shared.lua [code]ENT.Base = "base_anim" ENT.Type = "anim" ENT.Category = "Test" ENT.PrintName = "friendly_baby" ENT.Author = "Ninel" ENT.Contact = "" ENT.Purpose = "friendly_baby" ENT.Instructions = "" ENT.Spawnable = true ENT.AdminSpawnable = true[/code] The info.txt remains the same, however the cl_init.lua has been removed and the shared.lua which is just above has been added. The files are in this order: -Addons -friendly_baby (info.txt) -lua -entities -friendly_baby (init.lua and shared.lua)
Bump.
You need a cl_init.lua to draw the model. Use Ricky's Example SENT.
[QUOTE=cis.joshb;29566508]You need a cl_init.lua to draw the model. Use Ricky's Example SENT.[/QUOTE] Is that the problem? SweenyPaul sent me an example SENT himself and it didn't require a cl_init.lua
This works: init.lua [Lua] AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) function ENT:Initialize() self.Entity:SetModel( "models/props_c17/doll01.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) self.Entity:SetSolid( SOLID_VPHYSICS ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end end function ENT:SpawnFunction(ply, tr)//This is a standerd spawn function, you will mostly always use this if ( !tr.Hit ) then return end //checks if theres something in front of you, if there isnt dont spawn local SpawnPos = tr.HitPos + tr.HitNormal * 16 //creates a variable of the spawn position local ent = ents.Create("friendly_baby") //creates the entity ent:SetPos(SpawnPos) //Sets the spawn pos at the variable set eairler ent:Spawn() //spawn it ent:Activate() //activates it return ent //returns the entity spawned end function ENT:Use( activator, caller ) local EntityPos = self.Entity:GetPos() if (activator:IsPlayer()) then local effectdata = EffectData() effectdata:SetStart( self.Entity:GetPos()) effectdata:SetOrigin(self.Entity:GetPos()) util.Effect( "Explosion", effectdata ) activator:Kill() end self.Entity:Remove() end [/Lua] shared.lua [Lua] ENT.Base = "base_anim" ENT.Type = "anim" ENT.Category = "Test" ENT.PrintName = "friendly_baby" ENT.Author = "Ninel" ENT.Contact = "" ENT.Purpose = "friendly_baby" ENT.Instructions = "" ENT.Spawnable = true ENT.AdminSpawnable = true [/Lua] the cl_init.lua is not needed unless you want to add a outline effect or something else, it defaults to drawn itself if not added
It still doesn't work, I've pasted in the code you showed there SweeneyPaul and it doesn't work :s [editline]2nd May 2011[/editline] SweeneyPaul has helped me fix it over Steam, thank you ;)
Errors?
[QUOTE=Ninel;29573050]SweeneyPaul has helped me fix it over Steam, thank you ;)[/QUOTE]
Ok, this method seems good. If I'm set a task to code something I can learn from it. So, can anyone assign me a coding task (not too hard) which they think I may learn from i.e. gamemode, entity, weapon or whatever? Thanks, Ninel
Add me if you like
[QUOTE=King Flawless;29594537]Add me if you like[/QUOTE] Done, thank you.
Make an entity with a derma menu with options to kill you, heal you, explode etc.
Sorry, you need to Log In to post a reply to this thread.