DouglaS666 Posted June 17, 2018 Share Posted June 17, 2018 Bad argument @ 'getElementType' [Expected element at argument 1, got boolean] -- Player to Vehicle -- Original Script function glue() local player = getLocalPlayer() if not getPedOccupiedVehicle(player) then local vehicle = getPedContactElement(player) if vehicle and getElementType(vehicle) == "vehicle" then local px, py, pz = getElementPosition(player) local vx, vy, vz = getElementPosition(vehicle) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX = 0 local rotpY = 0 local rotpZ = getPedRotation(player) local rotvX,rotvY,rotvZ = getElementRotation(vehicle) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ local slot = getPedWeaponSlot(player) --outputDebugString("gluing ".. getPlayerName(player) .." to " .. getVehicleName(vehicle) .. "(offset: "..tostring(x)..","..tostring(y)..","..tostring(z).."; rotation:"..tostring(rotX)..","..tostring(rotY)..","..tostring(rotZ)..")") triggerServerEvent("gluePlayer", player, slot, vehicle, x, y, z, rotX, rotY, rotZ) unbindKey("x","down",glue) bindKey("x","down",unglue) bindKey("jump","down",unglue) elseif getElementType(vehicle) == "vehicle" then local object = vehicle local px, py, pz = getElementPosition(player) local vx, vy, vz = getElementPosition(object) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX = 0 local rotpY = 0 local rotpZ = getPedRotation(player) local rotvX,rotvY,rotvZ = getElementRotation(object) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ local slot = getPedWeaponSlot(player) --outputDebugString("gluing ".. getPlayerName(player) .." to " .. getVehicleName(vehicle) .. "(offset: "..tostring(x)..","..tostring(y)..","..tostring(z).."; rotation:"..tostring(rotX)..","..tostring(rotY)..","..tostring(rotZ)..")") triggerServerEvent("gluePlayer", player, slot, vehicle, x, y, z, rotX, rotY, rotZ) unbindKey("x","down",glue) bindKey("x","down",unglue) bindKey("jump","down",unglue) end end end addCommandHandler("glue",glue) function unglue () local player = getLocalPlayer() triggerServerEvent("ungluePlayer", player) unbindKey("jump","down",unglue) unbindKey("x","down",unglue) bindKey("x","down",glue) end addCommandHandler("unglue",unglue) bindKey("x","down",glue) -- Vehicle to Vehicle // Auto con Auto function gluev() -- viendo si funciona local outString outputDebugString("glue vehicle") local thePlayer = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(thePlayer) if myVehicle then local attachMe, attachedTo outputDebugString("my vehicle") local vehicles = getElementsByType("vehicle") local closest, cdist = nil, 100 local mx,my,mz = getElementPosition(myVehicle) for k,v in ipairs(vehicles) do if isElementStreamedIn(v) and v ~= myVehicle then local x,y,z = getElementPosition(v) local tmpdist = getDistanceBetweenPoints3D(x,y,z,mx,my,mz) if tmpdist < cdist then cdist = tmpdist closest = v end end end -- final de los autos function resourceStartNotify ( resourcename ) -- if the started resource is this one if ( resourcename == getThisResource() ) then -- send an info debug message as a notification outputDebugString ( "Resource " .. getResourceName(resourcename) .. " loaded." ) end end addEventHandler( "onResourceStart", getRootElement(), resourceStartNotify ) -- distancia minima if cdist > 5 or cdist == nil then return false end -- comprobando si esta en helicoptero local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then attachMe = closest attachedTo = myVehicle else -- si no esta attachMe = myVehicle attachedTo = closest end -- fin comprobacion local px, py, pz = getElementPosition(attachedTo) local vx, vy, vz = getElementPosition(attachMe) local sx = px - vx local sy = py - vy local sz = pz - vz local rotpX, rotpY, rotpZ = getElementRotation(attachedTo) local rotvX, rotvY, rotvZ = getElementRotation(attachMe) local t = math.rad(rotvX) local p = math.rad(rotvY) local f = math.rad(rotvZ) local ct = math.cos(t) local st = math.sin(t) local cp = math.cos(p) local sp = math.sin(p) local cf = math.cos(f) local sf = math.sin(f) local z = ct*cp*sz + (sf*st*cp + cf*sp)*sx + (-cf*st*cp + sf*sp)*sy local x = -ct*sp*sz + (-sf*st*sp + cf*cp)*sx + (cf*st*sp + sf*cp)*sy local y = st*sz - sf*ct*sx + cf*ct*sy local rotX = rotpX - rotvX local rotY = rotpY - rotvY local rotZ = rotpZ - rotvZ triggerServerEvent("glueVehicle", attachMe, attachedTo, x*-1, y*-1, z*-1, rotX, rotY, rotZ) unbindKey("x","down",gluev) bindKey("x","down",ungluev) else -- else no myvehicle end -- end if myvehicle end addCommandHandler("gluev",gluev) function ungluev () local player = getLocalPlayer() local myVehicle = getPedOccupiedVehicle(player) local vtype = getElementModel(myVehicle) if vtype == (487 or 548 or 425 or 417 or 488 or 497 or 563 or 447 or 469) then local attached = getAttachedElements(myVehicle) for k,v in ipairs(attached) do if getElementType(v) == "vehicle" then myVehicle = v end end end triggerServerEvent("unglueVehicle", myVehicle) unbindKey("jump","down",ungluev) unbindKey("x","down",ungluev) bindKey("x","down",gluev) end addCommandHandler("unglue",ungluev) bindKey("x","down",gluev) Link to comment
DNL291 Posted June 17, 2018 Share Posted June 17, 2018 (edited) Me responde uma coisa, esses erros que você posta aqui são mensagens aleatórias que você recebe no server? Sobre o erro, faça uma checagem (assim como na linha 7) assim: elseif vehicle and getElementType(vehicle) == "vehicle" then -- linha 48 if v and getElementType(v) == "vehicle" then -- linha 213 Se esse valor booleano não for true, não vai reportar erros, caso contrário, use um isElement na condição. Edited June 17, 2018 by DNL291 1 Link to comment
DouglaS666 Posted June 17, 2018 Author Share Posted June 17, 2018 27 minutes ago, DNL291 said: Me responde uma coisa, esses erros que você posta aqui são mensagens aleatórias que você recebe no server? Sobre o erro, faça uma checagem (assim como na linha 7) assim: elseif vehicle and getElementType(vehicle) == "vehicle" then -- linha 48if v and getElementType(v) == "vehicle" then -- linha 213 Se esse valor booleano não for true, não vai reportar erros, caso contrário, use um isElement na condição. Sim, são todos resources da net a grande maioria contendo erros. Link to comment
Other Languages Moderators Lord Henry Posted June 17, 2018 Other Languages Moderators Share Posted June 17, 2018 Sugiro que comece a estudar lógica de programação e depois a Wiki. Dai crie seus próprios resources em vez de ficar arrumando os dos outros. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now