Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution for servers using esx_multicharacter #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lush0n3
Copy link

@lush0n3 lush0n3 commented Dec 20, 2023

Added a fix to prevent player coordinates error when connecting. multicharacter is not recognized by the player immediately and this causes this error.

SCRIPT ERROR: @dream-postal/client.lua:755: attempt to perform arithmetich on a nil value (upvalue 'POSTAL_BOSS_COORDS')

fn (@dream-postal/client.lua:755)

You can improve it and adapt it to your programming style, I just added it to offer a solution!

Added a fix to prevent player coordinates error when connecting. multicharacter is not recognized by the player immediately and this causes this error.

SCRIPT ERROR: @dream-postal/client.lua:755: attempt to perform arithmetich on a nil value (upvalue 'POSTAL_BOSS_COORDS')
> fn (@dream-postal/client.lua:755)

You can improve it and adapt it to your programming style, I just added it to offer a solution!
Copy link
Owner

@kylemcshea kylemcshea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left some ideas for consideration. Overall I like the approach and this does sound annoying with esx having the game be spammed with trying to have player coords be indexed

@@ -1,3 +1,21 @@
FRAMEWORK = nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block of code is held globally within client_util.lua, BUT i think it's loaded afterwards -> https://github.com/kylemcshea/dream-postal/blob/master/fxmanifest.lua#L18

So we can go with 1 of 2 routes

  1. Delete this block of code and within fxmanifest.lua we have client_util.lua loaded up before client.lua
  'client_util.lua',
  'client.lua',
  1. we delete this block of code from client_util.lua and leave everything as is. I'm down for either.

I'll leave the decision to you :) we just dont want duplicate blocks of code is the only thing we are looking to move from

isPedSpawned = true
spawnPostalBossPed()
end
if (Config.FRAMEWORK == 'esx') then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change would break qb compatibility. Here's what I propose to decouple and for us to be more pure!

modify this thread to be

CreateThread(function()
    local spawnFunction = Config.FRAMEWORK == 'qb' and handlePedSpawnQB or handlePedSpawnESX
    while true do
        Wait(2000)
        spawnFunction()
    end
end)

we make two functions

function handlePedSpawnESX()
    local isLoaded = FRAMEWORK.IsPlayerLoaded()
    
    if not isLoaded then
        return
    end
    
    local playerCoords = GetEntityCoords(PlayerPedId())
    local distanceFromPed = #(POSTAL_BOSS_COORDS - playerCoords)

    if distanceFromPed < 200 and not isPedSpawned then
        isPedSpawned = true
        spawnPostalBossPed()
    end

    if postalBossPed and distanceFromPed >= 200 and isPedSpawned then
        isPedSpawned = false
        DeletePed(postalBossPed)
    end
end
function handlePedSpawnQB()
        local playerCoords = GetEntityCoords(PlayerPedId())
        local distanceFromPed = #(POSTAL_BOSS_COORDS - playerCoords)

        if distanceFromPed < 200 and not isPedSpawned then
            isPedSpawned = true
            spawnPostalBossPed()
        end

        if postalBossPed and distanceFromPed >= 200 and isPedSpawned then
            isPedSpawned = false
            DeletePed(postalBossPed)
        end
end

Let me know your thoughts!
@Misha0717 If you see this notification would love for you to chime in and throw a second opinion :)

Copy link
Contributor

@Misha0717 Misha0717 Dec 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good imo. But I should change the isPedSpawned variable to DoesEntityExist(postalBossPed) instead of a boolean. The functions should show like this.

function handlePedSpawnQB()
        local playerCoords = GetEntityCoords(PlayerPedId())
        local distanceFromPed = #(POSTAL_BOSS_COORDS - playerCoords)
        local isPedSpawned = DoesEntityExist(postalBossPed)

        if distanceFromPed < 200 and not isPedSpawned then
            spawnPostalBossPed()
        end

        if distanceFromPed >= 200 and isPedSpawned then
            DeletePed(postalBossPed)
        end
end

I have never worked with multicharacter from ESX so I don't know if the fix of @lush0n3 so fix the issue. But if he tested it and it works fine I think this pr could be merged

@kylemcshea kylemcshea added the good first issue Good for newcomers label Dec 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants