I did some work on it by myself and here's what i've accomplished so far:
Server-Side
function reward(p)
if getElementType ( p ) == "ped" then
local carro = getVehicleOccupant(getPedOccupiedVehicle(p), 0)
givePlayerMoney(carro, 1000)
destroyElement(p)
outputChatBox("Perp has been turned in and you earned $1000!", carro, 0,255,0)
end
end
policem = createMarker(1586,-1677,5, "cylinder", 5, 255, 0, 0, 170)
addEventHandler("onMarkerHit", policem, reward)
function teste(p)
local x,y,z = getElementPosition(p)
local pedestre = createPed(23, x,y,z)
end
addCommandHandler("teste", teste)
team = createTeam("Criminal", 255,0,0)
team2 = createTeam("Police", 0,0,255)
--i play alone on my server, but it can easily be adapted to play with other players.
function findRotation3D( x1, y1, z1, x2, y2, z2 )
local rotx = math.atan2 ( z2 - z1, getDistanceBetweenPoints2D ( x2,y2, x1,y1 ) )
rotx = math.deg(rotx)
local rotz = -math.deg( math.atan2( x2 - x1, y2 - y1 ) )
rotz = rotz < 0 and rotz + 360 or rotz
return rotx, 0,rotz
end
function func1(p)
local x,y,z = getElementPosition(p)
Marker = createMarker(x, y, z, "cylinder", 1, 255, 0, 0, 170)
attachElements(Marker,p, 0,1,0)
addEventHandler("onMarkerHit", Marker, bunda)
addEventHandler("onMarkerHit", Marker, cu)
end
addCommandHandler("bust", func1)
function release()
destroyElement(Marker)
timers = getTimers ( 1000)
for timerKey, timerValue in ipairs(timers) do
killTimer ( timerValue )
end
end
addCommandHandler("free", release)
function func2(p,_)
if getElementType ( p ) == "ped" then
x2,y2,z2 = getElementPosition(Marker)
x1,y1,z1 = getElementPosition(p)
rx,ry,rz = findRotation3D(x1,y1,z1,x2,y2,z2)
setElementRotation(p, rx+0,ry+0,rz+0)
setPedAnimation(p, "ped", "walk_player")
setTimer(function()
func2(p,_)
end, 999, 1)
else return end
end
function func3(p, ped)
if not getElementType ( ped ) == "ped" then return end
addEventHandler("onVehicleEnter", root, function()
setTimer(function()
setPedAnimation(ped, false)
end, 999, 1)
timers = getTimers ( 1000)
for timerKey, timerValue in ipairs(timers) do
killTimer ( timerValue )
end
destroyElement(Marker)
end)
end
function sirenes(p, pp)
carro = getPedOccupiedVehicle(p)
if getVehicleSirensOn(carro) then
local x,y,z = getElementPosition(carro)
sir = createMarker(x,y,z, "cylinder", 5, 255,0,0, 170)
attachElements(sir,carro, 0,-2,0)
addEventHandler("onMarkerHit", sir, function(p)
if getElementType(p) == "ped" then
warpPedIntoVehicle(p, carro, math.random(2,3))
else return end
end)
else
destroyElement(sir)
end
end
addEventHandler("onVehicleStartExit", getRootElement(), sirenes)
function sirenoff(p, pp)
carro = getPedOccupiedVehicle(p)
if getVehicleSirensOn(carro) then
destroyElement(sir)
end
end
addEventHandler("onVehicleEnter", getRootElement(), sirenoff)