Lua Scripting Engine with Advanced GTA-Style AI
Renderon Engine provides a powerful Lua scripting environment integrated with a sophisticated AI system inspired by GTA's living world mechanics. Create immersive open-world experiences with autonomous NPCs, dynamic traffic, police systems, daily schedules, and complex pathfinding â all without touching C++.
This documentation covers 100+ API functions across multiple systems including physics, input handling, NPC behavior, crime simulation, and advanced navigation.
Essential Functions for Game Logic
GetDeltaTime()
GetTime()
StartTimer(name)
GetTimer(name)
IsKeyDown(key)
IsMouseButton(button)
GetMousePos()
GetMouseDelta()
LockMouse(locked)
SetMousePos(x, y)
SetPosition(x, y, z)
GetPosition()
Translate(x, y, z)
SetRotation(x, y, z)
GetRotation()
Rotate(x, y, z)
LookAt(x, y, z)
SetScale(x, y, z)
GetScale()
SetVelocity(x, y, z)
GetVelocity()
AddForce(x, y, z)
SetGravity(enabled)
IsGrounded()
SetColor(r, g, b)
GetColor()
PlayAnim(name)
StopAnim()
SetAnimSpeed(speed)
PlayAudio(filepath)
PlayAudioLoop(filepath)
StopAudio()
Destroy()
FindEntity(tag)
GetEntityPosition(entityID)
GetDistance(x1, y1, z1, x2, y2, z2)
Lerp(a, b, t)
Clamp(value, min, max)
Random() or Random(min, max)
Sin(angle) / Cos(angle)
Abs(value) / Sqrt(value)
GetCameraPosition()
GetDeltaTime() to ensure frame-rate independent gameplay. For example: Translate(speed * GetDeltaTime(), 0, 0)
Personality-Driven Autonomous Characters
SetNPCType(type)
SetNPCPersonality(aggression, fear, courage)
SetNPCAnimations(idle, walk, run, attack, death)
SetNPCSpeed(walkSpeed, runSpeed)
SetNPCStats(health, vision, hearing)
SetNPCState(state)
GetNPCState()
SetNPCDestination(x, y, z)
SetNPCTarget(entityID)
NPCDamage(amount)
GetNPCHealth()
FindNearestEntity(tag, range)
Living World Mechanics & Advanced AI
AddDailyActivity(name, startHour, endHour, x, y, z)
ReportCrime(x, y, z, severity)
HasSeenPolice()
MakeFriend(entityID)
MoveTo(x, y, z)
| Severity | Crime Type | Police Response | Witness Reaction |
|---|---|---|---|
| 1 - Minor | Jaywalking, Trespassing, Speeding | 1 patrol car (delayed) | Ignore or mild concern |
| 2 - Moderate | Assault, Vehicle Theft, Vandalism | 2 patrol cars | Move away, call police |
| 3 - Serious | Armed Assault, Weapon Discharge | 3-4 units, armed response | Flee, panic, hide |
| 4 - Severe | Murder, Cop Killing | 6+ units, SWAT dispatched | Mass panic, stampede |
| 5 - Extreme | Mass Shooting, Terrorism | Full lockdown, helicopters | City-wide alert, evacuation |
Real-World Implementation Patterns
-- Creates a realistic NPC with work-life balance function OnStart() -- Configure as business professional SetNPCType("BUSINESS_PERSON") SetNPCPersonality(0.1, 0.7, 0.3) -- Low aggression, high fear (avoids conflict) -- Set appropriate speeds SetNPCSpeed(1.8, 5.5) -- Slightly faster walk -- Configure animations SetNPCAnimations("Idle_Office", "Walk_Business", "Run", "Punch", "Death") -- đ Define Complete Daily Schedule -- 6:00 AM - Wake up at home AddDailyActivity("Wake", 6.0, 7.0, 10, 0, 10) -- 7:00 AM - Coffee shop (morning routine) AddDailyActivity("Coffee", 7.0, 7.5, 45, 0, -15) -- 8:00 AM - 5:00 PM - Work at office downtown AddDailyActivity("Work", 8.0, 17.0, 150, 0, -40) -- 5:00 PM - 6:00 PM - Gym after work AddDailyActivity("Gym", 17.0, 18.0, -20, 0, 50) -- 6:30 PM - 7:30 PM - Dinner at restaurant AddDailyActivity("Dinner", 18.5, 19.5, 80, 0, 25) -- 8:00 PM - 6:00 AM - Home (sleep) AddDailyActivity("Sleep", 20.0, 6.0, 10, 0, 10) print("Business NPC initialized with daily schedule") end function OnUpdate(dt) -- React to danger (high fear personality) local playerID = FindNearestEntity("Player", 15.0) if playerID ~= nil then local px, py, pz = GetEntityPosition(playerID) local mx, my, mz = GetPosition() local distance = GetDistance(mx, my, mz, px, py, pz) -- If player is shooting nearby, flee immediately if IsKeyDown("F") and distance < 20.0 then SetNPCState("FLEEING") -- Run away from danger local fleeDir = { x = mx - px, z = mz - pz } local length = Sqrt(fleeDir.x * fleeDir.x + fleeDir.z * fleeDir.z) fleeDir.x = fleeDir.x / length fleeDir.z = fleeDir.z / length local fleeDist = 30.0 SetNPCDestination( mx + fleeDir.x * fleeDist, my, mz + fleeDir.z * fleeDist ) PlayAnim("Run") end end -- Health check if GetNPCHealth() < 20 then SetNPCState("FLEEING") end end
-- Civilian who witnesses crimes and calls police local crimeReported = false local witnessedCrime = false local panicMode = false function OnStart() SetNPCType("CIVILIAN_MALE") SetNPCPersonality(0.05, 0.85, 0.2) -- Very afraid, won't fight SetNPCSpeed(1.5, 6.0) SetNPCStats(80, 25.0, 30.0) -- Good hearing range StartTimer("witness_check") end function OnUpdate(dt) -- Look for nearby player local playerID = FindNearestEntity("Player", 25.0) if playerID ~= nil and not crimeReported then local px, py, pz = GetEntityPosition(playerID) local mx, my, mz = GetPosition() local distance = GetDistance(mx, my, mz, px, py, pz) -- Witness shooting (serious crime) if IsKeyDown("F") and distance < 20.0 then witnessedCrime = true panicMode = true -- Immediately report to police system ReportCrime(px, py, pz, 3.0) -- Severity 3: Armed assault crimeReported = true print("[WITNESS] Crime reported to police!") -- Play panic animation PlayAnim("Panic") SetNPCState("FLEEING") -- Run to safe distance local safeX = mx + (mx - px) * 2.0 local safeZ = mz + (mz - pz) * 2.0 SetNPCDestination(safeX, my, safeZ) end -- Witness assault (moderate crime) local nearbyNPC = FindNearestEntity("NPC", 5.0) if nearbyNPC ~= nil and distance < 8.0 then local npcState = GetNPCState() if npcState == "ATTACKING" then ReportCrime(px, py, pz, 2.0) -- Severity 2: Assault crimeReported = true print("[WITNESS] Assault reported!") end end end -- If crime reported, stay in panic mode for a while if panicMode then local panicTime = GetTimer("witness_check") if panicTime > 10.0 then panicMode = false SetNPCState("IDLE") PlayAnim("Idle") end end -- Check if police arrived (witness feels safer) if HasSeenPolice() and panicMode then print("[WITNESS] Police have arrived, feeling safer") panicMode = false SetNPCState("IDLE") end end
-- Gang member who defends territory and attacks police on sight local territoryCenter = {x = 50, y = 0, z = -30} local territoryRadius = 40.0 local gangMates = {} local inCombat = false function OnStart() SetNPCType("GANG_MEMBER") SetNPCPersonality(0.95, 0.15, 0.9) -- High aggression, fearless SetNPCSpeed(2.0, 7.0) -- Fast runner SetNPCStats(150, 30.0, 35.0) -- Tough, alert -- Find and befriend other gang members local gang1 = FindEntity("GangMember2") local gang2 = FindEntity("GangMember3") if gang1 ~= nil then MakeFriend(gang1) table.insert(gangMates, gang1) end if gang2 ~= nil then MakeFriend(gang2) table.insert(gangMates, gang2) end print("[GANG] Territory patrol initialized") end function OnUpdate(dt) local mx, my, mz = GetPosition() -- Check if in territory local distFromCenter = GetDistance( mx, my, mz, territoryCenter.x, territoryCenter.y, territoryCenter.z ) local inTerritory = distFromCenter < territoryRadius -- PRIORITY 1: Attack police on sight (gang vs cops) local copID, copDist = FindNearestEntity("Police", 40.0) if copID ~= nil then print("[GANG] Cop spotted! Engaging!") SetNPCTarget(copID) SetNPCState("ATTACKING") inCombat = true -- Report crime (gang attacking cop = high severity) local cx, cy, cz = GetEntityPosition(copID) ReportCrime(cx, cy, cz, 4.0) -- Cop assault = severity 4 return -- Focus on combat end -- PRIORITY 2: Defend territory from intruders if inTerritory then local playerID, playerDist = FindNearestEntity("Player", territoryRadius) if playerID ~= nil and playerDist < 20.0 then -- Warn player first time if not inCombat then print("[GANG] You're in our territory!") SetNPCState("TALKING") LookAt(GetEntityPosition(playerID)) -- If player comes closer, attack if playerDist < 8.0 then SetNPCTarget(playerID) SetNPCState("ATTACKING") inCombat = true end end end else -- Outside territory: return to patrol if GetNPCState() == "IDLE" then SetNPCDestination( territoryCenter.x + Random(-20, 20), territoryCenter.y, territoryCenter.z + Random(-20, 20) ) end end -- Health management local health = GetNPCHealth() if health < 40 and inCombat then -- Even tough gang members retreat when badly injured print("[GANG] Retreating to cover!") SetNPCState("FLEEING") -- Run back to territory center SetNPCDestination(territoryCenter.x, territoryCenter.y, territoryCenter.z) inCombat = false end end
-- Police officer who patrols, investigates crimes, and pursues suspects local patrolPoints = { {x = 0, y = 0, z = 0}, {x = 50, y = 0, z = 0}, {x = 50, y = 0, z = 50}, {x = 0, y = 0, z = 50} } local currentPatrolIndex = 1 local investigating = false local pursuitMode = false function OnStart() SetNPCType("POLICE") SetNPCPersonality(0.65, 0.25, 0.85) -- Aggressive but controlled SetNPCSpeed(2.0, 6.5) -- Fast response SetNPCStats(180, 40.0, 45.0) -- High awareness SetNPCAnimations("Idle_Cop", "Walk_Patrol", "Run_Chase", "Arrest", "Death") -- Start patrol route StartPatrolRoute() end function StartPatrolRoute() local nextPoint = patrolPoints[currentPatrolIndex] MoveTo(nextPoint.x, nextPoint.y, nextPoint.z) -- Uses advanced pathfinding SetNPCState("WALKING") end function OnUpdate(dt) local mx, my, mz = GetPosition() -- PRIORITY 1: Respond to active crimes local criminalID, crimeDist = FindNearestEntity("Criminal", 50.0) if criminalID ~= nil and crimeDist < 30.0 then investigating = true pursuitMode = true local cx, cy, cz = GetEntityPosition(criminalID) local distance = GetDistance(mx, my, mz, cx, cy, cz) -- If close enough, attempt arrest if distance < 2.5 then SetNPCState("ATTACKING") -- Arrest animation PlayAnim("Arrest") print("[POLICE] Attempting arrest!") -- Apply arrest (in real game, this would remove wanted level) local arrested = NPCDamage(criminalID, 0) -- Just check without damage elseif distance < 15.0 then -- Chase suspect SetNPCTarget(criminalID) SetNPCState("RUNNING") PlayAnim("Run_Chase") -- Use pathfinding for smart chase MoveTo(cx, cy, cz) else -- Move to last known position SetNPCState("RUNNING") MoveTo(cx, cy, cz) end return -- Focus on pursuit end -- PRIORITY 2: Investigate suspicious activity local suspectID = FindNearestEntity("NPC", 20.0) if suspectID ~= nil and not investigating then local suspectState = GetNPCState(suspectID) -- If NPC is fleeing or fighting, investigate if suspectState == "FLEEING" or suspectState == "ATTACKING" then investigating = true local sx, sy, sz = GetEntityPosition(suspectID) MoveTo(sx, sy, sz) SetNPCState("RUNNING") print("[POLICE] Investigating suspicious activity") end end -- PRIORITY 3: Normal patrol if not investigating and not pursuitMode then local currentPoint = patrolPoints[currentPatrolIndex] local distToPoint = GetDistance( mx, my, mz, currentPoint.x, currentPoint.y, currentPoint.z ) -- Reached patrol point, move to next if distToPoint < 2.0 then currentPatrolIndex = currentPatrolIndex + 1 if currentPatrolIndex > #patrolPoints then currentPatrolIndex = 1 end StartPatrolRoute() end end -- Give up chase if suspect escapes if pursuitMode and crimeDist > 60.0 then print("[POLICE] Suspect escaped") pursuitMode = false investigating = false SetNPCState("IDLE") StartPatrolRoute() end end
-- Full FPS controller with WASD movement, jumping, and mouse camera local moveSpeed = 8.0 local sprintSpeed = 12.0 local jumpForce = 8.0 local mouseSensitivity = 0.1 local cameraYaw = 0.0 local cameraPitch = 0.0 local isJumping = false function OnStart() -- Lock mouse for FPS controls LockMouse(true) -- Setup player SetGravity(true) print("[PLAYER] FPS Controller initialized") print("Controls: WASD = Move, SHIFT = Sprint, SPACE = Jump, ESC = Exit") end function OnUpdate(dt) -- ESC to unlock mouse if IsKeyDown("ESC") then LockMouse(false) end -- === MOUSE LOOK === local deltaX, deltaY = GetMouseDelta() cameraYaw = cameraYaw + deltaX * mouseSensitivity cameraPitch = cameraPitch + deltaY * mouseSensitivity -- Clamp pitch to prevent camera flipping cameraPitch = Clamp(cameraPitch, -89.0, 89.0) SetRotation(cameraPitch, cameraYaw, 0) -- === MOVEMENT === local currentSpeed = moveSpeed if IsKeyDown("SHIFT") then currentSpeed = sprintSpeed end -- Get current position and rotation local px, py, pz = GetPosition() local rotX, rotY, rotZ = GetRotation() -- Calculate forward and right vectors local yawRad = rotY * 3.14159 / 180.0 local forward = { x = Sin(yawRad), z = Cos(yawRad) } local right = { x = Cos(yawRad), z = -Sin(yawRad) } -- WASD movement local moveX = 0 local moveZ = 0 if IsKeyDown("W") then moveX = moveX + forward.x moveZ = moveZ + forward.z end if IsKeyDown("S") then moveX = moveX - forward.x moveZ = moveZ - forward.z end if IsKeyDown("A") then moveX = moveX - right.x moveZ = moveZ - right.z end if IsKeyDown("D") then moveX = moveX + right.x moveZ = moveZ + right.z end -- Normalize diagonal movement local moveLength = Sqrt(moveX * moveX + moveZ * moveZ) if moveLength > 0 then moveX = moveX / moveLength moveZ = moveZ / moveLength end -- Apply movement Translate( moveX * currentSpeed * dt, 0, moveZ * currentSpeed * dt ) -- === JUMPING === if IsKeyDown("SPACE") and IsGrounded() and not isJumping then AddForce(0, jumpForce, 0) isJumping = true end -- Reset jump when grounded if IsGrounded() then isJumping = false end -- === INTERACTION === if IsKeyDown("E") then -- Check for nearby interactable NPCs local npcID, distance = FindNearestEntity("NPC", 3.0) if npcID ~= nil then print("[PLAYER] Interacting with NPC") -- Trigger NPC dialogue or interaction end end end
GetDeltaTime() for frame-independent movementFindNearestEntity() with appropriate ranges to optimize performance