Getting_started/Your_first_server_script
Create Scripts/Main/Server.nut and list it in Script.xml. There is nothing to register for events: an event is just a global function with the right name. The server calls it when the thing happens.
function onScriptLoad()
{
print("Gamemode started!");
CreateVehicle(VEH_INFERNUS, Vector(812.0, -935.0, 36.0), 90.0, -1, -1);
CreatePickup(1362, Vector(805.0, -930.0, 36.0));
}
function onPlayerJoin(player)
{
Message(player.Name + " joined the server");
}
function onPlayerSpawn(player, classID)
{
player.Health = 100.0;
player.Cash = 5000;
player.SetWeapon(WEP_COLT45, 120);
MessagePlayer("Welcome, " + player.Name + "!", player);
}
function onPlayerCommand(player, cmd, params)
{
if (cmd == "heal") player.Health = 100.0;
else if (cmd == "car")
{
local v = CreateVehicle(VEH_BANSHEE, player.Pos, player.Angle, -1, -1);
if (v) player.Vehicle = v;
}
else MessagePlayer("Unknown command /" + cmd, player);
}Tip
print(...) writes to the server console. Typing a line in the server console fires onConsoleInput(cmd, text). Use ReloadScripts() (or the console command reload_scripts) to restart all scripts without restarting the server.Categories: Getting started