PlayerPedId()

Hello, im trying to create a script, where the ooc chat is sent to players near me.

AddEventHandler('chatMessage', function(source, name, msg)
    sm = stringsplit(msg, " ");
    if string.find(sm[1], "/") then return end
    CancelEvent()
    local playerPed = PlayerPedId()
    local playerPos = GetEntityCoords(playerPed)
    local targetPos = GetEntityCoords(ped)
    local dist = #(playerPos - targetPos)
    if dist <= 20 then
    TriggerClientEvent('chat:addMessage', -1, {
        color = { 255, 255, 255 },
        multiline = true,
        --args = { text}
        template = '<div style="padding: 0.35vw; margin: 0; background-color: rgba(0, 0, 0, 0.6); border-radius: 5px;"><i class="fas fa-user-crown"></i> {0} </div>',
        args = { "> ^5ooc^7 | " .. name .. " [" .. source .. "] : " .. string.sub(msg,1) }
    })
    end
end) 

function stringsplit(inputstr, sep)
    if sep == nil then
        sep = "%s"
    end
    local t={} ; i=1
    for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
        t[i] = str
        i = i + 1
    end
    return t
end

This is the whole script, but the problem is that i get an error:

Anyone have an idea how to make this work? Thank you! :slight_smile:

1 Like

Wild guess, make sure the resource that block of code is in is running on a fxmanifest.lua (NOT __resource.lua) and it has the latest fx_version defined.

This is my fxmanifest.lua:

fx_version 'cerulean'
game 'gta5'

server_script 'server.lua'

Im pretty sure the fx version is the latest one :confused:

PlayerPedId isn’t going to work server side is it… it doesn’t know who you are talking about

1 Like

im kinda new to this, i tried to write a simple function on client side but im not sure how to call it so it gets the value… Could you help me out? Thank you

any way to make a function on client side that gets the dist value and just get it on server side?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.