Skip to content

Commit

Permalink
See all players if map is collected.
Browse files Browse the repository at this point in the history
  • Loading branch information
Switty6 authored Dec 29, 2019
1 parent fa3d4a6 commit 12a46fb
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 1 deletion.
3 changes: 2 additions & 1 deletion __resource.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ client_scripts {
"spawning/cl_player.lua",
"spawning/cl_zombies.lua",
"spawning/cl_savezones.lua",
"cl_hud.lua"
"cl_hud.lua",
"cl_map.lua"
}
105 changes: 105 additions & 0 deletions cl_map.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
--[[TO DO:
*Add good places for map locations
*Make the map to be stored on player and only if map in inventory then show all players--]]
local Map = "prop_tourist_map_01"
local MapCoords ={
{x= 719.52940, y= -963.195, z=31.3872},
}
local Maps = {}
local collected = false

Citizen.CreateThread(function()
AddEventHandler('playerSpawned', function()
Citizen.CreateThread(function()
for _, prop in ipairs(MapCoords) do
MapSpawning = CreateObject(GetHashKey(Map), prop.x, prop.y, prop.z - 1, false, false, true)

blip = AddBlipForEntity(MapSpawning)
SetBlipSprite(blip, 274)
SetBlipAsShortRange(blip, true)
SetBlipAlpha(blip, 255)
SetBlipScale(blip, 0.5)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString('Map')
EndTextCommandSetBlipName(blip)
table.insert(Maps, MapSpawning)
end
end)
end)

Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
for i, MapSpawning in pairs(Maps) do
playerX, playerY, playerZ = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))

This comment has been minimized.

Copy link
@ghermans

ghermans Dec 30, 2019

Contributor

you don't need to unpack GetEntityCoords instead use this

local playerCoords = GetEntityCoords(PlayerPedId(), true)
if(Vdist(playerCoords.x, playerCoords.y, playerCoords.z, propX, propY, propZ) < 1.5) then
  -- do something
end

This comment has been minimized.

Copy link
@Switty6

Switty6 Dec 30, 2019

Author

Thank you. I’ll take that in consideration and I’ll modify as soon as I’m able to.

propX, propY, propZ = table.unpack(GetEntityCoords(MapSpawning, true))
if(Vdist(playerX, playerY, playerZ, propX, propY, propZ) < 1.5) then
DisplayHelpText("Press ~INPUT_CONTEXT~ to get the map.")
if IsControlJustReleased(1, 51) then
ShowNotification("Picked up: ~g~[Map]")
DeleteObject(MapSpawning)
RemoveBlip(blip)
table.remove(Maps, i)
collected = true
end
end
if IsPedDeadOrDying(PlayerPedId(), 1) == 1 then
DeleteObject(MapSpawning)
RemoveBlip(blip)
table.remove(Maps, i)
end
end
if collected == true then
DisplayAllMap()
end
if IsPedDeadOrDying(GetPlayerPed(-1),1) then
collected == false
end
end
end)

function DisplayAllMap()
local blips = {}
local xPlayer = PlayerId()

while true do
Wait(100)
local players = ShowPlayers()
for player = 0, NetworkGetNumConnectedPlayers() do
if player ~= xPlayer and NetworkIsPlayerActive(player) then
local ped = GetPlayerPed(player)
local playerName = GetPlayerName(player)
RemoveBlip(blips[player])
local new_blip = AddBlipForEntity(playerPed)
SetBlipNameToPlayerName(new_blip, player)
SetBlipColour(new_blip, 4)
SetBlipCategory(new_blip, 2)
SetBlipScale(new_blip, 0.3)
blips[player] = new_blip
end
end
end
end
function ShowPlayers()
local players = {}

for i = 0, NetworkGetNumConnectedPlayers() do
if NetworkIsPlayerActive(i) then
table.insert(players, i)
end
end

return players
end

function DisplayHelpText(str)
SetTextComponentFormat("STRING")
AddTextComponentString(str)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
end

function ShowNotification(text)
SetNotificationTextEntry("STRING")
AddTextComponentString(text)
DrawNotification(false, false)
end

0 comments on commit 12a46fb

Please sign in to comment.