Hey there! Im trying to make a script, that makes the player “half way invisible” (Like in GTA Online Passive Mode)… so basically this is what I tried:
xPlayer is not an entity. It’s an object. A collection of player data and functions.
You need to provide SetEntityAlpha with an entity. SetEntityAlpha(PlayerPedId(), 102, false) or similar.
And if that still doesn’t work, change the false to true, to also change the alpha of the ped’s skin.
RegisterNetEvent('alphaClients')
AddEventHandler('alphaClients', function(author)
local player = PlayerPedId(author)
local playerAlpha = GetEntityAlpha(player)
if playerAlpha == 102 then
SetEntityAlpha(player, 255, false)
else
SetEntityAlpha(player, 102, false)
end
end)
What im trying to do is to set my alpha to 100 so that all players see me like that. The problem here is, that when I type in the command, Im showing transparent, to myself, but on my friends screen, he is also transparent but not me. So basically everybody turns transparent for himself but nobody sees others as transparent yk? (Sry I rly cant explain that good)
Nah, the way you explained it made sense. And based on that code it makes sense too.
Also, you are trying to pass PlayerPedId a server ID but you can’t do that. PlayerPedId gets your own ped, GetPlayerPed will get another ped when passed a CLIENT Player ID. So to get a ped from a server ID, we do the following on the client; GetPlayerPed(GetPlayerFromServerId(author)) where author is a server ID.
Anyway, try this;
Server:
local alphaClients = {}
RegisterCommand('alpha', function(source, rawCommand)
alphaClients[source] = alphaClients[source] and nil or true
TriggerClientEvent('alphaClients', -1, source, alphaClients[source])
end)
Client:
local alphaClients = {}
RegisterNetEvent('alphaClients', function(author, enable)
local targetPed = GetPlayerPed(GetPlayerFromServerId(author))
if enable then
SetEntityAlpha(targetPed, 102, false)
alphaClients[author] = targetPed
else
ResetEntityAlpha(targetPed)
alphaClients[author] = nil
end
end)
CreateThread(function()
while true do
Wait(0)
for src, ped in pairs(alphaClients) do
SetEntityAlpha(ped, 102, false)
end
end
end)
okayy… so basically its half-way working… when I do /alpha i turn transparent on my screen and on my firends screen. The only problem is, that players who are far away from the command author also turn transparent but players who stand directly next to the author remain normal… do u have a last idea for that?