Home - DoktorSAS/IW6X-S1X-Scripting-Guide GitHub Wiki
IW6X/S1X Scripting Guide
IW6X is a Call Of Duty Ghost client that lets you play with other users through servers managed by the community itself. This client allows you to make changes to the game and modes through the Lua programming language. S1X is a Call Of Duty Advanced Warfare client which, like IW6X, uses the same system as Lua support with a few minor differences in some function calls. This guide is intended to help you understand the basic mechanisms for scripting in Lua on IW6X and S1X.
IW6X Extra
S1X Extra
How to load/create script
Creating or loading scripts is very easy. You have to open the game folder and then open the iw6x/s1x folder. There you will find a scripts folder (if there are no folders, create them).
What is in the scripts folder will be loaded. To begin with, simply create another folder and write the code in it. The file that defines the whole script is the __init__.lua
file. In fact this file will be the only one read by the game by default.
To include a lua file other than __init__.lua
, you must use the include function and specify the file name, such as include("bots")
.
If you have the files ready to use, simply copy and paste them into the scripts folder.
Notify / Events
Notifications are in-game events called on certain occasions. Through lua we can determine what to do once we receive a notify. In fact we can capture these Notify and choose the operations to do.
IW6X provides two functions for notifications, one is used to call it every time the event is captured ( level:onnotify("event", function)
) and another is used once, the first time the event occurs ( level:onnotifyonce("event",function)
).
- level:onnotify("event", function)
- level:onnotifyonce("event",function)
onPlayerSpawned
Once
function onPlayerSpawnedOnce( player )
...
end
function onPlayerConnected( player )
local spawnListener = player:onnotifyonce("spawned_player", function() onPlayerSpawnedOnce(player) end);
end
level:onnotify("connected", onPlayerConnected)
Not Once
function onPlayerSpawned( player )
...
end
function onPlayerConnected( player )
local spawnListener = player:onnotify("spawned_player", function() onPlayerSpawned(player) end);
end
level:onnotify("connected", onPlayerConnected)
Functions & Parameters
Functions represent the operations that need to be performed. Calling a function allows you to perform as many operations as you deem necessary with a single call. Functions in lua start at functions call and end at end call. Functions may or may not have parameters.
Parameters
When a parameter or variable has no value its default value will be nil, which is the equivalent of null. Variables and parameters do not have type beware of comparing strings with numbers
No parameters
functionName();
function functionName()
...
end
Parameters
If a function requires parameters remember to pass the parameters when you call the function.
functionName(par1, par2, ..., parX)
function functionName( par1, par2, ..., parX)
...
end
Entity
An entity we can define it as an object that contains the information of a certain scope. We can recognize different entities such as the player entity or the level entity. To get this information we need to call the variable representing the entity and write .nameparameter.
Exemple:
player.name
or level.gameended
Player
The player entity represents the player, in fact through an entity of type player we can get different information.
function onPlayerSpawnedOnce( player )
game:clientprint(player, "Welcome to the Server " .. player.name);
end
level:onnotifyonce("spawned_player", function() onPlayerSpawned( player ) end)
Level
The level entity represents the state of the game, we can in fact recognize states through these entities
function onPlayerSpawnedOnce( player )
if level.gameended then
game:clientprint(player, "Welcome to the Server " .. player.name);
end
end
function onPlayerConnected( player )
local spawnListener = player:onnotifyonce("spawned_player", function() onPlayerSpawnedOnce(player) end);
end
level:onnotify("connected", onPlayerConnected)
Loop
it is possible to call some loops through a function game:oninterval
, in fact specifying the function to call and specifying a time for the next call to the function we can create some loops. It is good to assign these loops to a variable. This allows you to terminate the loop at a time you decide. In the example I decided to end the loop when the player leaves the game. In a few words I make an operation that cleans up the script by stopping the things that are no longer necessary.
The game:oninterval function has two parameters
- Function to call
- Time to call again the Function to call in milliseconds
function client_print( player )
game:clientprint(player, "Respect the rules");
end
function onPlayerConnected( player )
local timer = game:oninterval(client_print, 1000)
player:onnotifyonce("disconnect", function ()
timer:clear();
end)
end
level:onnotify("connected", onPlayerConnected)
Entity Function
In gsc the entity affected by a call to a function is renamed self. In lua this is not quite possible but you can build functions that belong to the entity. In fact, I can call a function without having to pass the player entity as an input parameter, but I can use self directly.
function entity:client_print()
game:clientprint(self, "Respect the rules");
end
Socials