The top-library of gEvents, containing every single function and variable possible.
The top-library of gEvents, containing every single function and variable possible.
This table will contain every single event added to the table and its properties. Useful when you wan't to loop through all the events to get their properties.
Returns
The table with the gEvents properties.
It will register the gEvent into the events table, creating a unique ConVar specifically for the gEvent, having the name of the gEvent's ID, and giving it a place in the SpawnMenu. This function is able to detect if theres already a gEvent of the same ID, therefore no gEvent IDs will be repeated.
Fields
The table with the gEvent's properties.
Example Usage
gevents.AddgEvent({
["gEvent Name"] = "Teleportation Party",
["gEvent ID"] = "gevent_event_teleport_party",
["gEvent Description"] = "Players will be randomly teleported around the map.",
["gEvent ChatNotice"] = "A teleportation party has started!",
["gEvent Function"] = function()
if SERVER then
local players = player.GetAll()
for _, ply in pairs(players) do
local randomPos = Vector(math.random(-5000, 5000), math.random(-5000, 5000), 0)
ply:SetPos(randomPos)
end
end
end,
["gEvent CanRun"] = function()
return true
end
})
If the internal conditions of the function are true, the gEvent with said ID will be executed.
[WARNING] When the you're getting a random ID value from the gevents.EventTable to execute an event, keep in mind that theres a possibility that the client & server realms will execute different gEvents.
Fields
The ID of the gEvent to execute.
Returns
Will return true if all the internal conditions we're true.
Example Usage
if SERVER then
util.AddNetworkString("gecl1")
util.AddNetworkString("gecl2")
hook.Add("Think", "gBotsThinkRand", function()
randevent = gevents.EventTable[math.random(1, #gevents.EventTable)]
end)
hook.Add("Initialize", "gEventLoop", function()
timer.Create("gEventCooldown", GetConVar("gevents_cooldown"):GetInt(), 0, function()
print("[gEvents] Execution cooldown complete!")
if GetConVar("gevents_allowed"):GetBool() then
local id
repeat
randevent = gevents.EventTable[math.random(1, #gevents.EventTable)]
id = randevent["gEvent ID"]
until GetConVar(id):GetBool()
gevents.ExecutegEvent(id)
print("[gEvents] Event executed on server! (" .. id .. ")")
net.Start("gecl1")
net.WriteString(id)
net.Broadcast()
end
end)
end)
end
if CLIENT then
net.Receive("gecl1", function()
local id = net.ReadString()
gevents.ExecutegEvent(id)
print("[gEvents] Event executed on client! (" .. id .. ")")
for _, v in ipairs(gevents.EventTable) do
if v["gEvent ID"] == id then
chat.AddText(Color(0, 161, 255), "[gEvents] ", Color(255, 255, 255), v["gEvent ChatNotice"])
end
end
end)
net.Receive("gecl2", function()
local id = net.ReadString()
gevents.ExecutegEvent(id)
print("[gEvents] Event executed on client! (" .. id .. ")")
for _, v in ipairs(gevents.EventTable) do
if v["gEvent ID"] == id then
chat.AddText(Color(0, 161, 255), "[gEvents] ", Color(255, 255, 255), v["gEvent ChatNotice"])
end
end
end)
end
["gEvent Name"] The name of the gEvent.
["gEvent ID"] The ID of the gEvent (In string format).
["gEvent Description"] The description of the gEvent.
["gEvent ChatNotice"] The message to display when the gEvent is executed.
["gEvent Function"] Self explanatory. The function to call when the gEvent is executed.
["gEvent CanRun"] Checks if certain conditions are met before event execution. If it returns false, the gEvent Function can run, else it won't. Useful for gEvents that require certain conditions. (e.g. The gEvent can only be ran on Multiplayer.)