How to make the server spawn only one pickup during a co-op mission?

So I’ve scripted a beginner test coop mission between my friends and I where the player gets in the spawned car, goes to a drug meet, kills everyone including the boss, boss drops the package of drugs as a pickup. Player picks up the pickup and delivers it to the drop off point.

The problem is that when we play the mission, two cars spawn on top of each other. One is his and the other is mine. I only want one to spawn if that makes sense.

To circumvent this I did some GetGamePool(‘CVehicle’) magic and manually spawn the car using a trainer before starting the mission. Now it searches the world for that specific car model (Grotti Cheetah Classic) and uses that as the car for the mission. This way we are both being directed to get into the same car.

Next the problem is about the boss, the boss also spawns twice. The boss is in a relationship group called SPOONER_ENEMIES. When you kill the boss he drops a pickup but the problem is that the server spawns two pickups instead of one. One for me to pickup next to my boss and one for my friend to pickup at his spawned boss. This has been troubling me for a very long time and I cant seem to fix it. I would like only one boss to spawn and one pickup to spawn in which either one of us can pick it up to proceed to the next objective. GetGamePool(‘CPickup’) does not work for CreatePickup so I cant force the game to delete one of the pickups.

Code
Searching the world for the Cheetah classic that will be used for the mission (this works fine, no problems here).

MissionStart("~y~Gang Ties")

	car = GetHashKey('cheetah2')
	carfound = false
	while true do
		Citizen.Wait(0)
		for _, veh in ipairs(GetGamePool('CVehicle')) do
	
				if IsVehicleModel(veh, car) then
					cheetah = veh
					blipcar = AddBlipForEntity(cheetah)
					SetBlipColour(blipcar, 3)
					AddTextEntry('BLIPCAR', 'Personal Vehicle')
					BeginTextCommandSetBlipName('BLIPCAR')
					EndTextCommandSetBlipName(blipcar)
					carfound = true
				end
		end
			if carfound then
				break
			end
	
	end

Spawning the boss and then checking if all enemies in the SPOONER_ENEMIES relationship are all dead before spawning the pickup. To do that I use for loops and GetGamePool to check how many bosses they are in the world (in my case 2 since I am playing with a friend) and then to count how many bosses have been killed which is the count >= enemiesnum, kind of complicated but ignorable for this issue.

	boss1 = CreatePed(1, GetHashKey("g_m_y_lost_02"), 2309.13672, 4859.49658, 41.8117867, -7.97562265, true, true)
	SetEntityHealth(boss1, 400)
	SetEntityMaxHealth(boss1, 400)	
	SetPedCombatMovement(boss1, 1)
	SetPedCombatRange(boss1, 1)
	SetPedRelationshipGroupHash(boss1, GetHashKey("SPOONER_ENEMIES"))
	GiveWeaponToPed(boss1, 0xbfefff6d, 6000, false, true)
	SetEntityOnlyDamagedByPlayer(boss1, true)

	blip2 = AddBlipForEntity(boss1)
	SetBlipRoute(blip2, false)
	SetBlipColour(blip2, 1)
	AddTextEntry('BLIP2', 'Boss')
	BeginTextCommandSetBlipName('BLIP2')
	EndTextCommandSetBlipName(blip2)	
	
	enemiesnum = 0
		for _, ped in ipairs(GetGamePool('CPed')) do
		local pedrelation = GetPedRelationshipGroupHash(ped)
		local enemies = GetHashKey('SPOONER_ENEMIES')
		if pedrelation == enemies and DoesEntityExist(ped) and IsEntityDead(ped) then
		SetPedRelationshipGroupHash(ped, GetHashKey("MISSION6"))
		elseif pedrelation == enemies and DoesEntityExist(ped) and not IsEntityDead(ped) then
		enemiesnum = enemiesnum+1
		end
		
		end
	
	count = 0
	while not (count >= enemiesnum) do
	Citizen.Wait(0)
	MissionText("Eliminate ~r~everyone.", 1000000)
		local enemies = GetHashKey('SPOONER_ENEMIES')
		
		for _, ped in ipairs(GetGamePool('CPed')) do
		local pedrelation = GetPedRelationshipGroupHash(ped)
		
		if pedrelation == enemies and not IsEntityDead(ped) then
		count = 0
		elseif pedrelation == enemies and IsEntityDead(ped) then
		count = count+1
		end
		
		
		end
	end
	
		RemoveBlip(blip2)
		PlaySoundFrontend(a_0, "CHECKPOINT_NORMAL", "HUD_MINI_GAME_SOUNDSET", 1)
		ClearPrints()

Spawning the pickup at the bosses dead body as soon as he dies. This is where the game spawns two pickups, one at my friend’s boss’s body and one at mine

	deadped = GetSafePickupCoords(GetEntityCoords(boss1))
	pickuphash = GetHashKey("PICKUP_PORTABLE_PACKAGE")
	pickup1 = CreatePickupRotate(pickuphash, deadped.x, deadped.y, deadped.z, 0.0, 0.0, 0.0, 8, 1, 1, true)
blippickup = AddBlipForEntity(pickup1)
	SetBlipSprite(blippickup, 51)
	SetBlipColour(blippickup, 2)
	AddTextEntry('BLIPPICKUP', 'Package')
	BeginTextCommandSetBlipName('BLIPPICKUP')
	EndTextCommandSetBlipName(blippickup)	
SetPedAsNoLongerNeeded(boss1)

deadped = GetSafePickupCoords(GetEntityCoords(GetPickupObject(pickup1)))

	while true do
	Citizen.Wait(0)
	MissionText("Collect the ~g~package.", 1000000)
	
		local minimum, maximum = GetModelDimensions(GetEntityModel(GetPickupObject(pickup1)))
	pickuppos = GetEntityCoords(GetPickupObject(pickup1))
	DrawMarker(20, pickuppos.x, pickuppos.y, pickuppos.z+maximum.z+0.5, 0.0, 0.0, 0.0, 0.0, 180.0, 0.0, 0.5, 0.5, 0.5, 115, 195, 108, 50, 1, 1, 2, 0, 0)	
		if HasPickupBeenCollected(pickup1) then
		--Code removed from here for ease to understand
		

If anyone experienced in mission scripting could help I would be really grateful, thank you
Video of mission for ref
https://streamable.com/b1a3s7

1 Like

Can you send me the script please?