National War's structure aims to be optimised and developer friendly as much as possible, therefore you must follow specific layouts and uses
Events
As any developer knows, events are crucial in the FiveM enviroment, therefore you must follow the following in the following cases
Client to client // Server to server
In these cases there is no need of using RegisterNetEvent , therefore use only AddEventHandler
Server to client
In the client side you must set up an event that is similar to this structure
-- Example usage of event in the client-sideRegisterNetEvent("nw:cl:{module}:{action}", function(args)print(args)end)-- Example fill for {module} and {action}RegisterNetEvent("nw:cl:chat:sendMessage", function(player,message)print(("Player %s has said %s."):format(player, message))end)
Client to server
The structure is similar for "Server to client", but instead of starting with "nw:cl" we start with "nw:sv"
The server events must be secured in order to protect the server from exploiters
A check must be made for what ever the event is for
Built in
There's a lot of built in inside the development environment, and the most important is the following:
No use of CreateThread, Wait, etc... , when you code make sure to include Citizen. where it should be
-- Example for updating the player's safezone state
-- server-side
RegisterNetEvent("nw:sv:safezone:leftZone", function()
local player = source
local xPlayer = PlayerData.Get(player)
if not xPlayer then
return
end
if #(xPlayer.coords() - Safezone.Coords) < Safezone.Radius then
-- Player is still inside the safezone
return
end
-- Update the player state
end)
-- Rejected code
CreateThread(function()
while true do
-- something
Wait(0)
end
end)
-- Approved code
Citizen.CreateThread(function()
while true do
-- something
Citizen.Wait(0)
end
end)