Hey, I want to do a function witch will give a player a object (tire) and I want
to give it only once (limit of tires in trunk). Is there a way to do it?
My script is serverside,I am begginer in scripting so dont hate me :]
My script:
function bagaznik(player)
vehicle2 = getPedOccupiedVehicle(player)
if isElement(vehicle2) then
if getVehicleDoorOpenRatio(vehicle2,1) > 0 then
setVehicleDoorOpenRatio(vehicle2,1,0)
else
element = getPedOccupiedVehicle(player)
x,y,z = pozycja(element,0,-3,-1)
myMarker =createMarker ( x , y, z, "cylinder", 1.5, 255, 255, 0, 170 )
addEventHandler("onMarkerHit", myMarker, sprawdzstan)
setVehicleDoorOpenRatio(vehicle2,1,1)
end
end
end
addCommandHandler("trunk",bagaznik)
--This funciton makes trunk open and create marker behind trunk and if you touch marker it run function sprawdzstan
function sprawdzstan(thePlayer)
if stan(thePlayer)==0 then
outputChatBox("#ffea00"..getVehicleName ( vehicle ).." jest sprawny: ",getRootElement(),r,g,b, true )
outputChatBox ( "#ffea00Lewy-Przod: " .. stany [ lewyprzod ] .. " #ffea00Prawy-Przod: " .. stany [ prawyprzod ]
.." #ffea00Lewy-tyl: " .. stany [ lewytyl ] .. " #ffea00Prawy-Tyl: " .. stany [ prawytyl ],getRootElement(),r,g,b, true )
setVehicleDoorOpenRatio(vehicle,1,0)
destroyElement(myMarker)
else
outputChatBox("#ffea00"..getVehicleName ( vehicle ).." jest zepsuty: ",getRootElement(),r,g,b, true )
outputChatBox ( "#ffea00Lewy-Przod: " .. stany [ lewyprzod ] .. " #ffea00Prawy-Przod: " .. stany [ prawyprzod ]
.. " #ffea00Lewy-tyl: " .. stany [ lewytyl ] .. " #ffea00Prawy-Tyl: " .. stany [ prawytyl ],getRootElement(),r,g,b, true )
outputChatBox("By naprawić zepsute koło podejdz do pojazdu i odczekaj 5 sekund")
playanim(thePlayer)
end
end
--this function check if car wheels are damaged or not if not it output they are in good condition and destroy marker and close trunk
--if wheels are damaged it output they are damaged and run playanim
function playanim(thePlayer)
poprawka(thePlayer)
setPedAnimation(thePlayer,"carry","crry_prtial",0,true,true,false,true)
setTimer(function()setVehicleWheelStates ( vehicle, 0, 0, 0, 0 ) destroyElement(object) setPedAnimation(thePlayer,"carry","crry_prtial",0,true,true,false,false)
destroyElement(myMarker) setVehicleDoorOpenRatio(vehicle,1,0)
end,5000,1)
end
--this function set player animation to carry a object set on arms and after 5 seconds repair wheels in car destroy marker and set trunk close
function poprawka(thePlayer)
x,y,z=getElementPosition(thePlayer )
object =createObject (1327,x,y,z)
setObjectScale(object,0.3)
attachElements(object, thePlayer,-0.05,0.5,0.2,0,90,-100)
setElementCollisionsEnabled(object, false)
end
-- function to set tire on player arms
function pozycja(element,offX,offY,offZ)
local m = getElementMatrix ( element ) -- Get the matrix
local x = offX * m[1][1] + offY * m[2][1] + offZ * m[3][1] + m[4][1] -- Apply transform
local y = offX * m[1][2] + offY * m[2][2] + offZ * m[3][2] + m[4][2]
local z = offX * m[1][3] + offY * m[2][3] + offZ * m[3][3] + m[4][3]
return x, y, z -- Return the transformed point
end
--function requried to get position of trunk
function getNearestVehicle( thePlayer )
local x, y, z = getElementPosition( thePlayer )
for i, v in ipairs( getElementsByType( "vehicle" ) ) do
local distance = getDistanceBetweenPoints3D( x, y, z, getElementPosition( v ) )
if distance <12 then
nearestVehicle = v
end
end
return nearestVehicle or false
end
--get distance and id etc. of the nearest car
function stan ( thePlayer)
vehicle=getNearestVehicle( thePlayer )
stany = { [0]="#099e34Pełna", [1]="#FF0000Bez powietrza", [2]="#FF0000Odpadnięte koło" }
lewyprzod, lewytyl, prawyprzod, prawytyl = getVehicleWheelStates ( vehicle )
if lewyprzod==1 or lewytyl==1 or prawyprzod==1 or prawytyl==1 then
else
return lewyprzod, lewytyl, prawyprzod, prawytyl,stany
end
end
--check car wheels condition that if is required to work sprawdzstan
--Script written by Rivsky :]
I want a limit in bagazanik function like:
Player open trunk and take's one tire,repair a tire and In second time when he puncture the tire and open trunk the output say the Trunk is empty and after get into the car car and get out of the car the trunk don't reset and will be still empty until I reset script.
If something is incomprehensible write here and I'll explain you and sorry If my English was not understandable :]