[How-To] Create a basic script

@pongo1231 you can add that plz ?

List of native function is here > List of native functions

What data return a funtion, you can use > Native

for showing data from F8 you can use Citizen.Trace


now someone can tell me how can fing data from this ?

local pos = GetEntityCoords(player)

how can find x, y and y inside pos if i don’t know is exist ??? (pos.x, pos.y, pos.z)

Thank you so much Scammer!

Thank you for this awsome resource.

what shud i be editing this on c++ or somethaing else

um so how would it be if you wanted it to say Welcome ‘user’ to this server. ‘user’ would change for each person that joins?

I believe this would work. I have not tried it though. @Xnitro67

-- SERVER --
RegisterServerEvent("welcomeMessage")
AddEventHandler("welcomeMessage", function(id)
	local name = GetPlayerName(id)
	TriggerClientEvent("chatMessage", -1, "WELCOME", {255,0,0}, name .. " to the server!")
end)

-- CLIENT --
AddEventHandler("onClientMapStart", function()
	local serverId = GetPlayerServerId(PlayerId())
	TriggerServerEvent("welcomeMessage", serverId)
end)
1 Like

omg thank you it works

1 Like

That’s better, you can use GetPlayerName with ‘source’ @Xnitro67

-- SERVER --
RegisterServerEvent("welcomeMessage")
AddEventHandler("welcomeMessage", function()
	TriggerClientEvent("chatMessage", -1, "WELCOME", {255,0,0}, GetPlayerName(source).. " to the server!")
end)

-- CLIENT --
AddEventHandler("playerSpawned", function()
	TriggerServerEvent("welcomeMessage")
end)
1 Like

Could someone private message me and help me with the following, I am quite new to learning Lua, but I’ve picked it up quickly and I’m learning well.

I’ve started to learn Lua purely for GTA V use ONLY. I’ve gone to the Natives DB (http://www.dev-c.com/nativedb/) and I am unsure how I should use these natives in a working script. I am wanting to make a script that does the following, this is for learning purposes and I understand a script like this may have been done before, however I am doing it for my own benefit.

  • Script checks to make sure player is alive
  • Script checks to make sure player is not cuffed.
  • Script checks to make sure player is near a vehicle.
  • Script makes sure the target vehicle is stopped.
  • Script then checks to make sure target vehicle is upside down/on roof
  • Script then sets vehicle on ground properly.

However when I go to create this, I get confused, as I feel the natives located on that DB are for C language.

Could someone give me a basic idea of how the natives work, the syntax and how they should be structured for Lua only.

I would be eternally grateful.

https://wiki.fivem.net/wiki/Client_functions
has all information you might need.
In short, a C++ NATIVE_NAME_GOES_HERE is invoked in Lua with NativeNameGoesHere.
Also pointers ( the * thingies) in C++ are generally returned values in Lua.

example:
GET_SCREEN_RESOLUTION(int* x, int* y)
is done in Lua with:
x, y = GetScreenResolution()

2 Likes

I just wrote this real quick based on what you told me, this is the FIRST TIME i’ve applied Lua to GTA so please tell me where I am fucking up, if I am.

RegisterNetEvent('lupo:unflip')
AddEventHandler('lupo:unflip', function()

local playerPed = GetPlayerped(-1)
local targetVehicle = GetVehiclePedIsIn(playerPed, true)
local checkCuffs = IsPedCuffed(playerPed)
local checkHeartbeat = IsPedDead(playerPed)
local checkBrakes = IsVehicleStopped(targetVehicle)

-- Act on the information
if(checkCuffs(0)) then
  if(checkHeartbeat(0)) then
    if(checkBrakes(1)) then
          
          SetVehicleOnGroundProperly(targetVehicle)
          TriggerEvent("chatMessage", "[lupoFlipping:]", {255, 255, 0}, "The vehicle has been put on the ground properly.")
          
        else
          TriggerEvent("chatMessage", "[lupoFlipping:]", {255, 255, 0}, "You are either dead, handcuffed or the vehicle is moving, try again!")
    end
  end
end
end)

local targetVehicle = nil


Why are you passing parameters to checkCuffs, checkHeartbeat? Those are not functions, you defined them as variables.
For the rest I think that’s fine :slight_smile:

if(checkCuffs(0))
Would that not call the variable above?
local checkCuffs = IsPedCuffed(playerPed)

RookieError?

You don’t call variables.
local checkCuffs = IsPedCuffed(playerPed) does the following:

  1. call IsPedCuffed with argument playerPed
  2. store the result in checkCuffs.
    checkcuffs is a boolean variable, not a function.

Pretty rookie yeah.

I now understand. So this would work?


RegisterNetEvent('lupo:unflip')
AddEventHandler('lupo:unflip', function()

local playerPed = GetPlayerped(-1)
local targetVehicle = GetVehiclePedIsIn(playerPed, true)
local checkCuffs = IsPedCuffed(playerPed)
local checkHeartbeat = IsPedDead(playerPed)
local checkBrakes = IsVehicleStopped(targetVehicle)

-- Act on the information
if checkCuffs = 0 then
  if checkHeartbeat = 0 then
    if checkBrakes = 1 then
          
          SetVehicleOnGroundProperly(targetVehicle)
          TriggerEvent("chatMessage", "[lupoFlipping:]", {255, 255, 0}, "The vehicle has been put on the ground properly.")
          
        else
          TriggerEvent("chatMessage", "[lupoFlipping:]", {255, 255, 0}, "You are either dead, handcuffed or the vehicle is moving, try again!")
    end
  end
end
end)

local targetVehicle = nil


Boolean comparison is done with double equals sign and true/false.
checkCuffs == false for example.
For conciseness you can just omit the ==false or ==true really.

As for if it would work, why not try it yourself? :slight_smile:

Ah I see :smiley: Thank you!
I’d try, but I’m at work with no GTA access :frowning: just learning whole being bored.

This still works in the new FXserver update right?

1 Like

If anyone could help, how would I trigger a message by someone typing a command. Like if someone typed “/discord” it would say my discord, if that makes sense

This is probably quite a dumb question, but how would I go abouts with creating a client-side script, rather than a server-side script?