sm64coopdx/docs/lua/lua.md

64 lines
2.6 KiB
Markdown
Raw Normal View History

2022-01-30 06:47:22 +00:00
# Lua Reference
The Lua scripting API is in early development.
Expect many more things to be supported in the future.
<br />
## How to install Lua mods
Lua scripts you make can be placed either the `mods` folder in the base directory, or in `<SAVE FILE LOCATION>/mods`
<br />
## Tips
- When developing Lua mods, run the game from a console. Lua errors and logs will appear there.
- You can use the `print()` command when debugging. Your logs will show up in the console.
2022-03-13 05:47:48 +00:00
- [Setting up Visual Studio Code](vs-code-setup.md) will give you autocomplete and other nice things.
2022-03-17 05:55:16 +00:00
- You can create a folder within the mods folder containing multiple lua scripts as long as one script is called `main.lua`. Dynos actors can be placed inside this mod folder under `<your mod folder>/actors/`.
<br />
2022-02-02 02:52:26 +00:00
## Sections
- [Globals](globals.md)
2022-01-30 08:07:50 +00:00
- [Hooks](hooks.md)
2022-01-30 06:47:22 +00:00
- [Constants](constants.md)
- [Functions](functions.md)
- [Structs](structs.md)
<br />
## Important notes on player indices
Something important to realize is that the `localIndex` for each player is different (unfortunately).
So the order of `gMarioStates[]`, `gNetworkPlayers[]`, and `gPlayerSyncTable[]` is different for each player.
Luckily `gPlayerSyncTable[]` will automatically translate the player indices, so setting `gPlayerSyncTable[0].example = 1` will set it for the correct player for everyone.
The `globalIndex` of each player is consistent among everyone connected. So if you absolutely need to sort things in order you will have to grab it from `gNetworkPlayers[<LOCAL INDEX HERE>].globalIndex`.
All of this is a holdover from when there were only two players. It was a reasonable idea back then.
<br />
## Example Lua mods (small)
2022-01-30 06:47:22 +00:00
- [Low Gravity](../../mods/low-gravity.lua)
- [Faster Swimming](../../mods/faster-swimming.lua)
2022-03-19 04:30:53 +00:00
- [Mario Run](../../mods/Mario-Run.lua)
2022-02-16 06:15:49 +00:00
- [HUD Rendering](examples/hud.lua)
2022-02-26 08:03:21 +00:00
- [Object Spawning](examples/spawn-stuff.lua)
2022-03-05 07:14:01 +00:00
- [Custom Ball Behavior](examples/behavior-ball.lua)
- [Replace Goomba Behavior](examples/behavior-replace-goomba.lua)
- [Add to Goomba Behavior](examples/behavior-add-to-goomba.lua)
- [Behavior with Surface Collisions](examples/behavior-surface-collisions.lua)
2022-03-17 05:55:16 +00:00
- [Custom Box Model](examples/custom-box-model)
2022-03-18 04:41:46 +00:00
- [Custom Player Model](examples/koopa-player-model)
2022-03-19 04:30:53 +00:00
- [Moonjump](examples/Moonjump.lua)
- [Instant Clip](examples/Instant_Clip.lua)
## Example Lua mods (large)
- [Extended Moveset](../../mods/extended-moveset.lua)
- [Character Movesets](../../mods/character-movesets.lua)
- [Hide and Seek Gamemode](../../mods/hide-and-seek.lua)
- [Football (soccer) Gamemode](../../mods/football.lua)