Jump to content

Jedi Academy turned 20 this year! We celebrated in a ton of different ways: mod contest, server event, podcast, etc. Thank you to all who have been a part of this game for the last two decades. Check out the anniversary content!

Read more

Welcome to JKHub

This community is dedicated to the games Star Wars: Jedi Outcast (2002) and Jedi Academy (2003). We host over 3,000 mods created by passionate fans around the world, and thousands of threads of people showcasing their works in progress and asking for assistance. From mods to art to troubleshooting help, we probably have it. If we don't, request or contribute!

Get started

This game turned 20 years old this year, and it is still one of the greatest Star Wars games of all time. If you're new or returning from a long hiatus, here are the basics of getting started with Star Wars Jedi Knight Jedi Academy in 2023.

Read more

Creating a Lua plugin for JA++


Astral Serpent
spacer.png
Introduction
Welcome to my tutorial on creating a Lua plugin for JA++.
Let's start with the requirements, whether they be software or actual knowledge:
 

 

Installation instructions for each of these can be found on the respective sites, LUA does not need to be installed as it is interpreted by JA++ itself.
 
Additional Information:
 
Getting Started
First, you'll want to navigate to your GameData\japlus\cl\lua and create a folder for your plugin, I suggest naming it something related to planes, because planes are neat, mine will be named AstralPlane.
 
Next, we want to go inside our plugin folder and create a file named plugin.lua.
 
Alternatively, you can just open up notepad++ and save the file we will be working on as plugin.lua, so long as it's plugin.lua and it ends up there somehow with the needed things inside.
 
Let's jump in, first we need to declare the plugin so JA++ knows what it is.
 
RegisterPlugin( string name, string version )

 

 
We must assign a local object to this and fill it with the correct info, here's an example:

 

local AstralPlane = RegisterPlugin( AstralPlane, 1337 )

 

After that, start up JA++ (I suggest also doing jappvideomode 1 while at the menu, so that you can alt tab, or you can just use windowed mode)
 
Join a japlus server, I generally test on jawa.jk3.in since it's usually full of people to talk to.
 
Lua plugins are loaded in client game, meaning once you join a server your Lua plugin will load. This means that you can not use or test a Lua plugin in the menu.
 
Once in-game, you should see information on plugins you have, a completely fresh install of JA++ won't have any plugins, but your new plugin should display along with the name and version you set.
 
Fun note: You can use ^1-7 on the name and version too for colourful plugin names. Seems obvious, but whatever.
 
Now that we have our plugin initialized and ready to modify... Let's get creating!
 
Creating A Console Command
Let's create a console command that uses an anonymous function to print something. (anonymous means the function is defined here and can't be used elsewhere)
 
AddConsoleCommand( string cmd, function listener )

 

 
the first argument is what the player must type in the console, the second is the function to be executed, in our case we shall be using an anonymous function (a function defined here and now, not somewhere else in the .lua file)
 
AddConsoleCommand( foo, function()

print(bar)

end)

 

Two things to note:
 
AddConsoleCommand() in this case does not finish until end), which closes both our anonymous function and the AddConsoleCommand call.
 
the function has no name, meaning it can't be called anywhere else, you may want to try named functions for something you'll want to call in different circumstances.
 
And there you have it, the basics of a Lua plugin.

 

Some extra info that'll help you:
 
You can run the game in windowed mode (r_fullscreen 0, and then vid_restart).
 
type jplua_reload after saving any Lua plugin changes to see the effects immediately.
 

Edited by Circa
Formatting


User Feedback

Recommended Comments

There are no comments to display.



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...