[HELP] Create INI File

Hello,

I have recently started building my own framework and have run into some issues.

The framework will be menu based and I need a way to save player data.

I want to avoid MYSQL because I dont know it, but I do know that ARMA servers sued to use INI files to save player data. I am familiar with INI files and therefore would like to use them instead.

I found this LUA to INI parser on GitHub, included it in my resource but nothing works.

Here are my scripts:

PlayerConnecting:

AddEventHandler('playerConnecting', function()
    TriggerServerEvent('ReadPlayerSave')
end)

ReadPlayerSave:

local ped = GetPlayerPed(-1)

print("Catraz RP 'Saving': Variables Loaded")

RegisterServerEvent('ReadPlayerSave')
AddEventHandler('ReadPlayerSave',function()
    local data = LIP.load(getPlayerEndpoint(source)..'.ini');

    SetPedCoordsKeepVehicle(ped, data.PlayerInformation.posX, data.PlayerInformation.posY, data.PlayerInformation.posZ)
    SetEntityHeading(ped, data.PlayerInformation.posHeading)
    print("Catraz RP 'Saving': Player Information Loaded")
end)

print("Catraz RP 'Saving': Event Loaded")

PlayerDropped:

AddEventHandler('playerDropped', function(reason)
    TriggerServerEvent('CreatePlayerSave')
end)

CreatePlayerSave:

local ped = GetPlayerPed(-1)
local pedX, pedY, pedZ = table.unpack(GetEntityCoords(ped, true))
local pedHeading = GetEntityHeading(GetPlayerPed(-1))

print("Catraz RP 'Saving': Variables Loaded")

RegisterServerEvent('CreatePlayerSave')
AddEventHandler('CreatePlayerSave',function()
    local data =
    {
        PlayerInformation =
        {
            posX = pedX,
            posY = pedY,
            posZ = pedZ,
            posHeading = pedHeading,
        },
    };

    -- Data saving
    LIP.save(getPlayerEndpoint(source)..'.ini', data);
    print("Catraz RP 'Saving': Player Information Saved")
end)

print("Catraz RP 'Saving': Event Loaded")

I know its not ideal to just post my stuff but if anyone knows the reason its not working, id love you forever.

Thanks
Harry Catraz

Don’t use getplayerendpoint() use local player = GetPlayerIdentifers(source)[1] and then use ””..player..”.ini”

Also you need to send these as variables with the server request. They can’t work server side.

local ped = GetPlayerPed(PlayerId())
local pedX, pedY, pedZ = table.unpack(GetEntityCoords(ped, true))
local pedHeading = GetEntityHeading(ped)

So say in player connecting where I use
TriggerServerEvent('ReadPlayerSave')

I should use this instead

local ped = GetPlayerPed(-1)
local pedX, pedY, pedZ = table.unpack(GetEntityCoords(ped, true))
local pedHeading = GetEntityHeading(GetPlayerPed(-1))
local player = GetPlayerIdentifers(source)[1]
TriggerServerEvent('ReadPlayerSave', ped, pedX, pedY, pedZ, pedHeading, player)

to pass the variables to the function and then add them as input serverside using

RegisterServerEvent('ReadPlayerSave')

AddEventHandler('ReadPlayerSave',function(ped, pedX, pedY, pedZ, pedHeading, player)

Is this correct?

Kind Reagrds,
Harry Catraz

Yes that’s it. But one thing that I’m think about now is playerconnecting is a server side only event. And cannot be “handled” in a client script but I might be wrong. The client equivalent would be OnPlayerMapSpawn or something like that (look it up)

found it I think its playerSpawned.

Testing now.

You’re setting the player’s ped before their ped has actually loaded in. Using the playerSpawned event would fix this :wink: .