Talk:Add-On Creation & Folder Structure

From GMod Wiki

Revision as of 17:24, 13 June 2011 by Erik (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This page is truly incomplete. I'm coming from Roblox lua, and their wiki is terrific. I was able to script anything within a week. But here, learning is quite difficult. Most links refer to either, weapons, game modes, or concommands. You forgot to mention how addons work. I'm going through a list here of things that I do NOT know.

I will give some example code and I will ask some questions in which I cannot find the answer on this wiki.



-- Taken from addons/DarkRP/entities/entities/microwave/init

 
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
 
include("shared.lua")
 
function ENT:Initialize()
	self.Entity:SetModel("models/props/cs_office/microwave.mdl")
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:SetUseType(SIMPLE_USE)
	local phys = self.Entity:GetPhysicsObject()
	if phys and phys:IsValid() then phys:Wake() end
	self.sparking = false
	self.damage = 100
	self.Entity.dt.price = math.Clamp((GetConVarNumber("pricemin") ~= 0 and GetConVarNumber("pricemin")) or 30, (GetConVarNumber("pricecap") ~= 0 and GetConVarNumber("pricecap")) or 30)
end
 
 

1. How does self work? What does self relate to? Is self.Entity essentially ENT?

2. What is ENT? How does it identify the entity?

3. How does this entity spawn?

4. I were to make an addon of let's say "Lava" how could I create an entity that would simulate lava? I understand it would use the hook function, but how do I hook it? I understand how it would check if the entity that hit it is a player and how to kill the player, but how do I add the hook?

5. There is no entities under the folder structure.

6. What is the SVN?

Please answer these questions. I want to create add ons, not silly game modes or weapons. 76561198039615601 10:48, 12 June 2011 (PDT) MrOdysseus


--76561197993138946 05:12, 13 June 2011 (PDT)
1. self is a variable that exists inside ENT functions, it referrs to the entity and it's options. self.Entity is the exact same thing, I don't think anything differs.

2. ENT is a variable that exists in all lua files placed inside a folder inside lua/entities/ folder. You define everything about the entity inside them. You can make your own hooks/functions, like

function ENT:Derp(bla) print(bla) end
function ENT:Think()
self:Derp("test")
end

A list of the default hooks Entity Hooks

3. You create it using "Entity = ents.Create("<entityfoldername")", like, ents.Create("microwave"). It won't exist in the world properly untill you've done Entity:Spawn() first. Entity.Spawn

4. Use the StartTouch hook. ENT.StartTouch See the example in that page.

5. Most entities exists in the addons folder, garrysmod only brings you one entity, the bouncy ball. The rest are made by addon developers.

6. SVN is a repository download program thing. Developers can commit things into the repository, then everyone can just update their SVN folder, the software you use (tortoiseSVN preferably) will look at internet if the developer has made any changes, then update your folder with the changes. http://www.facepunch.com/threads/688324-Divran-s-SVN-Tutorial-Pictures-Included


Thanks! I appreciate the help. There is already a tutorial on how to create an entity of your liking. I just needed to know that it was under gamemode!

Personal tools
Namespaces
Variants
Actions
Navigation
Lua Scripting
Functions
Hooks
Toolbox