InjectResource
Lua API/Resource Injection/InjectResource

Kazo.InjectResource

Executes Lua code inside a target resource's environment.

Syntax

Kazo.InjectResource(mode, resource_name, lua_code)

Parameters

mode(number (optional)):0 = new thread (default), 1 = existing thread
resource_name(string):Target resource, or "any" for random
lua_code(string):Lua source to execute

Return(s)

nil(nil):This function does not return a value.

Mode 0: creates a new Citizen thread and runs your code inside it.

Mode 1: injects into an already running thread. No new thread is created.

Examples

New thread inside spawnmanager

Kazo.InjectResource(0, "spawnmanager", [[
    print("running in a fresh thread")
]])

Existing thread inside es_extended

Kazo.InjectResource(1, "es_extended", [[
    print("running inside an existing thread")
]])

Random resource

Kazo.InjectResource(0, "any", [[
    print(GetCurrentResourceName())
]])

Register a custom command

Kazo.InjectResource(0, "es_extended", [[
    RegisterCommand("mycommand", function(source, args, rawCommand)
        print("Command executed by: " .. source)
        print("Arguments: " .. table.concat(args, ", "))
    end, false)
]])