Add new effect 'Disable Pedestrians'; update 'Back To Black' effect timing; enhance 'Annoying RC Vehicle' functionality
This commit is contained in:
47
.github/copilot-instructions.md
vendored
Normal file
47
.github/copilot-instructions.md
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
# Copilot instructions for gta5-chaos-luascripts
|
||||
|
||||
These notes help an AI coding agent make productive, targeted edits to this repository.
|
||||
|
||||
1. Project purpose
|
||||
- This repo is a collection of Lua effects for the GTA V Chaos Mod runtime. Each file defines one effect that the Chaos Mod loader expects to find and execute.
|
||||
|
||||
2. Key file patterns
|
||||
- Every effect defines an `EffectInfo` table and three lifecycle functions: `OnStart()`, `OnTick()`, and `OnStop()`.
|
||||
- Example files: [Player/PlayerTPEverythingAway.lua](Player/PlayerTPEverythingAway.lua), [Player/PlayerAnnoyingRCVehicle.lua](Player/PlayerAnnoyingRCVehicle.lua), [Peds/PedsClowningAround.lua](Peds/PedsClowningAround.lua), [Misc/MiscCleanUp.lua](Misc/MiscCleanUp.lua).
|
||||
|
||||
3. Naming & metadata conventions
|
||||
- `EffectInfo.EffectId`: unique, snake_case id (prefixes used include `player_`, `peds_`, `veh_`, `misc_`). Keep ids stable to avoid breaking saved configs.
|
||||
- `TimedType`: one of `None`, `Normal`, `Short`, `Permanent`, or `Custom` (set `CustomTime` when using `Custom`). See `PlayerTPEverythingAway.lua` for examples.
|
||||
- `EffectGroup`/`EffectCategory`: optional grouping used by the mod UI—preserve existing values when editing.
|
||||
|
||||
4. API and runtime expectations
|
||||
- Scripts call Chaos Mod runtime helpers and GTA native functions (e.g. `GET_ENTITY_COORDS`, `SET_ENTITY_COORDS`, `GET_HASH_KEY`). Do not assume standard Lua libraries beyond basic math/table/string.
|
||||
- Use provided helper functions like `GetAllVehicles()` and `GetAllPeds()` when present. Heavy work should be bracketed with `EnableScriptThreadBlock()` / `DisableScriptThreadBlock()` as shown in `PlayerTPEverythingAway.lua`. This prevents mission breakage.
|
||||
|
||||
5. Safe editing practices
|
||||
- Keep `OnTick()` lightweight. Per-file patterns use `OnStart()` for heavy one-off operations and `OnStop()` for cleanup (see `Misc/MiscCleanUp.lua`).
|
||||
- When adding model/ped/vehicle creation, call `SET_MODEL_AS_NO_LONGER_NEEDED()` after spawning and set network flags where existing files do.
|
||||
|
||||
6. Debugging & testing
|
||||
- Runtime: these scripts are loaded by the Chaos Mod runtime. The README explains how to install effects into `ChaosMod/Effects` — follow those steps to test in game.
|
||||
- Use `print()` statements for minimal runtime logs; prefer non-destructive testing (temporary vehicles/peds) and ensure cleanup in `OnStop()`.
|
||||
|
||||
7. Code style & idioms to follow
|
||||
- Minimal globals: existing scripts set a few globals (e.g. `playerPed`) in `OnStart()` — match existing style rather than introducing module systems.
|
||||
- Prefer small, focused changes: add helpers at the bottom of the same file unless the change is shared across many effects.
|
||||
|
||||
8. Integration & external dependencies
|
||||
- This repo depends on the external Chaos Mod loader and GTA Natives—do not attempt to refactor away from those calls.
|
||||
|
||||
9. What not to change
|
||||
- Do not rename `EffectInfo.EffectId`, remove lifecycle functions, or change `TimedType` semantics without updating any UI grouping logic (not present in this repo).
|
||||
|
||||
10. If you need more context
|
||||
- Read the top-level [README.md](README.md) and review representative scripts in `Player/`, `Peds/`, `Vehs/`, `Misc/` to learn common helpers and patterns.
|
||||
|
||||
If anything is unclear or you want additional examples (naming, timing, or network-safe spawning), tell me which area to expand.
|
||||
|
||||
11. External References
|
||||
- Chaos Mod Lua Scripting Wiki: `(https://github.com/gta-chaos-mod/ChaosModV/wiki/Lua-Scripting)`
|
||||
- GTA V Natives Reference: `(https://nativedb.scheenen.dev/natives)`
|
||||
- Example Effect Template: `(https://gitea.nathan-falvey.synology.me/Templates/gta5-chaos-luascript-template)`
|
||||
101
Misc/MiscDisablePedestrians.lua
Normal file
101
Misc/MiscDisablePedestrians.lua
Normal file
@@ -0,0 +1,101 @@
|
||||
-- Short coherent template for a Chaos Mod effect.
|
||||
-- Edit the fields below to describe the effect and adjust timing/weighting.
|
||||
-- Full reference: https://github.com/gta-chaos-mod/ChaosModV/wiki/Lua-Scripting
|
||||
|
||||
EffectInfo = { -- ScriptInfo for mod version < 2.0
|
||||
Name = "Disable Pedestrians", -- Display name of the effect
|
||||
EffectId = "misc_disablepeds", -- ScriptId for mod version < 2.0, must be unique
|
||||
--Description = "A short one-line description of what this effect does.",
|
||||
TimedType = "Custom", -- None, Normal, Short, Permanent, or "Custom"
|
||||
CustomTime = 120, -- (seconds) only if TimedType = "Custom"
|
||||
WeightMultiplier = 1, -- Relative probability of being chosen
|
||||
HideRealNameOnStart = false, -- true to hide the effect's real name when it starts
|
||||
EffectCategory = "None", -- Optional category
|
||||
EffectGroup = "", -- Optional grouping (leave empty if unused)
|
||||
IncompatibleIds = {
|
||||
-- Example: "other_effect_id", -- add EffectIds that cannot run simultaneously
|
||||
}
|
||||
}
|
||||
|
||||
-- Called once when the effect starts
|
||||
function OnStart()
|
||||
print("[effect_template] OnStart: " .. ((EffectInfo and EffectInfo.Name) or "unknown"))
|
||||
-- Initialize effect state here (e.g. set timers, spawn helpers)
|
||||
end
|
||||
|
||||
-- Called once when the effect stops/ends
|
||||
function OnStop()
|
||||
SET_PED_POPULATION_BUDGET(3)
|
||||
SET_VEHICLE_POPULATION_BUDGET(3)
|
||||
SET_REDUCE_PED_MODEL_BUDGET(false)
|
||||
SET_REDUCE_VEHICLE_MODEL_BUDGET(false)
|
||||
SET_DISTANT_CARS_ENABLED(true)
|
||||
print("[effect_template] OnStop: " .. ((EffectInfo and EffectInfo.Name) or "unknown"))
|
||||
-- Cleanup state here (e.g. remove entities, clear timers)
|
||||
end
|
||||
|
||||
-- Called every game tick while the effect is active
|
||||
function OnTick()
|
||||
-- Keep this lightweight. Use this for per-frame checks or gradual changes.
|
||||
|
||||
SET_PED_POPULATION_BUDGET(0)
|
||||
SET_VEHICLE_POPULATION_BUDGET(0)
|
||||
SET_REDUCE_PED_MODEL_BUDGET(true)
|
||||
SET_REDUCE_VEHICLE_MODEL_BUDGET(true)
|
||||
SET_DISTANT_CARS_ENABLED(false)
|
||||
WAIT(500) -- Example: wait 500 ms between ticks, adjust as needed, also for performance
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- A compilation of frequently used lua helper functions.
|
||||
-- If downloaded externally, ensure to credit the original author.
|
||||
|
||||
-- Add custom helper functions below.
|
||||
|
||||
function IS_PLAYER_AVAILABLE()
|
||||
local player_ped = PLAYER_PED_ID()
|
||||
if not DOES_ENTITY_EXIST(player_ped) or IS_ENTITY_DEAD(player_ped) or IS_PLAYER_SWITCH_IN_PROGRESS() then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function GET_PLAYER_PED_OFFSET(offset_x, offset_y, offset_z)
|
||||
local player_ped = PLAYER_PED_ID()
|
||||
return GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(player_ped, offset_x, offset_y, offset_z)
|
||||
end
|
||||
|
||||
function RETURN_PLAYER_VEHICLE()
|
||||
local player_ped = PLAYER_PED_ID()
|
||||
if IS_PED_IN_ANY_VEHICLE(player_ped, false) then
|
||||
local vehicle = GET_VEHICLE_PED_IS_IN(player_ped, false)
|
||||
return vehicle
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function GET_PLAYER_PED_HEADING()
|
||||
local player_ped = PLAYER_PED_ID()
|
||||
return GET_ENTITY_HEADING(player_ped)
|
||||
end
|
||||
|
||||
function RANDOM_CHOICE(p1)
|
||||
if type(p1) ~= "table" or #p1 == 0 then
|
||||
return nil
|
||||
end
|
||||
local choice = p1[math.random(#p1)]
|
||||
return choice
|
||||
end
|
||||
|
||||
|
||||
function CREATE_GHOST(ped_model, offset_x, offset_y, offset_z)
|
||||
local player_heading = GET_PLAYER_PED_HEADING()
|
||||
local ped_model_hash = GET_HASH_KEY(ped_model)
|
||||
local player_coords = GET_PLAYER_PED_OFFSET(offset_x, offset_y, offset_z)
|
||||
local ghost = CreatePoolPed(1, ped_model_hash, player_coords.x, player_coords.y, player_coords.z, player_heading)
|
||||
SET_ENTITY_ALPHA(ghost, 0, false)
|
||||
return ghost
|
||||
end
|
||||
|
||||
@@ -17,6 +17,7 @@ function OnStart()
|
||||
driver = CreatePoolPed(1, driverModelHash, coords.x, coords.y, coords.z+50, heading)
|
||||
SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(PED_TO_NET(driver), true)
|
||||
SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(VEH_TO_NET(rc), true)
|
||||
SET_HORN_ENABLED(rc, false)
|
||||
SET_PED_INTO_VEHICLE(driver, rc, -1)
|
||||
SET_ENTITY_LOAD_COLLISION_FLAG(driver, true, 1)
|
||||
SET_ENTITY_INVINCIBLE(driver, true, false)
|
||||
|
||||
@@ -17,6 +17,7 @@ function OnStart()
|
||||
driver = CreatePoolPed(1, driverModelHash, coords.x, coords.y, coords.z+50, heading)
|
||||
SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(PED_TO_NET(driver), true)
|
||||
SET_NETWORK_ID_EXISTS_ON_ALL_MACHINES(VEH_TO_NET(rc), true)
|
||||
SET_HORN_ENABLED(rc, false)
|
||||
SET_PED_INTO_VEHICLE(driver, rc, -1)
|
||||
SET_ENTITY_LOAD_COLLISION_FLAG(driver, true, 1)
|
||||
SET_ENTITY_INVINCIBLE(driver, true, false)
|
||||
|
||||
@@ -30,3 +30,9 @@ This project is a hands-on exercise in game modding and logic design. Through th
|
||||
3. Place them in your `ChaosMod/Effects` directory.
|
||||
|
||||
---
|
||||
|
||||
---
|
||||
### Effect Template
|
||||
* An effect template can be found at [this repo](https://gitea.nathan-falvey.synology.me/Templates/gta5-chaos-luascript-template).
|
||||
* [Raw Template Code](https://gitea.nathan-falvey.synology.me/Templates/gta5-chaos-luascript-template/raw/branch/main/effect_template.lua), if needed.
|
||||
---
|
||||
@@ -6,8 +6,7 @@ EffectInfo = { -- ScriptInfo for mod version < 2.0
|
||||
Name = "Back To Black", -- Display name of the effect
|
||||
EffectId = "screen_backtoblack", -- ScriptId for mod version < 2.0, must be unique
|
||||
Description = "A short one-line description of what this effect does.",
|
||||
TimedType = "Custom", -- None, Normal, Short, Permanent, or "Custom"
|
||||
CustomTime = 340, -- (seconds) only if TimedType = "Custom"
|
||||
TimedType = "Normal", -- None, Normal, Short, Permanent, or "Custom"
|
||||
WeightMultiplier = 1, -- Relative probability of being chosen
|
||||
HideRealNameOnStart = false, -- true to hide the effect's real name when it starts
|
||||
EffectCategory = "Shader", -- Optional category
|
||||
@@ -33,6 +32,7 @@ end
|
||||
darkness_value = 0.0
|
||||
start = GetTickCount()
|
||||
function OnTick()
|
||||
print(start)
|
||||
playerPed = PLAYER_PED_ID()
|
||||
if not DOES_ENTITY_EXIST(playerPed) or IS_PLAYER_SWITCH_IN_PROGRESS() or IS_PED_DEAD_OR_DYING(playerPed,0) then return end
|
||||
DRAW_RECT(0.5, 0.5, 1.0, 1.0, 0, 0, 0, darkness_value)
|
||||
|
||||
@@ -33,8 +33,7 @@ end
|
||||
-- Called every game tick while the effect is active
|
||||
function OnTick()
|
||||
-- Keep this lightweight. Use this for per-frame checks or gradual changes.
|
||||
local pc_time = os.date("*t")
|
||||
SET_CLOCK_TIME(pc_time.hour, pc_time.min, pc_time.sec)
|
||||
SET_CLOCK_TIME(os.date("%H"), os.date("%M"), os.date("%S"))
|
||||
WAIT(500) -- Example: wait 500 ms between ticks, adjust as needed, also for performance
|
||||
end
|
||||
|
||||
|
||||
@@ -45,5 +45,5 @@ function OnTick()
|
||||
end
|
||||
USE_SNOW_FOOT_VFX_WHEN_UNSHELTERED(true)
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user