Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TestDotLua = {}
- TestDotLua.Executables = {}
- TestDotLua.Commands = {}
- TestDotLua.loadExecutableForCallback = function(callback_name)
- local ret = false
- local func = loadfile("scriptfiles/inline/" .. callback_name .. ".lua")
- if func then
- TestDotLua.Executables[callback_name] = func
- ret = true
- end
- return ret
- end
- TestDotLua.saveExecutableForCallback = function(callback_name, code)
- local ret = false
- local func = nil
- xpcall(
- function()
- func = load(code)
- end,
- function(err)
- print(err)
- end)
- if func then
- TestDotLua.Executables[callback_name] = func
- local f = io.open("scriptfiles/inline/" .. callback_name .. ".lua", "w")
- if f then
- io.output(f)
- io.write(code)
- io.close(f)
- ret = true
- end
- end
- return ret
- end
- TestDotLua.loadCommand = function(command)
- local ret = false
- local func = loadfile("scriptfiles/commands/" .. string.lower(command) .. ".lua")
- if func then
- TestDotLua.Commands[string.lower(command)] = TestDotLua.createCommandData("Custom command", "A custom command", "", func)
- ret = true
- end
- return ret
- end
- TestDotLua.saveCommand = function(command, code)
- local ret = false
- local func = nil
- xpcall(
- function()
- func = load(code)
- end,
- function(err)
- print(err)
- end)
- if func then
- TestDotLua.Commands[string.lower(command)] = TestDotLua.createCommandData("Custom command", "A custom command", "", func)
- local f = io.open("scriptfiles/commands/" .. string.lower(command) .. ".lua", "w")
- if f then
- io.output(f)
- io.write(code)
- io.close(f)
- ret = true
- end
- end
- return ret
- end
- TestDotLua.removeExecutableForCallback = function(callback_name)
- TestDotLua.Executables[callback_name] = nil
- end
- TestDotLua.removeCommand = function(command)
- TestDotLua.Executables[string.lower(command)] = nil
- end
- TestDotLua.executeInCallback = function(callback_name, ...)
- local f = TestDotLua.Executables[callback_name]
- local args = {...}
- if f then
- xpcall(
- function()
- f(args)
- end,
- function(err)
- SendMessageToAll("~r~Scipt error detected at \"" .. callback_name .. "\". Please see the logs.")
- print("[ERROR] In \"" .. callback_name .. "\": " .. err)
- end)
- end
- end
- -- Get command
- TestDotLua.getCommand = function(command)
- return TestDotLua.Commands[string.lower(command)]
- end
- -- Is command allowed
- TestDotLua.isCommandAllowed = function(command)
- return TestDotLua.getCommand(command) or false
- end
- -- Parse command
- TestDotLua.parseCommand = function(playerID, message)
- local cmd = ""
- local args = {}
- local raw_args = ""
- local first = true
- for v in string.gmatch(message, "%w+") do
- if first == true then
- cmd = string.lower(v)
- raw_args = string.sub(message, string.len(cmd) + 2)
- first = false
- else
- table.insert(args, v)
- end
- end
- local command = TestDotLua.getCommand(cmd)
- if command then
- command.command(playerID, args, raw_args)
- else
- if TestDotLua.loadCommand(cmd) then
- TestDotLua.getCommand(cmd).command(playerID, args, raw_args)
- else
- SendMessageToPlayer(playerID, "Command \"/" .. cmd .. "\" not found or forbidden.")
- end
- end
- end
- -- Create command data
- TestDotLua.createCommandData = function(description, fullDescription, requiredParams, command)
- local ret = {}
- ret.description = description
- ret.fullDescription = fullDescription
- ret.requiredParams = requiredParams
- ret.command = command
- return ret
- end
- -- Show help topic
- TestDotLua.showHelpTopic = function(playerID, command)
- local ret = false
- local cmd = TestDotLua.getCommand(command)
- if cmd then
- SendMessageToPlayer(playerID, "")
- SendMessageToPlayer(playerID, "=====Help Topic=====")
- SendMessageToPlayer(playerID, "/" .. string.lower(command) .. " " .. cmd.requiredParams)
- SendMessageToPlayer(playerID, "")
- SendMessageToPlayer(playerID, "Description: " .. cmd.description)
- SendMessageToPlayer(playerID, cmd.fullDescription)
- SendMessageToPlayer(playerID, "====================")
- ShowMessageToPlayer(playerID, "Usage: ~r~/" .. string.lower(command) .. " " .. string.gsub(string.gsub(cmd.requiredParams, "<", "["), ">", "]"))
- ret = true
- end
- return ret
- end
- TestDotLua.Commands.help = TestDotLua.createCommandData("Help topics", "This command shows help topics of all commands", "<optional: topic>", function (playerID, args, raw_args)
- local h = true
- if #args == 1 then
- local cmd = TestDotLua.getCommand(args[1])
- h = not TestDotLua.showHelpTopic(playerID, args[1])
- end
- if h then
- local first = true
- local msg = ""
- SendMessageToPlayer(playerID, "=====Help Topic=====")
- for k, v in pairs(TestDotLua.Commands) do
- if first then
- first = false
- else
- msg = msg .. ", "
- end
- msg = msg .. "/" .. k
- end
- SendMessageToPlayer(playerID, msg)
- end
- end)
- TestDotLua.Commands.inline = TestDotLua.createCommandData("Set inline code", "This command sets inline code", "<callback> <code>", function (playerID, args, raw_args)
- if #args > 1 then
- local code = string.sub(raw_args, string.len(args[1]) + 2)
- if TestDotLua.saveExecutableForCallback(args[1], code) then
- ShowMessageToPlayer(playerID, "~g~Lua code successfully compiled for callback \"" .. args[1] .. "\"")
- else
- ShowMessageToPlayer(playerID, "~r~Failed to compile Lua code for callback \"" .. args[1] .. "\"")
- end
- else
- TestDotLua.showHelpTopic(playerID, "inline")
- end
- end)
- TestDotLua.Commands.setcommand = TestDotLua.createCommandData("Set command code", "This command sets command code", "<command> <code>", function (playerID, args, raw_args)
- if #args > 1 then
- local code = string.sub(raw_args, string.len(args[1]) + 2)
- if TestDotLua.saveCommand(args[1], code) then
- ShowMessageToPlayer(playerID, "~g~Lua code successfully compiled for command /" .. args[1])
- else
- ShowMessageToPlayer(playerID, "~r~Failed to compile Lua code for command /" .. args[1])
- end
- else
- TestDotLua.showHelpTopic(playerID, "setcommand")
- end
- end)
- TestDotLua.Commands.invoke = TestDotLua.createCommandData("Invoke code", "This command invokes code", "<code>", function (playerID, args, raw_args)
- if #args > 0 then
- local func = nil
- xpcall(
- function()
- func = load(raw_args)
- end,
- function(err)
- print(err)
- end)
- if func then
- xpcall(
- function()
- func()
- ShowMessageToPlayer(playerID, "~g~Lua code successfully invoked")
- end,
- function(err)
- print(err)
- ShowMessageToPlayer(playerID, "~r~Failed to invoke Lua code")
- end)
- else
- ShowMessageToPlayer(playerID, "~r~Failed to invoke Lua code")
- end
- else
- TestDotLua.showHelpTopic(playerID, "invoke")
- end
- end)
- TestDotLua.Commands.reloadcommand = TestDotLua.createCommandData("Reload command", "This command reloads a command from file", "<command>", function (playerID, args, raw_args)
- if #args == 1 then
- if TestDotLua.loadCommand(args[1]) then
- ShowMessageToPlayer(playerID, "~g~Command /" .. args[1] .. " successfully reloaded")
- else
- ShowMessageToPlayer(playerID, "~r~Failed to reload command /" .. args[1])
- end
- else
- TestDotLua.showHelpTopic(playerID, "reloadcommand")
- end
- end)
- -- Gamemode init
- function OnGameModeInit()
- print("[INIT ] Setting spawn points...")
- SetSpawnPoint(-817.657, 178.111, 75.0)
- SetSpawnPoint(-640.183, 297.111, 91.0)
- print("[INIT ] Done!")
- print("[INIT ] Loading IPLs...")
- LoadIPL("hei_carrier")
- LoadIPL("hei_carrier_DistantLights")
- LoadIPL("hei_Carrier_int1")
- LoadIPL("hei_Carrier_int2")
- LoadIPL("hei_Carrier_int3")
- LoadIPL("hei_Carrier_int4")
- LoadIPL("hei_Carrier_int5")
- LoadIPL("hei_Carrier_int6")
- LoadIPL("hei_carrier_LODLights")
- print("[INIT ] Done!")
- print("[INIT ] Loading inline code...")
- TestDotLua.loadExecutableForCallback("OnGameModeInit")
- TestDotLua.loadExecutableForCallback("OnGameModeExit")
- TestDotLua.loadExecutableForCallback("OnPlayerPickUpPickup")
- TestDotLua.loadExecutableForCallback("OnPlayerConnect")
- TestDotLua.loadExecutableForCallback("OnPlayerDisconnect")
- TestDotLua.loadExecutableForCallback("OnPlayerUpdate")
- TestDotLua.loadExecutableForCallback("OnPlayerSpawn")
- TestDotLua.loadExecutableForCallback("OnPlayerDeath")
- TestDotLua.loadExecutableForCallback("OnPlayerEnterVehicle")
- TestDotLua.loadExecutableForCallback("OnPlayerExitVehicle")
- TestDotLua.loadExecutableForCallback("OnPlayerEnterCheckpoint")
- TestDotLua.loadExecutableForCallback("OnPlayerExitCheckpoint")
- TestDotLua.loadExecutableForCallback("OnPlayerEnteringVehicle")
- TestDotLua.loadExecutableForCallback("OnPlayerExitingVehicle")
- TestDotLua.loadExecutableForCallback("OnPlayerDamage")
- TestDotLua.loadExecutableForCallback("OnPlayerShotBullet")
- TestDotLua.loadExecutableForCallback("OnProjectileImpact")
- TestDotLua.loadExecutableForCallback("OnVehicleRespawn")
- TestDotLua.loadExecutableForCallback("OnVehicleDamage")
- print("[INIT ] Done!")
- print("")
- print("===========Start===========")
- print("= Alpha test script =")
- print("= Made by BigETI (c) 2016 =")
- print("===========Start===========")
- print("")
- TestDotLua.executeInCallback("OnGameModeInit")
- return 1
- end
- -- Gamemode exit
- function OnGameModeExit()
- print("")
- print("===========Stop============")
- print("= Alpha test script =")
- print("= Made by BigETI (c) 2016 =")
- print("===========Stop============")
- print("")
- TestDotLua.executeInCallback("OnGameModeExit")
- return 1
- end
- -- Player command
- -- @param playerID : number (int)
- -- @param message : string
- function OnPlayerCommand(playerID, message)
- TestDotLua.parseCommand(playerID, message)
- TestDotLua.executeInCallback("OnPlayerCommand", playerID, message)
- return 1
- end
- -- Player message
- -- @param playerID : number (int)
- -- @param message : string
- function OnPlayerMessage(playerID, message)
- SendMessageToAll("~b~" .. GetPlayerName(playerID) .. "~w~(" .. playerID .. "): " .. message)
- TestDotLua.executeInCallback("OnPlayerMessage", playerID, message)
- return 1
- end
- -- Player pick up pickup
- -- @param pickUpID : number (int)
- -- @param playerID : number (int)
- function OnPlayerPickUpPickup(pickUpID, playerID)
- TestDotLua.executeInCallback("OnPlayerPickUpPickup", pickUpID, playerID)
- return 1
- end
- -- Player connect
- -- @param playerID : number (int)
- function OnPlayerConnect(playerID)
- SendMessageToAll("[~g~+~w~]" .. GetPlayerName(playerID) .. "(" .. playerID .. ") has joined the server")
- SetPlayerModel(playerID, 240)
- SetPlayerVisible(playerID, true)
- TestDotLua.executeInCallback("OnPlayerConnect", playerID)
- return 1
- end
- -- Player disconnect
- -- @param playerID : number (int)
- function OnPlayerDisconnect(playerID)
- SendMessageToAll("[~r~-~w~]" .. GetPlayerName(playerID) .. "(" .. playerID .. ") has left the server")
- TestDotLua.executeInCallback("OnPlayerDisconnect", playerID)
- return 1
- end
- -- Player update
- -- @param playerID : number (int)
- function OnPlayerUpdate(playerID)
- TestDotLua.executeInCallback("OnPlayerUpdate", playerID)
- return 1
- end
- -- Player spawn
- -- @param playerID : number (int)
- function OnPlayerSpawn(playerID)
- PlayerScreenFadeIn(playerID, 500)
- TestDotLua.executeInCallback("OnPlayerSpawn", playerID)
- return 1
- end
- -- Player death
- -- @param playerID : number (int)
- function OnPlayerDeath(playerID)
- PlayerScreenFadeOut(playerID, 500)
- TestDotLua.executeInCallback("OnPlayerDeath", playerID)
- return 1
- end
- -- Player enter vehicle
- -- @param playerID : number (int)
- -- @param vehicleID : number (int)
- -- @param seatID : number (int)
- function OnPlayerEnterVehicle(playerID, vehicleID, seatID)
- TestDotLua.executeInCallback("OnPlayerEnterVehicle", playerID, vehicleID, seatID)
- return 1
- end
- -- Player exit vehicle
- -- @param playerID : number (int)
- -- @param vehicleID : number (int)
- -- @param seatID : number (int)
- function OnPlayerExitVehicle(playerID, vehicleID, seatID)
- TestDotLua.executeInCallback("OnPlayerExitVehicle", playerID, vehicleID, seatID)
- return 1
- end
- -- Player exit checkpoint
- -- @param playerID : number (int)
- -- @param checkpointID : number (int)
- function OnPlayerEnterCheckpoint(playerID, checkpointID)
- TestDotLua.executeInCallback("OnPlayerEnterCheckpoint", playerID, checkpointID)
- return 1
- end
- -- Player exit checkpoint
- -- @param playerID : number (int)
- -- @param checkpointID : number (int)
- function OnPlayerExitCheckpoint(playerID, checkpointID)
- TestDotLua.executeInCallback("OnPlayerExitCheckpoint", playerID, checkpointID)
- return 1
- end
- -- Player entering vehicle
- -- @param playerID : number (int)
- -- @param vehicleID : number (int)
- -- @param seatID : number (int)
- function OnPlayerEnteringVehicle(playerID, vehicleID, seatID)
- TestDotLua.executeInCallback("OnPlayerEnteringVehicle", playerID, vehicleID, seatID)
- return 1
- end
- -- Player exiting vehicle
- -- @param playerID : number (int)
- -- @param vehicleID : number (int)
- -- @param seatID : number (int)
- function OnPlayerExitingVehicle(playerID, vehicleID, seatID)
- TestDotLua.executeInCallback("OnPlayerExitingVehicle", playerID, vehicleID, seatID)
- return 1
- end
- -- Player damage
- -- @param playerID : number (int)
- -- @param damagerID : number (int)
- -- @param amount : number (int)
- function OnPlayerDamage(playerID, damagerID, amount)
- TestDotLua.executeInCallback("OnPlayerDamage", playerID, damagerID, amount)
- return 1
- end
- -- Player shot bullet
- -- @param playerID : number (int)
- -- @param weapon : string
- function OnPlayerShotBullet(playerID, weapon)
- TestDotLua.executeInCallback("OnPlayerShotBullet", playerID, weapon)
- return 1
- end
- -- Projectile impact
- -- @param playerID : number (int)
- -- @param weapon : string
- -- @param x : number (float)
- -- @param y : number (float)
- -- @param z : number (float)
- -- @param entityType : string
- -- @param entityID : number (int)
- -- @param entityBone : number (int)
- function OnProjectileImpact(playerID, weapon, x, y, z, entityType, entityID, entityBone)
- TestDotLua.executeInCallback("OnProjectileImpact", playerID, weapon, x, y, z, entityType, entityID, entityBone)
- return 1
- end
- -- Vehicle respawn
- -- vehicleID : number (int)
- function OnVehicleRespawn(vehicleID)
- TestDotLua.executeInCallback("OnVehicleRespawn", vehicleID)
- return 1
- end
- -- Vehicle damage
- -- vehicleID : number (int)
- -- playerID : number (int)
- -- engineDamageID : number (int)
- -- fuelDamage : number (int)
- function OnVehicleDamage(vehicleID, playerID, engineDamageID, fuelDamage)
- TestDotLua.executeInCallback("OnVehicleDamage", vehicleID, playerID, engineDamageID, fuelDamage)
- return 1
- end
Advertisement
Add Comment
Please, Sign In to add comment