[Solved]A very little code don't work

Hi,

I’m don’t understand but this code do nothing: (it’s near cable car)

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0, 0, 0, 0, 0, 0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0, 0, 0, 0, 0, 0, 4, 4, 1000, 255, 255, 0, 255, 0, 0, 2, 0, 0, 0, 0)
    end
end)

Any idea?

Thanks

DrawMarker(1, -921.1211, 4828.44, 1.635, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)
DrawMarker(1, -921.1211, 4828.44, 1.635, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 4.0, 1000.0, 255, 255, 0, 255, 0, 0, 2, 0, 0, 0, 0)

Anything that says “float” needs to be a decimal number. Even if it is 0, it has to be 0.0. A lot of the numbers you had put in weren’t floats.

I tested this code here, and it works. I had the same problem a while ago and pulled my hair out going mad trying to figure it out.

1 Like

ok, it’s become wired: I copy/paste your lines, and that not work!

The code from first post it just a short version of another code that just work half:

Citizen.CreateThread(function()
--    Wait(100)
    while true do
        Citizen.Wait(1)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0, 0, 0, 0, 0, 0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)
        --if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -902.648, 4811.57, 303.749, true) > 2 then
            DrawMarker(1, -921.1211, 4828.44, 1.635, 0, 0, 0, 0, 0, 0, 4, 4, 1000.0, 255, 255, 0, 75, 0, 0, 2, 0, 0, 0, 0)
        --end
        if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, true) > 500.981 then
            endScreen = true
            EndScreen("You will dead in 10 secondes", "DeathFailOut")
            timer = GetGameTimer()
            if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, true) > 500.981 then
                if GetGameTimer() > timer + 10000 then
                    SetEntityHealth(GetPlayerPed(-1),  0)
                end
            end
            Wait(10000)  
        end
        if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, true) < 500.981 then
            endScreen = false
            StopScreenEffect("DeathFailOut")
        end
        if IsPedFatallyInjured(PlayerPedId()) then
            Wait(2500)
            GiveAWeapon()
        end
        --for i = 1, #weaponCoords do
            --weaponPos = weaponCoords[i]
           
       -- end
    end
end)

The first DrawMarker work, the second not… I have another problem to: at start, the player is inside the range GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, true) > 500.981
But the game do this when starting:
EndScreen("You will dead in 10 secondes", "DeathFailOut")

All of that make me completly mad!

I change the line you give me in this code right here, and that work now… (for DrawMarker)

Thanks a lot!

No problem. Are you still having problems with the “you will be dead in 10 seconds” thing?

Yep, I will investigate more but if you have a clue, I take it :wink:

So, your issue is what you put in the GetDistanceBetweenCoords() function. It needs to be (x1, y1, z1, x2, y2, z2,useZ).

Underneath “while true do” put local pos = GetEntityCoords(GetPlayerPed(-1)). This will constantly update the player’s position and put it into the variable ‘pos’.

Now for the functions, they need to be:
GetDistanceBetweenCoords(pos.x, pos.y, pos.z, -921.1211, 4828.44, 1.635, true)

Also, to clean up the code a little (you use the same exact function 3 times), store the value from the GetDistanceBetweenCoords in another variable.

So, underneath the local pos = GetEntityCoords(GetPlayerPed(-1)) I told you to put in, put this local distance = GetDistanceBetweenCoords(pos.x, pos.y, pos.z, -921.1211, 4828.44, 1.635, true)

Then you can replace the other bits with if distance > 500.981 then, etc.

You learn me a lot of usefull triks! thank you so much!

I’ve done what you suggest to me, but the problem still here:

Citizen.CreateThread(function()
    while true do
        local playerPos = GetEntityCoords(GetPlayerPed(-1))
        local distance = GetDistanceBetweenCoords(playerPos.x, playerPos.y, playerPos.z, -921.1211, 4828.44, 1.635, true)
        Citizen.Wait(1)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)
        if distance > 500.981 then
            EndScreen("You will be dead in 10 seconds", "DeathFailOut")
            timer = GetGameTimer()
            if distance > 500.981 then
                if GetGameTimer() > timer + 10000 then
                    SetEntityHealth(GetPlayerPed(-1),  0)
                end
            end
            Wait(10000)  
        end
        if distance < 500.981 then
            StopScreenEffect("DeathFailOut")
        end
        if IsPedFatallyInjured(PlayerPedId()) then
            Wait(2500)
            GiveAWeapon()
        end
        for i = 1, #weaponCoords do
            weaponPos = weaponCoords[i]
            DrawMarker(1, weaponPos[1], weaponPos[2], weaponPos[3] - 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 4.0, 300.0, 255, 255, 0, 75, 0, 0, 2, 0, 0, 0, 0)  
        end
    end
end)

Uhh… I’m really not too sure. I’m not an expert with the coding :stuck_out_tongue:

Is the Z actually at ground level and not wayyyy under the ground? Try setting the “true” at the end of your GetDistance thingy to “false”

Use vdist(playerPos.x, playerPos.y, playerPos.z, -921.1211, 4828.44, 1635) - calculates distance in 3D space.

Citizen.CreateThread(function()
    while true do
        local playerPos = GetEntityCoords(GetPlayerPed(-1))
        local distance = vidst(playerPos.x, playerPos.y, playerPos.z, -921.1211, 4828.44, 1.635)
        Citizen.Wait(1)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)
        if distance > 500.981 then
            EndScreen("You will be dead in 10 seconds", "DeathFailOut")
            timer = GetGameTimer()
            if distance > 500.981 then
                if GetGameTimer() > timer + 10000 then
                    SetEntityHealth(GetPlayerPed(-1),  0)
                end
            end
            Wait(10000)  
        end
        if distance < 500.981 then
            StopScreenEffect("DeathFailOut")
        end
        if IsPedFatallyInjured(PlayerPedId()) then
            Wait(2500)
            GiveAWeapon()
        end
        for i = 1, #weaponCoords do
            weaponPos = weaponCoords[i]
            DrawMarker(1, weaponPos[1], weaponPos[2], weaponPos[3] - 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 4.0, 300.0, 255, 255, 0, 75, 0, 0, 2, 0, 0, 0, 0)  
        end
    end
end)

What is the purpose for each wait() and timer?

I’ve already tryed this, but no difference

The timer is to detect if player is out of the zone more than 10 seconds. I not have take time to do it properly for now, I just looking for a way to try some stuff.

I just trying Vdist instead of GetDistance and same problem: the EndScreen() function is executed at start… maybe a game bug?

Move EndScreen("You will be dead in 10 seconds", "DeathFailOut") to after SetEntityHealth(GetPlayerPed(-1), 0)

EndScreen() is being called before your timer starts.

Yes, it’s normal: when a player go out of the zone, the function EndScreen is called, if the player come back in the zone, another command is called (StopScreenEffect(“DeathFailOut”) to stop EndScreen() )

If I move EndScreen after SetEntityHealth, the EndScreen not appear before the player death, and the player was not warned that it will die…

So: When player go out of the zone, message appear and the timer start, if the player come back in the zone, the screen effect is stopped and nothing happen, if the player is always out of the zone after 10 seconds, the player is killed

I’m having a bit of trouble understanding your design. You want to give the player 10 seconds to get to a zone or they die? Does the timer reset once the player is in the zone, and they can leave for another 10 seconds before they die? Or must they stay in that zone after the initial 10 seconds?

The timer is reseted each time a player go out of the zone (it’s for that I do timer = GetGameTimer() when distance is more than 500). Nothing happen to the timer when player come back in the zone, but it’s not a big deal because “timer” is updated everytime the player go out

I think you may have confused the timer’s purpose.

local maxTimerCount = 0
local newTimerTick = true

while true do
	if (newTimerTick) then
		maxTimerCount = GetGameTimer() + 10000
		newTimerTick = false
	end

	if GetGameTimer() > maxTimerCount then
		-- Do something every 10 seconds
		newTimerTick = true -- Reset timer
	end
end

With your code the player die before reach the limit of the zone! (and the limit of the zone desappear at this moment)

It’s the very beginning of the idea: a mix between Hunger Games and Battle Royal inside a limited zone:

Client:

centerZone = {-894.991, 4820.33, 0.635}
weaponPlaced = false
x = 1
local maxTimerCount = 0
local newTimerTick = true


startCoords = {
    {-887.754, 4808.6001, 301.719},
    {-899.4501, 4795.47, 302.164},
    {-912.142, 4798.32, 304.263},
    {-927.669, 4808.37, 308.387},
    {-937.618, 4821.66, 310.792},
    {-947.295, 4841.00001, 312.859},
    {-930.011, 4854.23, 309.717},
    {-910.177, 4850.34, 30.569},
    {-891.45, 4849.11, 301.881},
    {-871.776, 4852.59, 295.675},
    {-885.558, 4854.29, 293.803},
    {-844.075, 4841.63, 296.5},
    {-838.079, 4823.21, 295.012},
    {-841.344, 4799.51, 297.968},
    {-870.867, 4785.86, 300.176},
    {-901.063, 4780.73, 298.851},
    {-902.648, 4811.57, 303.749}
}
-- blip courone: 437, cible avec mec dedans: 458, 
weaponCoords = { --blip 110 (pistolet) ou, 313 (arme dans cible) ou, 408 (attaché case), 
    {-1137.32, 4873.58, 215.169},
    {-1112.26, 4897.08, 214.364},
    {-1062.24, 4966.88, 213.215},
    {-1170.51, 4926.65, 224.327},
    {-1002.78, 4857.37, 274.606},
    {-826.116, 5174.91, 107.886},
    {-481.692, 4917.72, 146.825},
    {-537.135, 4507.65, 79.9888},
    {-740.425, 4435.74, 16.5733},
    {-1142.47, 4388.8, 21.2187},
    {-1290.21, 4497.25, 14.6273},
    {-902.648, 4811.57, 303.749}
}

weaponsList = {"WEAPON_KNIFE", "WEAPON_GOLFCLUB", "WEAPON_CROWBAR", "WEAPON_PISTOL", "WEAPON_SMG", "WEAPON_ASSAULTSMG"," WEAPON_MG", "WEAPON_PUMPSHOTGUN", "WEAPON_STUNGUN", "WEAPON_SNIPERRIFLE","WEAPON_GRENADELAUNCHER","WEAPON_GRENADELAUNCHER_SMOKE","WEAPON_RPG","WEAPON_MINIGUN","WEAPON_GRENADE","WEAPON_STICKYBOMB","WEAPON_SMOKEGRENADE","WEAPON_BZGAS","WEAPON_MOLOTOV","WEAPON_FIREEXTINGUISHER","WEAPON_BRIEFCASE","WEAPON_FLARE","WEAPON_BARBED_WIRE","WEAPON_BOTTLE","WEAPON_GUSENBERG","WEAPON_SPECIALCARBINE","WEAPON_HEAVYPISTOL","WEAPON_SNSPISTOL","WEAPON_BULLPUPRIFLE","WEAPON_DAGGER","WEAPON_VINTAGEPISTOL","WEAPON_FIREWORK","WEAPON_MUSKET","WEAPON_HEAVYSHOTGUN","WEAPON_MARKSMANRIFLE","WEAPON_HOMINGLAUNCHER","WEAPON_PROXMINE","WEAPON_SNOWBALL","WEAPON_FLAREGUN","WEAPON_GARBAGEBAG","WEAPON_COMBATPDW","WEAPON_MARKSMANPISTOL","WEAPON_KNUCKLE"}

local function EndScreen(text, type)
    Citizen.CreateThread(function()
       -- while true do
           Citizen.Wait(100)      
            if GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, false) > 500.981 then 
                StartScreenEffect(type, 0, 0)
                PlaySoundFrontend(-1, "Bed", "WastedSounds", 1)

                local scaleform = RequestScaleformMovie("MP_BIG_MESSAGE_FREEMODE")

                if HasScaleformMovieLoaded(scaleform) then
                    Citizen.Wait(0)

                    PushScaleformMovieFunction(scaleform, "SHOW_SHARD_WASTED_MP_MESSAGE")
                    BeginTextComponent("STRING")
                    AddTextComponentString(text)
                    EndTextComponent()
                    PopScaleformMovieFunctionVoid()

                    --Citizen.Wait(500)

                    PlaySoundFrontend(-1, "TextHit", "WastedSounds", 1)
                    while GetDistanceBetweenCoords(GetEntityCoords(GetPlayerPed(-1)), -921.1211, 4828.44, 1.635, false) > 500.981 do
                        DrawScaleformMovieFullscreen(scaleform, 255, 255, 255, 255)
                        Citizen.Wait(0)
                    end 
                    --Citizen.Wait(1000)
                end
            else
                StopScreenEffect(type)
            end
        --end
    end)
end


local function GiveAWeapon()
    Citizen.CreateThread(function()
        Citizen.Wait(0)
        RemoveAllPedWeapons(GetPlayerPed(-1), true)
        weaponNum = GetRandomIntInRange(1, #weaponsList)
        givenWeapon = weaponsList[weaponNum]
        weaponHash = GetHashKey(givenWeapon)
        GiveWeaponToPed(GetPlayerPed(-1), weaponHash, 10, 0, true)
        TriggerEvent('chatMessage', '', { 0, 0, 0 }, 'Arme donnée: '..givenWeapon)
    end)
end

RegisterNetEvent('br:placeWeapon')
AddEventHandler('br:placeWeapon', function()
    Citizen.CreateThread(function()
        Citizen.Wait(0)
        while not weaponPlaced do -- Récuperer distance entre coordonnée et player puis nil la valeur dans la table, envoyer l'info au serveur qu'il l'a renvoie a tous les autres joueurs
        --TriggerEvent('chatMessage', '', { 0, 0, 0 }, 'Préparation armes')
        --    RemoveAllPedWeapons(GetPlayerPed(-1), true)
            weaponPlace = weaponCoords[x] 
            --weaponNum = GetRandomIntInRange(1, #weaponsList)
            givenWeapon = weaponsList[GetRandomIntInRange(1, #weaponsList)]

            --while not HasModelLoaded(GetHashKey(givenWeapon)) do
            --    Citizen.Wait(0)
            --end
            weaponHash = GetHashKey(givenWeapon)
            weapon = CreatePickupRotate(weaponHash, weaponPlace[1], weaponPlace[2], weaponPlace[3], 0.0, 0.0, 0.0, 8, 1.0, 24, 24, true, weaponHash)
            --CreateWeaponObject(weaponHash, 10, weaponPlace[1], weaponPlace[2], weaponPlace[3], true, 220.20, 1)
            SetEntityDynamic(weapon, true)
            SetEntityRecordsCollisions(weapon, true)
            SetEntityHasGravity(weapon, true)
            FreezeEntityPosition(weapon, false)
            SetEntityVelocity(weapon, 0.0, 0.0, -0.2)
            TriggerEvent('chatMessage', '', { 0, 0, 0 }, 'Arme donnée '..x..' : '..givenWeapon)
            x = x + 1
            if x == #weaponCoords then
                weaponPlaced = true
            end
        end
    end)
end)




Citizen.CreateThread(function()
    while true do
        Wait(0)
        if NetworkIsSessionStarted() then
            TriggerServerEvent('br:firstJoin')
            return
        end
    end
end)

Citizen.CreateThread(function()
    while true do
        local playerPos = GetEntityCoords(GetPlayerPed(-1))
        local distance = Vdist(playerPos.x, playerPos.y, playerPos.z, -921.1211, 4828.44, 1.635)
        Citizen.Wait(1)
        DrawMarker(1, -921.1211, 4828.44, 1.635, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1000.0, 1000.0, 1000.0, 255, 0, 0, 75, 0, 0, 2, 0, 0, 0, 0)

        if distance > 500.981 then
            Wait(100)
            EndScreen("You have 10 seconds to come back", "DeathFailOut") 
            timer = GetGameTimer()
            if distance > 500.981 then
                if (newTimerTick) then
                    maxTimerCount = GetGameTimer() + 10000
                    newTimerTick = false
                end
                if GetGameTimer() > maxTimerCount then
                    SetEntityHealth(GetPlayerPed(-1),  0)
                    newTimerTick = true
                end
            end
            Wait(10000)  
        end
        if distance < 500.981 then
            StopScreenEffect("DeathFailOut")
        end
        if IsPedFatallyInjured(PlayerPedId()) then
            Wait(2500)
            GiveAWeapon()
        end
        for i = 1, #weaponCoords do
            weaponPos = weaponCoords[i]
            if Vdist(playerPos.x, playerPos.y, playerPos.z, weaponPos[1], weaponPos[2], weaponPos[3]) > 2 then
                DrawMarker(1, weaponPos[1], weaponPos[2], weaponPos[3] - 10, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 4.0, 4.0, 300.0, 255, 255, 0, 75, 0, 0, 2, 0, 0, 0, 0)
            end 
        end
    end
end)

--[[RegisterNetEvent('br:setBlip')
AddEventHandler('br:setBlip', function()
	zoneBlip = AddBlipForCoord(-921.1211, 4828.44, 150.635)
	SetBlipScale(zoneBlip, 100)
	SetBlipSprite(zoneBlip, 4)
	SetBlipColour(zoneBlip, 1)
	SetBlipAlpha(zoneBlip, 64)
	SetBlipAsShortRange(zoneBlip, true)
end)]]

RegisterNetEvent('br:giveWeapon')
AddEventHandler('br:giveWeapon', function()
    GiveAWeapon()
end)

Server:

local list = {}
playerCount = 0
battleInProgress = false

RegisterServerEvent('br:firstJoin')
AddEventHandler('br:firstJoin', function()
	TriggerClientEvent('br:placeWeapon', source)
  	if not list[source] then
    	playerCount = playerCount + 1
    	list[source] = true
    	print("nombre de joueur: "..#list)
  	end
--    TriggerClientEvent('br:setBlip', source)
end)

I test it alone, but in future, I will not let other player than the first in a player list to place weapons on map (and placing weapons don’t work too)

1 Like