RedEM-RP / redemrp_inventory

An Inventory System for RedEM:RP
GNU General Public License v3.0
13 stars 21 forks source link

pb delete item after use ("bread" or "water") #40

Open heretic08000 opened 2 years ago

heretic08000 commented 2 years ago

First of all, I'm sorry for my English but I use a translator :-)

I would like to post my problem because I can't find out where the problem comes from. The problem is that when I want to use the bread or water in my inventory, it is taken into account in "redemrp_status" but the item is not counted and I have an error message in the console of the server that is :

image

From what I could see, the "redemrp:getPlayerFromId" function would return "null" instead of the ID of my character (at least that's what I think) so any idea how to fix this? I specify that I use the official Redemrp_roleplay framework, redemrp_inventory-2.0 and that all dependencies are Ok

Thanks in advance for any help you can give me

Nb : I tried to change the redemrp_roleplay, redemrp_status, coming from another source and the pb is the same

abdulkadiraktas commented 2 years ago

Can you send "RegisterUsableItem" side?

heretic08000 commented 2 years ago

first of all thank you for your help

Citizen.CreateThread(function()
    for name, info in pairs(Config.Items) do
        RegisterServerEvent("RegisterUsableItem:" .. name)
        AddEventHandler("RegisterUsableItem:" .. name, function(source)
            TriggerEvent('redemrp:getPlayerFromId', source, function(user)
                local identifier = user.getIdentifier()
                local charid = user.getSessionVar("charid")
                PlayersStatus[identifier .. "_" .. charid].hunger = PlayersStatus[identifier .. "_" .. charid].hunger + info.hunger
                PlayersStatus[identifier .. "_" .. charid].thirst = PlayersStatus[identifier .. "_" .. charid].thirst + info.thirst
                if PlayersStatus[identifier .. "_" .. charid].hunger > 100.0 then PlayersStatus[identifier .. "_" .. charid].hunger = 100 end
                if PlayersStatus[identifier .. "_" .. charid].thirst > 100.0 then PlayersStatus[identifier .. "_" .. charid].thirst = 100 end
                local ItemData = Inventory.getItem(tonumber(PlayersStatus[identifier .. "_" .. charid].source), name)
                ItemData.RemoveItem(1)
                TriggerClientEvent('redemrp_status:UpdateStatus', tonumber(PlayersStatus[identifier .. "_" .. charid].source), PlayersStatus[identifier .. "_" .. charid].thirst, PlayersStatus[identifier .. "_" .. charid].hunger)
                info.action(tonumber(PlayersStatus[identifier .. "_" .. charid].source) , name)

            end)
        end)
    end
end)

this is the part of the code used by redemrp_status on the server side

heretic08000 commented 2 years ago

And this, it's a config.lua in redemrp_status :

Config = {}
Config.Items = {

    ["water"] = {
        hunger = 0,
        thirst = 25,
        action = function(source, name)
            TriggerClientEvent('redemrp_status:Action-' .. name, source)
        end,
        ClientAction = function()
            Drink()
            BoostStamina(20)
            -- YOU CAN USE HERE ELSE CLIENT CODE
            -- print("water used") etc
        end
    },

    ["bread"] = {
        hunger = 25,
        thirst = 0,
        action = function(source, name)
            TriggerClientEvent('redemrp_status:Action-' .. name, source)
        end,
        ClientAction = function()
            Eat()
            BoostStamina(20)
        end
    },
}
abdulkadiraktas commented 2 years ago

This is not an inventory issue. First of all, if you restart the status script after your character is loaded and logged into the game, you will run into problems. If you are restarting the status script, you need to reload your character. You can use the sc 1 command for this or restart the redemrp_identity script. sc 1 means select first character. You can use sc 2, sc 3 etc.

heretic08000 commented 2 years ago

Indeed, it was not a problem of inventory, but the script "redemrp_status" start before those of the management of the character, my bad ^^ thank you very much for the help ;-)