Plate Posted May 24, 2013 Share Posted May 24, 2013 Hola por que esto no funciona nisiquiera da error function bindStart() for k,v in pairs(getElementsByType("player")) do bindKey(v, "n", "down", pickupWeapon) end end addEventHandler("onResourceStart", getRootElement(), bindStart) function login() for k,v in ipairs(getElementsByType("player")) do bindKey(v, "n", "down", pickupWeapon) end end addEventHandler("onPlayerLogin", getRootElement(), login) function pullItem(item, ammo) local x, y ,z = getElementPosition(source) theWeapon = createObject(358, x, y, z- 1, 70, 0, 0) colshape = createColTube ( x, y, z, 1, 1 ) setElementData(colshape, "Arma", 34) setElementData(colshape, "Municion", ammo) takeWeapon(source, 34) end addEvent("onPlayerPullSniper", true) addEventHandler("onPlayerPullSniper", getRootElement(), pullItem) function pickupWeapon(player) if (source == colshape) then if isElement(colshape) then if isElementWithinColShape(source, colshape) then outputChatBox("/recoger", player, 0, 255, 255) giveWeapon(player, tonumber(getElementData(colshape, "Arma")), tonumber(getElementData(colshape, "Municion"))) destroyElement(source) destroyElement(theWeapon) end end end end addEventHandler("onColShapeHit", getRootElement(), pickupWeapon) Link to comment
Castillo Posted May 24, 2013 Share Posted May 24, 2013 local inColShape = { } function bindStart ( ) for _, v in ipairs ( getElementsByType ( "player" ) ) do bindKey ( v, "n", "down", pickupWeapon ) end end addEventHandler ( "onResourceStart", resourceRoot, bindStart ) function login ( ) bindKey ( source, "n", "down", pickupWeapon ) end addEventHandler ( "onPlayerLogin", getRootElement(), login ) function pullItem ( item, ammo ) local x, y, z = getElementPosition ( source ) theWeapon = createObject ( 358, x, y, z - 1, 70, 0, 0 ) colshape = createColTube ( x, y, z, 1, 1 ) setElementData ( colshape, "Arma", 34 ) setElementData ( colshape, "Municion", ammo ) takeWeapon ( source, 34 ) addEventHandler ( "onColShapeHit", root, onColShape ) addEventHandler ( "onColShapeLeave", root, onColShape ) end addEvent ( "onPlayerPullSniper", true ) addEventHandler ( "onPlayerPullSniper", getRootElement(), pullItem ) function onColShapeHit ( hitElement, matchDim ) if ( getElementType ( hitElement ) == "player" and matchDim ) then if ( eventName == "onColShapeHit" ) then inColShape [ hitElement ] = source else inColShape [ hitElement ] = nil end end end function pickupWeapon ( player ) local colshape = inColShape [ player ] if isElement ( colshape ) then if isElementWithinColShape ( player, colshape ) then outputChatBox ( "/recoger", player, 0, 255, 255 ) giveWeapon ( player, getElementData ( colshape, "Arma" ), getElementData ( colshape, "Municion" ) ) destroyElement ( source ) destroyElement ( theWeapon ) inColShape [ player ] = nil end end end Link to comment
Plate Posted May 24, 2013 Author Share Posted May 24, 2013 Me da error en el destroyElement Link to comment
Castillo Posted May 24, 2013 Share Posted May 24, 2013 local inColShape = { } local weapons = { } function bindStart ( ) for _, v in ipairs ( getElementsByType ( "player" ) ) do bindKey ( v, "n", "down", pickupWeapon ) end end addEventHandler ( "onResourceStart", resourceRoot, bindStart ) function login ( ) bindKey ( source, "n", "down", pickupWeapon ) end addEventHandler ( "onPlayerLogin", getRootElement(), login ) function pullItem ( item, ammo ) local x, y, z = getElementPosition ( source ) local colshape = createColTube ( x, y, z, 1, 1 ) weapons [ colshape ] = createObject ( 358, x, y, z - 1, 70, 0, 0 ) setElementData ( colshape, "Arma", 34 ) setElementData ( colshape, "Municion", ammo ) takeWeapon ( source, 34 ) addEventHandler ( "onColShapeHit", root, onColShape ) addEventHandler ( "onColShapeLeave", root, onColShape ) end addEvent ( "onPlayerPullSniper", true ) addEventHandler ( "onPlayerPullSniper", getRootElement(), pullItem ) function onColShapeHit ( hitElement, matchDim ) if ( getElementType ( hitElement ) == "player" and matchDim ) then if ( eventName == "onColShapeHit" ) then inColShape [ hitElement ] = source else inColShape [ hitElement ] = nil end end end function pickupWeapon ( player ) local colshape = inColShape [ player ] if isElement ( colshape ) then if isElementWithinColShape ( player, colshape ) then outputChatBox ( "/recoger", player, 0, 255, 255 ) giveWeapon ( player, getElementData ( colshape, "Arma" ), getElementData ( colshape, "Municion" ) ) destroyElement ( weapons [ source ] ) destroyElement ( source ) inColShape [ player ] = nil end end end Link to comment
Plate Posted May 24, 2013 Author Share Posted May 24, 2013 local inColShape = { } local weapons = { } function bindStart ( ) for _, v in ipairs ( getElementsByType ( "player" ) ) do bindKey ( v, "n", "down", pickupWeapon ) end end addEventHandler ( "onResourceStart", resourceRoot, bindStart ) function login ( ) bindKey ( source, "n", "down", pickupWeapon ) end addEventHandler ( "onPlayerLogin", getRootElement(), login ) function pullItem ( item, ammo ) local x, y, z = getElementPosition ( source ) local colshape = createColTube ( x, y, z, 1, 1 ) weapons [ colshape ] = createObject ( 358, x, y, z - 1, 70, 0, 0 ) setElementData ( colshape, "Arma", 34 ) setElementData ( colshape, "Municion", ammo ) takeWeapon ( source, 34 ) addEventHandler ( "onColShapeHit", root, onColShape ) addEventHandler ( "onColShapeLeave", root, onColShape ) end addEvent ( "onPlayerPullSniper", true ) addEventHandler ( "onPlayerPullSniper", getRootElement(), pullItem ) function onColShapeHit ( hitElement, matchDim ) if ( getElementType ( hitElement ) == "player" and matchDim ) then if ( eventName == "onColShapeHit" ) then inColShape [ hitElement ] = source else inColShape [ hitElement ] = nil end end end function pickupWeapon ( player ) local colshape = inColShape [ player ] if isElement ( colshape ) then if isElementWithinColShape ( player, colshape ) then outputChatBox ( "/recoger", player, 0, 255, 255 ) giveWeapon ( player, getElementData ( colshape, "Arma" ), getElementData ( colshape, "Municion" ) ) destroyElement ( weapons [ source ] ) destroyElement ( source ) inColShape [ player ] = nil end end end Nop antes no se destruia el colshape ahora no se destruye el arma y tampoco el colshape Link to comment
Castillo Posted May 24, 2013 Share Posted May 24, 2013 Pero te da el arma y pone ese mensaje en el chat? Link to comment
Plate Posted May 24, 2013 Author Share Posted May 24, 2013 Si lo unico que no destruye el colshape y el arma Link to comment
Castillo Posted May 24, 2013 Share Posted May 24, 2013 Ah, me olvide de cambiar unas variables. local inColShape = { } local weapons = { } function bindStart ( ) for _, v in ipairs ( getElementsByType ( "player" ) ) do bindKey ( v, "n", "down", pickupWeapon ) end end addEventHandler ( "onResourceStart", resourceRoot, bindStart ) function login ( ) bindKey ( source, "n", "down", pickupWeapon ) end addEventHandler ( "onPlayerLogin", getRootElement(), login ) function pullItem ( item, ammo ) local x, y, z = getElementPosition ( source ) local colshape = createColTube ( x, y, z - 1, 1, 1 ) weapons [ colshape ] = createObject ( 358, x, y, z - 1, 70, 0, 0 ) setElementData ( colshape, "Arma", 34 ) setElementData ( colshape, "Municion", ammo ) takeWeapon ( source, 34 ) addEventHandler ( "onColShapeHit", colshape, onColShape ) addEventHandler ( "onColShapeLeave", colshape, onColShape ) end addEvent ( "onPlayerPullSniper", true ) addEventHandler ( "onPlayerPullSniper", getRootElement(), pullItem ) function onColShape ( hitElement, matchDim ) if ( getElementType ( hitElement ) == "player" and matchDim ) then if ( eventName == "onColShapeHit" ) then inColShape [ hitElement ] = source else inColShape [ hitElement ] = nil end end end function pickupWeapon ( player ) local colshape = inColShape [ player ] if isElement ( colshape ) then if isElementWithinColShape ( player, colshape ) then outputChatBox ( "/recoger", player, 0, 255, 255 ) giveWeapon ( player, getElementData ( colshape, "Arma" ), getElementData ( colshape, "Municion" ) ) destroyElement ( weapons [ colshape ] ) weapons [ colshape ] = nil destroyElement ( colshape ) inColShape [ player ] = nil end end end Link to comment
Plate Posted May 25, 2013 Author Share Posted May 25, 2013 Gracias solid me funciona de 10 te lo agradesco me podrias decir por que esto no anda eto usaba yo para los pickups jaja function getItemInfo() local px, py, pz, tx, ty, tz, dist local px, py, pz = getCameraMatrix() for _, v in ipairs(getElementsByType("object")) do if getElementData(v, "Municion") then local tx, ty, tz = getElementPosition( v ) local dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getElementPosition( v ) local x,y = getScreenFromWorldPosition( sx + 0.9, sy, sz + 0.7 ,100,false ) if x and y then if (v == 358) then local distance = getDistanceBetweenPoints3D(px, py, pz, sx, sy, sz) dxDrawText("item: 1234", x, y+10, x, y, tocolor(245,245,245), 0.60 + ( 15 - dist ) * 0.02, "bankgothic" ) dxDrawText("Ammo: 12345", x, y-5, x, y+100, tocolor(245,245,245), 0.60 + ( 20 - dist ) * 0.02, "bankgothic" ) else return end end end end end end end addEventHandler( "onClientRender",root,getItemInfo) Link to comment
Castillo Posted May 25, 2013 Share Posted May 25, 2013 if (v == 358) then Estas checkeando si "v" es igual a 358, pero "v" es un elemento, tenes que obtener el modelo del objeto con getElementModel Link to comment
Plate Posted May 25, 2013 Author Share Posted May 25, 2013 function getItemInfo() local px, py, pz, tx, ty, tz, dist local px, py, pz = getCameraMatrix() for _, v in ipairs(getElementsByType("object")) do if getElementData(v, "Municion") then local tx, ty, tz = getElementPosition( v ) local dist = math.sqrt( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if dist < 30.0 then if isLineOfSightClear( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false,localPlayer ) then local sx, sy, sz = getElementPosition( v ) local x,y = getScreenFromWorldPosition( sx + 0.9, sy, sz + 0.7 ,100,false ) if x and y then local item = getElementModel(v) outputChatBox(item.."") local distance = getDistanceBetweenPoints3D(px, py, pz, sx, sy, sz) dxDrawText("item: 1234", x, y+10, x, y, tocolor(245,245,245), 0.60 + ( 15 - dist ) * 0.02, "bankgothic" ) dxDrawText("Ammo: 12345", x, y-5, x, y+100, tocolor(245,245,245), 0.60 + ( 20 - dist ) * 0.02, "bankgothic" ) else return end end end end end end end end addEventHandler( "onClientRender",root,getItemInfo) Link to comment
Castillo Posted May 25, 2013 Share Posted May 25, 2013 function getItemInfo ( ) local px, py, pz, tx, ty, tz, dist local px, py, pz = getCameraMatrix ( ) for _, v in ipairs ( getElementsByType ( "object" ) ) do if getElementData ( v, "Municion" ) then local tx, ty, tz = getElementPosition ( v ) local dist = math.sqrt ( ( px - tx ) ^ 2 + ( py - ty ) ^ 2 + ( pz - tz ) ^ 2 ) if ( dist < 30.0 ) then if isLineOfSightClear ( px, py, pz, tx, ty, tz, true, false, false, true, false, false, false, localPlayer ) then local sx, sy, sz = getElementPosition ( v ) local x, y = getScreenFromWorldPosition ( sx + 0.9, sy, sz + 0.7, 100, false ) if ( x and y ) then local item = getElementModel ( v ) outputChatBox ( tostring ( item ) ) local distance = getDistanceBetweenPoints3D ( px, py, pz, sx, sy, sz ) dxDrawText ( "item: 1234", x, y+10, x, y, tocolor(245,245,245), 0.60 + ( 15 - dist ) * 0.02, "bankgothic" ) dxDrawText ( "Ammo: 12345", x, y-5, x, y+100, tocolor(245,245,245), 0.60 + ( 20 - dist ) * 0.02, "bankgothic" ) end end end end end end addEventHandler ( "onClientRender", root, getItemInfo ) Link to comment
Recommended Posts