0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【FiveM】コード(ネイティブ関数など) 備忘録

Last updated at Posted at 2025-08-24

サーバー最大接続人数の取得

maxPlayer = GetConvarInt('sv_maxclients', 64)

RegisterNetEvent

イベント名が問い合わせられたらこの処理を実行する

RegisterNetEvent('イベント名', function(受け取るデータ) ... end)

OnPlayerLoaded

キャラクター選択後にプレーヤーのロードを処理する

RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()
end)

TriggerClientEvent

サーバーからクライアントへ、イベント名にデータを送る
ターゲットID:
- srcは通信している相手のみ
- -1はサーバーに接続しているすべてのプレイヤーに

TriggerClientEvent('イベント名', ターゲットID, 送るデータ)

IsControlJustPressed

キーが押されたとき

IsControlJustPressed(0, 212)

IsControlJustReleased

キーを離したとき

IsControlJustReleased(0, 212)

スクリプトのバージョン取得

第1引数にスクリプト名、第2引数にどの項目か、第3引数には何番目のかを
第3引数についてだが、versionというのが2つあった場合上から数えてのことだけど、2つ書くというケースはないだろうから、0を入れると覚えればいいはず

server.lua
local currentVersion = GetResourceMetadata(GetCurrentResourceName(), 'version', 0)

PerformHttpRequest()

HTTPリクエスト、ウェブサイトやファイルにインターネット経由でアクセスするための命令
第1引数:URL、第2引数:何をするか(コールバック関数)

PerformHttpRequest(string url, function callback(number statusCode, string body, table headers, string errorData), string method = 'GET', string data = '', table headers = {}, table options = { followLocation = true })
sample.lua
local url = "https://example.com/version.txt"

-- PerformHttpRequestでURLにアクセス
PerformHttpRequest(url, function(err, responseText, headers)
    -- 通信が成功したかチェック (HTTPステータスコード200が成功)
    if err == 200 then
        -- 取得したresponseTextを使ってバージョン比較などの処理を行う
        local latestVersion = responseText
        print("最新バージョンは: " .. latestVersion)
    else
        -- 通信失敗時の処理
        print("バージョン情報の取得に失敗しました。")
    end
end)

SetNuiFocus

UIなのか判別させるために使う
簡単に言えば第1引数がtrueならUIが上側になり、ゲーム操作からUIの操作に移る。

SetNuiFocus(true, true)
SetNuiFocus(false, false)

プレイヤーの現金、口座残高取得

local cash = PlayerData.money.cash
local bank = PlayerData.money.bank

リソース名の取得

ResourceName = GetCurrentResourceName()
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?