Jump to content

Random survivor script


kewizzle

Recommended Posts

so I am trying to create a random survivor script and when the first survivor dies survivorPed it also destroys elements survivorMarker, survivorBlip and survivorPed. But when the next survivor spawns it does not do that and it does not spawn a survivor after 15 seconds.

 

addEventHandler("onResourceStart", root, function()
		function spawnSurvivor()
				survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
				survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
				survivorBlip = createBlipAttachedTo( survivorPed, 47 )
				outputChatBox("The Survivor Was Saved! New one spawning soon.")
		end

spawnSurvivor()
		
addEventHandler("onPedWasted", survivorPed, function()
		outputChatBox("The Survivor Was Saved! New one spawning soon.")
		destroyElement(survivorMarker)
		destroyElement(survivorBlip)
		destroyElement(survivorPed)
		setTimer(spawnSurvivor, 15000, 1)

	end)
end)

 

this works but now the location isnt random

function spawnSurvivor()
	survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
			
			addEventHandler("onPedWasted", survivorPed, function()
				outputChatBox("The Survivor Was Saved! New one spawning soon.")
				destroyElement(survivorMarker)
				destroyElement(survivorBlip)
				destroyElement(survivorPed)
				setTimer(spawnSurvivor, 15000, 1)

	end)
end

addEventHandler("onResourceStart", root, function()
spawnSurvivor()
end)

 

Link to comment
local spawns = {
{ xf = -786, yf = 893, zf = 13, ro = 90.0 },
{ xf = -767, yf = 882, zf = 13, ro = 120.6928 }
}

local livingPeds = {
{ id = 0 },
{ id = 104 }
}

and

 

rnd = math.random(1,2)
rnd2 = math.random(1,2)	
survivorPed = createPed(livingPeds[rnd2].id, spawns[rnd].xf, spawns[rnd].yf, spawns[rnd].zf, spawns[rnd].ro)

 

Link to comment
1 hour ago, 3laa33 said:

local spawns = {
{ xf = -786, yf = 893, zf = 13, ro = 90.0 },
{ xf = -767, yf = 882, zf = 13, ro = 120.6928 }
}

local livingPeds = {
{ id = 0 },
{ id = 104 }
}

and

 


rnd = math.random(1,2)
rnd2 = math.random(1,2)	
survivorPed = createPed(livingPeds[rnd2].id, spawns[rnd].xf, spawns[rnd].yf, spawns[rnd].zf, spawns[rnd].ro)

 

still not working as it should, both scripts however did a random spawn and skin on each resource restart tho.

Link to comment
1 hour ago, 3laa33 said:

as it should ? what do do you want it to do?

each time the spawnSurvivor function is called by setTimer it spawns a new survivorPed with a random location in the table and a random skin. Basically onPedWasted it destroys the ped, blimp and marker and then 15 seconds later respawns somewhere else, kinda like breifcase.

Link to comment
function spawnSurvivor()
	survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
			

end

			addEventHandler("onPedWasted", survivorPed, function()
				outputChatBox("The Survivor Was Saved! New one spawning soon.")
				destroyElement(survivorMarker)
				destroyElement(survivorBlip)
				destroyElement(survivorPed)
				setTimer(spawnSurvivor, 15000, 1)

	end)

get out the pedwasted event from the function
and if there is debug errors post it
 

Link to comment
1 hour ago, 3laa33 said:

function spawnSurvivor()
	survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
			

end

			addEventHandler("onPedWasted", survivorPed, function()
				outputChatBox("The Survivor Was Saved! New one spawning soon.")
				destroyElement(survivorMarker)
				destroyElement(survivorBlip)
				destroyElement(survivorPed)
				setTimer(spawnSurvivor, 15000, 1)

	end)

get out the pedwasted event from the function
and if there is debug errors post it
 

expected element at argument 2 for addEventHandler onPedWasted

Link to comment
function spawnSurvivor()
	survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	addEventHandler("onPedWasted", survivorPed, killedPed)
	outputChatBox("The Survivor Was Saved! New one spawning soon.")		
end

function killedPed()
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	destroyElement(survivorPed)
	setTimer(spawnSurvivor, 15000, 1)
end

I suppose you want this.

Link to comment
1 hour ago, NeXuS™ said:

function spawnSurvivor()
	survivorPed = createPed(livingPeds[rnd2][1], spawns[rnd][1], spawns[rnd][2], spawns[rnd][3], spawns[rnd][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	addEventHandler("onPedWasted", survivorPed, killedPed)
	outputChatBox("The Survivor Was Saved! New one spawning soon.")		
end

function killedPed()
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	destroyElement(survivorPed)
	setTimer(spawnSurvivor, 15000, 1)
end

I suppose you want this.

it doesnt work i get the error bad argument at createMarkerAttachedTo expected element at argument 1 got boolean and when i remove that line(which is needed for further development) i get 3 more errors, createPed expected element at argument 1 got nil and createBlipAttachedTo element expected at argument 1 got boolean and addEventHandler expected element at argument 2 got boolean

Link to comment
local avaibleSkins = {
	0,
	1,
	2
}

local spawnPoints = {
	{0, 0, 0, 0},
	{10, 10, 10, 90}
}

function spawnSurvivor()
	local random1 = math.random(1, #avaibleSkins)
	local random2 = math.random(1, #spawnPoints)
	survivorPed = createPed(avaibleSkins[random1], spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawns[random2][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	addEventHandler("onPedWasted", survivorPed, killedPed)
	outputChatBox("The Survivor Was Saved! New one spawning soon.")		
end

function killedPed()
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	destroyElement(survivorPed)
	setTimer(spawnSurvivor, 15000, 1)
end

You gotta learn have to fix easy errors like these.

  • Like 1
Link to comment
1 hour ago, NeXuS™ said:

local avaibleSkins = {
	0,
	1,
	2
}

local spawnPoints = {
	{0, 0, 0, 0},
	{10, 10, 10, 90}
}

function spawnSurvivor()
	local random1 = math.random(1, #avaibleSkins)
	local random2 = math.random(1, #spawnPoints)
	survivorPed = createPed(avaibleSkins[random1], spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawns[random2][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	addEventHandler("onPedWasted", survivorPed, killedPed)
	outputChatBox("The Survivor Was Saved! New one spawning soon.")		
end

function killedPed()
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	destroyElement(survivorPed)
	setTimer(spawnSurvivor, 15000, 1)
end

You gotta learn have to fix easy errors like these.

works but aye i can fix the easy errors, I like to speed up the process by posting tho cuz im working on it as you professionals help. :D Im a moderate scripter i guess.

Link to comment
2 hours ago, NeXuS™ said:

local avaibleSkins = {
	0,
	1,
	2
}

local spawnPoints = {
	{0, 0, 0, 0},
	{10, 10, 10, 90}
}

function spawnSurvivor()
	local random1 = math.random(1, #avaibleSkins)
	local random2 = math.random(1, #spawnPoints)
	survivorPed = createPed(avaibleSkins[random1], spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawns[random2][4])
	survivorMarker = createMarkerAttachedTo ( survivorPed, "cylinder", 4.0, 0, 0, 255, 255 )
	survivorBlip = createBlipAttachedTo( survivorPed, 47 )
	addEventHandler("onPedWasted", survivorPed, killedPed)
	outputChatBox("The Survivor Was Saved! New one spawning soon.")		
end

function killedPed()
	outputChatBox("The Survivor Was Saved! New one spawning soon.")
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	destroyElement(survivorPed)
	setTimer(spawnSurvivor, 15000, 1)
end

You gotta learn have to fix easy errors like these.

youre really good at scripting so im wondering okay so i got this

function hitSurv(playerSource)
	
	outputChatBox(getPlayerName(playerSource).." Has Collected The Survivor!", server, 0, 255, 0)
	destroyElement(survivorMarker)
	destroyElement(survivorBlip)
	setElementData(playerSource, "hasSurv", true)
	toMarker = createMarker(-719, 951, 11, "cylinder", 3, 255, 0, 255, 150, playerSource)
	saveBlip = createBlipAttachedTo( toMarker, 22 )
	setPedAnimation( survivorPed, "ped", "WOMAN_run")
	addEventHandler("onMarkerHit", toMarker, hitSurvDes)
end

i need the ped to follow me once i hit the marker but all i got it to do is run. is there a way to use setPedLookAt to work with the server side created ped?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...