example
example

教程 有用的函数(持续更新)

  • 主题发起人 主题发起人 Yann
  • 开始时间 开始时间

Yann

站长
管理成员
GTAOS管理组
认证卖家
认证用户
黄金
263.11G

各位有好用不错的函数也可以留言补充

getPedHeadCoords 获取Ped头部世界坐标​

获取Ped头部世界坐标
Lua:
function getPedHeadCoords(ped)
    local coords = GetWorldPositionOfEntityBone(ped, GetPedBoneIndex(ped, 31086))
    coords = coords == vector3(0, 0, 0) and GetEntityCoords(ped) + vector3(0, 0, 0.9) or coords + vector3(0, 0, 0.3)
    local frameTime  = GetFrameTime()
    local vel = GetEntityVelocity(ped)
    coords = vector3(coords.x + vel.x * frameTime, coords.y + vel.y * frameTime, coords.z + vel.z * frameTime)
    return coords
end

DrawText3D 一个函数绘制多段文字,并且自定义每段文字相对位置偏移、尺寸和颜色​

Lua:
function DrawText3D(coords, texts, scale, alpha)
    scale = scale or 1

    SetDrawOrigin(coords)

    for _, text in pairs(texts) do
        SetTextScale((text.scale or 0.3) * scale, (text.scale or 0.3) * scale)
        SetTextFont(0)

        local r, g, b = table.unpack(text.color or { 255, 255, 255, alpha })
        r = r or 255
        g = g or 255
        b = b or 255

        SetTextWrap(0.0, 1.0)
        SetTextColour(r, g, b, math.floor(alpha))
        SetTextOutline()
        SetTextCentre(true)
        BeginTextCommandDisplayText("STRING")
        AddTextComponentString(text.text)

        local x, y = table.unpack(text.pos or { 0, 0 })
        EndTextCommandDisplayText(x or 0, y or 0)
    end

    ClearDrawOrigin()
end
 
最后编辑:

绘制屏幕文本​

Lua:
function DrawScreenText(text, coordsx, coordsy, colorr, colorg, colorb, colora, size) 

        SetTextFont(0)

        SetTextProportional(0)

        SetTextScale(0.0, size)

        SetTextColour(colorr, colorg, colorb, colora)

        SetTextDropshadow(0, 0, 0, 0, 255)

        SetTextEdge(1, 0, 0, 0, 255)

        SetTextDropShadow()

        SetTextOutline()

        SetTextEntry("STRING")

        AddTextComponentString(text)

        DrawText(coordsx, coordsy)

end
 
由版主最后编辑:

左上角提示​

Lua:
function helpMessage(text, duration)
    BeginTextCommandDisplayHelp("STRING")
    AddTextComponentSubstringPlayerName(text)
    EndTextCommandDisplayHelp(0, false, true, duration or 5000)
end
 
由版主最后编辑:

冻结/解冻 玩家​

代码:
function FreezePlayer(state)
    if GetPedInVehicleSeat(GetVehiclePedIsIn(GetPlayerPed(-1)), -1) == GetPlayerPed(-1) then
        FreezeEntityPosition(GetVehiclePedIsUsing(GetPlayerPed(-1)), state)
    else
        FreezeEntityPosition(PlayerPedId(), state)
    end
end
 
由版主最后编辑:

左下角提示​

Lua:
function notify(text)
    SetNotificationTextEntry("STRING")
    AddTextComponentString(text)
    DrawNotification(true, true)
end
 
由版主最后编辑:
function AddEntityBlip(id, Entity, Colour, Category, Scale) --为实体添加图标
blips[id] = AddBlipForEntity(Entity)
SetBlipColour(blips[id], Colour)
SetBlipCategory(blips[id], Category)
SetBlipScale(blips[id], Scale)
end
 

传送至坐标​

Lua:
function teleportToCoord(x, y, z, heading)
    Citizen.Wait(1)
    local player = GetPlayerPed(-1)
    if IsPedInAnyVehicle(player, true) then
        SetEntityCoords(GetVehiclePedIsUsing(player), x, y, z)
        Citizen.Wait(100)
        SetEntityHeading(GetVehiclePedIsUsing(player), heading)
    else
        SetEntityCoords(player, x, y, z)
        Citizen.Wait(100)
        SetEntityHeading(player, heading)
    end
end
 
由版主最后编辑:
后退
顶部