Skip to main content

Introduction

Pragma uses the programming language Lua 5.1 (with LuaJIT) for its scripting engine. If you're new to Lua, the PIL is a good starting point.

Any text editor suited for programming (Notepad++, Sublime, Visual Studio Code, etc.) can be used to write Lua scripts, however using the ZeroBrane IDE is highly recommended due to its powerful debugging capabilities specialized for Lua development.

You can find a list of available libraries and classes for Pragma in the API documentation over here.

Tutorials will follow (if there is demand).

 

All Entities

Examples

Respawn all players (serrverside):

for ent in ents.iterator({ents.IteratorFilterComponent(ents.COMPONENT_PLAYER)}) do
	print(ent)local playerC = ent:GetComponent(ents.COMPONENT_PLAYER)
	playerC:Respawn()
end

 Registering a console command

console.register_command("custom_command",function(pl,...)
    if(pl ~= nil) then
		print("Command was initiated by player ",pl:GetEntity():GetName())
    end
    print("Command arguments: ",...)
    
    local arg1,arg2,arg3 = ...
    -- Do something with arguments
end)

Register a console variable and do something on change:

local cvHealth = console.register_variable("player_gravity_factor","1",bit.bor(console.FLAG_BIT_ARCHIVE,console.FLAG_BIT_REPLICATED),"Specifies barney's default health.")

local gravityFactor = cvHealth:GetInt()

console.add_change_callback("player_gravity_factor",function(old,new)

end)

Creating a prop and placing it in front of the player console command +physics

local ent = ents.create_prop()

 

Create a trigger +Touch Event

 

Registering 

a console command

 

 

Creating a GUI element

 

local rect = gui.create("WIRect")
rect:SetColor(Color.Red)
rect:SetPos(Vector(32,32))
rect:SetSize(256,65)

local text = gui.create("WIText",rect)
text:SetColor(Color(0,255,64,255))
text:SetPos(5,5)
text:SetText("Hello World")
text:SizeToContents()

Classes

 

creating an image buffer

 

 

Creating a timer

 

-- Print "Hello" every 2 seconds
local numberOfRepetitions = -1 -- -1 = infinite
local timer = time.create_timer(2.0,numberOfRepetitions,function()
    print("Hello")
end)

-- Remove the timer after 15 seconds using a second timer
time.create_simple_timer(15,function()
    util.remove(timer)
end)

light source -> parent to player

 Turn on flashlight, change intensity and color

3d gui element

 

create zombie

 

RenderComponent

CalcRayIntersection

 

Math examples