aka Blue Posted April 10, 2016 Posted April 10, 2016 Bueno, lo que quiero hacer es que al darle un golpe a x objeto, realice una función. Estoy intentando actualmente con onPlayerDamage pero no funciona. Gracias function golpeObjeto ( attacker, weapon, _, _ ) if weapon == 0 then if getElementType ( source ) == "object" and getElementModel ( source ) == 2001 then outputChatBox ( "s" ) end end end addEventHandler ( "onPlayerDamage", getRootElement (), golpeObjeto )
Arsilex Posted April 10, 2016 Posted April 10, 2016 No funciona de esa manera, el evento onPlayerDamage como bien dice en español es Cuando el jugador es dañado es decir que este evento solo se ejecuta cuando un jugador es dañando lo que ahora mismo se me ocurre que puedas usar es onPlayerContact por que un objeto no puede ser dañado en si ya que no tiene vida.
aka Blue Posted April 10, 2016 Author Posted April 10, 2016 Mmmm, sigue sin funcionar. function pegarVentana ( _, current ) if ( current ) then if ( getElementType ( current ) == "object" and getElementModel ( current ) == 2900 ) then outputChatBox ( "ola" ) end end end addEventHandler ( "onPlayerContact", getRootElement(), pegarVentana )
Tomas Posted April 10, 2016 Posted April 10, 2016 No funciona de esa manera, el evento onPlayerDamage como bien dice en español es Cuando el jugador es dañado es decir que este evento solo se ejecuta cuando un jugador es dañando lo que ahora mismo se me ocurre que puedas usar es onPlayerContact por que un objeto no puede ser dañado en si ya que no tiene vida. El onPlayerContact es para cuando está sobre algo. onClientObjectDamage podría servirte.
aka Blue Posted April 10, 2016 Author Posted April 10, 2016 Sigue sin ir, no lo entiendo. local x, y = guiGetScreenSize ( ) local golpes = 0 function dxDrawTextAllResolutions (v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) dxDrawText(v1, v2/1280*x, v3/800*y, v4/1280*x, v5/800*y, v6, v7/1280*x, v8, v9, v10, v11, v12, v13, v14, v15) end function render ( ) addEventHandler ( "onClientRender", getRootElement ( ), dibujarTest ) end function dibujarTest ( ) dxDrawTextAllResolutions("Llevas "..golpes.." golpes", 500, 703, 614, 694, tocolor(0, 0, 0, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false) dxDrawTextAllResolutions("Llevas "..golpes.." golpes", 500, 700, 614, 694, tocolor(255, 255, 255, 255), 1.00, "bankgothic", "left", "top", false, false, false, false, false) end function pegar ( loss, attacker ) outputChatBox ( "hey" ) render ( ) end addEventHandler ( "onClientObjectDamage", root, pegar )
Enargy, Posted April 10, 2016 Posted April 10, 2016 RequirementsMinimum supported server n/a Minimum supported client 1.3-9.05086 Note: Using this function requires the resource to have the above minimum version declared in the meta.xml section. e.g.
Enargy, Posted April 10, 2016 Posted April 10, 2016 Tengo la última versión, no sé. Agrega esto en el meta
aka Blue Posted April 10, 2016 Author Posted April 10, 2016 Me da éste error: contains invalid version strings.
Enargy, Posted April 10, 2016 Posted April 10, 2016 Tienes que interactuarte con el streaming del objeto que golpeas con setElementStreamable, lo he probado con esto y un objeto que hice y funcionó. La misma wiki te dice que solo funciona con objetos streamables (no se que significa en ingles ).
aka Blue Posted April 10, 2016 Author Posted April 10, 2016 No entendí, ¿qué evento debo usar entonces? pd:
aka Blue Posted April 12, 2016 Author Posted April 12, 2016 Nada, sigue sin funcionar. Aquí mi código cliente: saco1 = createObject ( 1985, 140.351, 2510.98, 18.9705 ) saco2 = createObject ( 1985, 139.841, 2516.55, 18.9399 ) setElementDimension ( saco1, 15 ) setElementDimension ( saco2, 15 ) setElementInterior ( saco1, 0 ) setElementInterior ( saco2, 0 ) local function testNonStreamableObjects() setElementStreamable ( saco1, false ) setElementStreamable ( saco2, false ) end addEventHandler ( "onClientResourceStart", resourceRoot, testNonStreamableObjects ) function outputLoss(loss) if isElementStreamable ( source ) then local oldHealth = getElementHealth(source) setTimer(function() local newHealth = getElementHealth(source) outputChatBox("Real loss: "..(newHealth-oldHealth)) outputChatBox("Theoretical loss: "..loss) end,100,1) end end addEventHandler("onClientObjectDamage", root, outputLoss)
Enargy, Posted April 13, 2016 Posted April 13, 2016 Quita lo del streaming, no tiene mucho que ver. Yo lo probe sin el streaming y cuandl lo golpee no hizo nada.
Enargy, Posted April 13, 2016 Posted April 13, 2016 Nada, sigue sin funcionar. Aquí mi código cliente: saco1 = createObject ( 1985, 140.351, 2510.98, 18.9705 ) saco2 = createObject ( 1985, 139.841, 2516.55, 18.9399 ) setElementDimension ( saco1, 15 ) setElementDimension ( saco2, 15 ) setElementInterior ( saco1, 0 ) setElementInterior ( saco2, 0 ) local function testNonStreamableObjects() setElementStreamable ( saco1, false ) setElementStreamable ( saco2, false ) end addEventHandler ( "onClientResourceStart", resourceRoot, testNonStreamableObjects ) function outputLoss(loss) if isElementStreamable ( source ) then local oldHealth = getElementHealth(source) setTimer(function() local newHealth = getElementHealth(source) outputChatBox("Real loss: "..(newHealth-oldHealth)) outputChatBox("Theoretical loss: "..loss) end,100,1) end end addEventHandler("onClientObjectDamage", root, outputLoss) Cambia el booleano del setElementStreamable a true.
El_Zorro Posted April 13, 2016 Posted April 13, 2016 Cuando crees el objeto, le das un setElementData (object, "healthObject", 100) function objectLoss(loss) if getElementData (source, "healthObject") then local oldHealth = getElementData (source, "healthObject") if loss >= 0 then local newHealth = oldHealth - loss setElementData (source, "healthObject", newHealth) end if getElementData (source, "healthObject") <= 0 then -- destroyElement(source) -- SI DESEAS QUE SE DESTRUYA EL OBJETO end end end addEventHandler("onClientObjectDamage", root, objectLoss)
Enargy, Posted April 13, 2016 Posted April 13, 2016 Cuando crees el objeto, le das un setElementData (object, "healthObject", 100) function objectLoss(loss) if getElementData (source, "healthObject") then local oldHealth = getElementData (source, "healthObject") if loss >= 0 then local newHealth = oldHealth - loss setElementData (source, "healthObject", newHealth) end if getElementData (source, "healthObject") <= 0 then -- destroyElement(source) -- SI DESEAS QUE SE DESTRUYA EL OBJETO end end end addEventHandler("onClientObjectDamage", root, objectLoss) Eso no tiene nada que ver con que el evento le funcione, dice que no me hace nada.
El_Zorro Posted April 13, 2016 Posted April 13, 2016 Que no le funciona el evento "OnClientObjectDamage" cuando le dispara al objeto?, quizás no será porque lo tiene en la dimensión del elemento en 15?
Recommended Posts