Zaloguj się by uzyskać pełen dostęp. Nie masz jeszcze konta? Założ je już teraz w kilka sekund.

Wysłany: 2020-03-29, 12:06


dakuVen







Wiek: 30
Na forum: 2859 dni
Posty: 10
Nick w MP: dakuVen



Respekt: 50

Gdy wyci?gam torbe R1 z karetki to bierze mi j? i odrazu chowa pom?g? by mi kto? z tym z g?ry dzi?kuje. Za pomoc stawiam zimne piwko :piwo: :piwo:
Tutaj daje kod:
Kod:

local torbysamc = {}

addEvent("onTryTakeSAMCItem1",true)
addEventHandler("onTryTakeSAMCItem1",root,function ()
if not getElementData(client,"SAMC:item:r1") then
stworztorbe(client)
setElementData(client,"SAMC:item:r1",true)
toggleControl(client,"sprint", false )
else
usuntorbe(client)
setElementData(client,"SAMC:item:r1",nil)
toggleControl(client,"sprint", true )
end
end)

function stworztorbe(plr)
if not plr then return end
local x,y,z = getElementPosition(plr)
local torba = createObject(323,x,y,z)
torbysamc[plr] = torba
setElementCollisionsEnabled (torba, false)
exports["bone_attach"]:attachElementToBone(torba,plr,12,0.02,0.1,0.3,0,180,0)
setObjectScale(torba,1.0)
end

function usuntorbe(plr)
if not plr then return end
local torba = torbysamc[plr]
if torba then
if isElement(torba) then
if exports["bone_attach"]:isElementAttachedToBone(torba) then exports["bone_attach"]:detachElementFromBone(torba) end
destroyElement(torba)
end
torbysamc[plr] = nil
end
end

addEventHandler ( "onPlayerQuit", root, function()
local torba = torbysamc[source]
if torba then
if isElement(torba) then
if exports["bone_attach"]:isElementAttachedToBone(torba) then exports["bone_attach"]:detachElementFromBone(torba) end
destroyElement(torba)
end
torbysamc[source] = nil
end
end )

addCommandHandler("r1",function(plr,cmd)
if not getElementData(plr,"player:duty") then return end
if getElementData(plr,"player:duty") and getElementData(plr,"player:duty") ~= "PR" then return end
local veh = getPedOccupiedVehicle(plr)
if veh then return end
local torba = torbysamc[plr]
if not torba then outputChatBox("Nie posiadasz torby w d?oni",plr,255,0,0) return end
if not isElement(torba) then outputChatBox("Nie posiadasz torby w d?oni",plr,255,0,0) return end
if exports["bone_attach"]:isElementAttachedToBone(torba) then
exports["bone_attach"]:detachElementFromBone(torba)
setElementCollisionsEnabled (torba, true)
local x,y,z = getElementPosition(plr)
setElementPosition(torba,x,y+0.45,z-0.82)
local rz = getElementRotation(torba)
setElementRotation(torba,0,0,rz)
else
local x,y,z = getElementPosition(plr)
local x2,y2,z2 = getElementPosition(torba)
local distance = getDistanceBetweenPoints3D(x,y,z,x2,y2,z2)
if distance > 2 then outputChatBox("Podejd? bli?ej by podnie?? torb?.",plr,255,0,0) return end
exports["bone_attach"]:attachElementToBone(torba,plr,12,0.02,0.1,0.3,0,180,0)
setElementCollisionsEnabled (torba, false)
end
end)



-----------------------------------------------
object = {}
attach = {}
controls = {"jump", "sprint", "crouch", "enter_exit", "enter_passenger"}

addEvent("onTryTakeSAMCItem2",true)
addEventHandler("onTryTakeSAMCItem2",root,function ()
if not getElementData(client,"SAMC:item:nosze") then
nosze(client)
setElementData(client,"SAMC:item:nosze",true)
else
nosze(client)
setElementData(client,"SAMC:item:nosze",nil)
end
end)

function nosze(player, cmd)
if not getElementData(player,"nosze") then
setElementData(player, "nosze", true)
object[player] = Object(2146, 0, 0, 0)
object[player]:attach(player, 0, 1.3, -1)
object[player]:setCollisionsEnabled(false)
else
removeElementData(player, "nosze")
if object[player] then
destroyElement(object[player])
end
end
end

function ustaw(player, cmd, target)
if object[player] then
if not attach[player] then
local target = exports["ogrpg-core"]:findPlayer(player, target)
if not target then
outputChatBox("Nie znaleziono podanego gracza!",player,255,255,255,true)
return
end
if not getElementData(player, "nosze") then outputChatBox('#ff0000✖ #ffffffNie posiadasz roz?o?onych noszy! #ff0000✖', player, 0, 0, 0,true) return end
if (player.position-Vector3(getElementPosition(target))).length < 5 then
if not target.vehicle then
target:attach(object[player], 0, -0.2, 2)
attach[player] = target

for _,control in ipairs(controls) do
toggleControl(player, control, false)
end
local rotation = {getElementRotation(player)}
target:setAnimation("CRACK", "crckidle4", -1, true, false)
Timer(function() triggerClientEvent(target, "iyw_samd_stretcher:rotation", root, target, object[player],true) end, 500, 1)
else
outputChatBox('#ff0000✖ #ffffffPodany gracz znajduje si? w poje?dzie, nie mo?esz wzi?? go na nosze! #ff0000✖', player, 0, 0, 0,true)
end
else
outputChatBox('#ff0000✖ #ffffffZnajdujesz si? zbyt daleko od gracza, kt?rego chcesz wzi?? na nosze! #ff0000✖', player, 0, 0, 0,true)

end
else
outputChatBox('#ff0000✖ #ffffffNa tych noszach ju? kto? si? znajduje! #ff0000✖', player, 0, 0, 0,true)
end
else
outputChatBox('#ff0000✖ #ffffffNie posiadasz roz?o?onych noszy! #ff0000✖', player, 0, 0, 0,true)
end
end
addCommandHandler("nosze-ustaw", ustaw)
function zdejmij(player, cmd, target)
if object[player] then
if attach[player] then
for _,control in ipairs(controls) do
toggleControl(player, control, true)
end
local target = exports["ogrpg-core"]:findPlayer(player, target)
if not target then
outputChatBox("Nie znaleziono podanego gracza!",player,255,255,255,true)
return
end
target:detach(object[player])
attach[player] = false
triggerClientEvent(target, "iyw_samd_stretcher:deleteRotation", root)
else
outputChatBox('#ff0000✖ #ffffffNa tych noszach nikt si? nie znajduje! #ff0000✖', player, 0, 0, 0,true)
end
else
outputChatBox('#ff0000✖ #ffffffNie posiadasz roz?o?onych noszy! #ff0000✖', player, 0, 0, 0,true)

end
end
addCommandHandler("nosze-zdejmij",zdejmij)
addEventHandler("onPlayerQuit",root,function(_,_,_)
local player=source
if object[player] then
if attach[player] then
attach[player]:detach(object[player])
triggerClientEvent(attach[player], "iyw_samd_stretcher:deleteRotation", root)
attach[player] = false
end
destroyElement(object[player])
end
end)

function usun(player,target)
if not player then return end
if not target then return end
if attach[player] then
for _,control in ipairs(controls) do
toggleControl(player, control, true)
end
target:detach(object[player])
attach[player] = false
triggerClientEvent(target, "iyw_samd_stretcher:deleteRotation", root)
end
if getElementData(player,"nosze") then
removeElementData(player, "nosze")
if object[player] then
destroyElement(object[player])
end
end
end


Postaw piwo autorowi tego posta
 

 
Wysłany: 2020-03-29, 13:17


MrVip615

witam






Wiek: 22
Na forum: 4307 dni
Posty: 167
Nick w MP: ramzes

Piwa: 207

Respekt: 85,3

Nie ustawiaj wartosci dla ElementDaty SAMC:item:r1 nil bo sprawdzasz czy istnieje taka ElementData, polecam
Więcej informacji znajdziesz w Wikipedii MTA:

removeElementData

A elementdata zwraca false gdy takowej nie ma a nie nil

[ Dodano: 2020-03-29, 13:27 ]
I wstawiaj kod w [lua] a nie w [code]

Postaw piwo autorowi tego posta
 

 
Tagi: torba :: wyciąganie :: karetki
Anonymous





Na forum: 245 dni
Posty: 1



Anonymous Koniecznie zajrzyj na:






Skocz do:  
Wyświetl posty z ostatnich:   
GTAONLINE.PL » JĘZYKI PROGRAMOWANIA » LUA » Torba R1 Wyciąganie z karetki Odpowiedz do tematu

Nie możesz pisać nowych tematów
Nie możesz odpowiadać w tematach
Nie możesz zmieniać swoich postów
Nie możesz usuwać swoich postów
Nie możesz głosować w ankietach
Dodaj temat do Ulubionych
Wersja do druku