aka Blue Posted August 22, 2015 Share Posted August 22, 2015 Bueno, acabo de terminar mi script de drogas y querría saber si hay alguna funcion para que al jugador, tras tomar la droga, le ponga un efecto de borracho quizás unos 20 segundos o así. Link to comment
aka Blue Posted August 22, 2015 Author Share Posted August 22, 2015 ¿Cómo sería exactamente para server-side? Link to comment
El_Zorro Posted August 22, 2015 Share Posted August 22, 2015 Client local root = getRootElement() local resourceRoot = getResourceRootElement(getThisResource()) local screenWidth, screenHeight = guiGetScreenSize() local blurStrength = 6 local myScreenSource = dxCreateScreenSource(screenWidth, screenHeight) addEventHandler("onClientResourceStart", resourceRoot, function() if getVersion ().sortable < "1.3.1" then return else blurShader, blurTec = dxCreateShader("shaders/BlurShader.fx") end end) addEventHandler("onClientPreRender", root, function() if (blurShader) then dxUpdateScreenSource(myScreenSource) dxSetShaderValue(blurShader, "ScreenSource", myScreenSource); dxSetShaderValue(blurShader, "BlurStrength", blurStrength); dxSetShaderValue(blurShader, "UVSize", screenWidth, screenHeight); dxDrawImageSection(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, blurShader) end end) addEventHandler("onClientResourceStop", resourceRoot, function() if (blurShader) then destroyElement(blurShader) blurShader = nil end end) shaders/BlurShader.fx texture ScreenSource; float BlurStrength; float2 UVSize; sampler TextureSampler = sampler_state { Texture = <ScreenSource>; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; static const float2 poisson[16] = { float2(-0.326212f, -0.40581f), float2(-0.840144f, -0.07358f), float2(-0.695914f, 0.457137f), float2(-0.203345f, 0.620716f), float2(0.96234f, -0.194983f), float2(0.473434f, -0.480026f), float2(0.519456f, 0.767022f), float2(0.185461f, -0.893124f), float2(0.507431f, 0.064425f), float2(0.89642f, 0.412458f), float2(-0.32194f, -0.932615f), float2(-0.65432f, -0.87421f), float2(-0.456899f, -0.633247f), float2(-0.123456f, -0.865433f), float2(-0.664332f, -0.25680f), float2(-0.791559f, -0.59771f) }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); for(int i = 0; i < 16; i++) { float2 coord= TextureCoordinate.xy + (poisson[i] / UVSize * BlurStrength); color += tex2D(TextureSampler, coord); } return(color/17); } technique BlurShader { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } Link to comment
El_Zorro Posted August 22, 2015 Share Posted August 22, 2015 ¿Cómo sería exactamente para server-side? Usa un triggerClientEvent y en el evento añadido, colocas el evento onClientRender Link to comment
aka Blue Posted August 22, 2015 Author Share Posted August 22, 2015 ¿Algo así? function mareoextremo() setBlurLevel ( 1000 ) end function mareito() addEventHandler("onClientRender", getRootElement(), mareoextremo) end addEvent("onTomar", true) addEventHandler("onTomar", getRootElement(), mareito) triggerClientEvent(thePlayer, "onTomar", thePlayer) ¿Se le podría poner un timer al efecto? Link to comment
Platin Posted August 22, 2015 Share Posted August 22, 2015 ¿Algo así? function mareoextremo() setBlurLevel ( 1000 ) end function mareito() addEventHandler("onClientRender", getRootElement(), mareoextremo) end addEvent("onTomar", true) addEventHandler("onTomar", getRootElement(), mareito) triggerClientEvent(thePlayer, "onTomar", thePlayer) ¿Se le podría poner un timer al efecto? Podrías usar getElementData y setElementData. Link to comment
El_Zorro Posted August 22, 2015 Share Posted August 22, 2015 Pruebalo así y recuerda añadir el shader .fx Ejemplo usando granadas para activar la función blur shader: Client side local root = getRootElement() local resourceRoot = getResourceRootElement(getThisResource()) local screenWidth, screenHeight = guiGetScreenSize() local blurStrength = 6 local myScreenSource = dxCreateScreenSource(screenWidth, screenHeight) addEventHandler("onClientResourceStart", resourceRoot, function() if getVersion ().sortable < "1.3.1" then return else blurShader, blurTec = dxCreateShader("shaders/BlurShader.fx") end end) function mareo() if (blurShader) then dxUpdateScreenSource(myScreenSource) dxSetShaderValue(blurShader, "ScreenSource", myScreenSource); dxSetShaderValue(blurShader, "BlurStrength", blurStrength); dxSetShaderValue(blurShader, "UVSize", screenWidth, screenHeight); dxDrawImageSection(0, 0, screenWidth, screenHeight, 0, 0, screenWidth, screenHeight, blurShader) end end function beginDrugsEffect () addEventHandler("onClientPreRender", root, mareo) end addEvent("DrugsEffectOn", true) addEventHandler("DrugsEffectOn", root, beginDrugsEffect) function StopDrugsEffect () removeEventHandler("onClientPreRender", root, mareo) end addEvent("DrugsEffectStop", true) addEventHandler("DrugsEffectStop", root, StopDrugsEffect) addEventHandler("onClientResourceStop", resourceRoot, function() if (blurShader) then destroyElement(blurShader) blurShader = nil end end) Server side (Source es el jugador que activa el trigger, source si lo usas con algún evento para jugador.) Activar el efecto desde server triggerClientEvent(source, "DrugsEffectOn", source) Detener el efecto desde server triggerClientEvent(source, "DrugsEffectStop", source) shaders/BlurShader.fx texture ScreenSource; float BlurStrength; float2 UVSize; sampler TextureSampler = sampler_state { Texture = ; MinFilter = Linear; MagFilter = Linear; MipFilter = Linear; AddressU = Wrap; AddressV = Wrap; }; static const float2 poisson[16] = { float2(-0.326212f, -0.40581f), float2(-0.840144f, -0.07358f), float2(-0.695914f, 0.457137f), float2(-0.203345f, 0.620716f), float2(0.96234f, -0.194983f), float2(0.473434f, -0.480026f), float2(0.519456f, 0.767022f), float2(0.185461f, -0.893124f), float2(0.507431f, 0.064425f), float2(0.89642f, 0.412458f), float2(-0.32194f, -0.932615f), float2(-0.65432f, -0.87421f), float2(-0.456899f, -0.633247f), float2(-0.123456f, -0.865433f), float2(-0.664332f, -0.25680f), float2(-0.791559f, -0.59771f) }; float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0 { float4 color = tex2D(TextureSampler, TextureCoordinate); for(int i = 0; i < 16; i++) { float2 coord= TextureCoordinate.xy + (poisson[i] / UVSize * BlurStrength); color += tex2D(TextureSampler, coord); } return(color/17); } technique BlurShader { pass Pass1 { PixelShader = compile ps_2_0 PixelShaderFunction(); } } Link to comment
aka Blue Posted August 22, 2015 Author Share Posted August 22, 2015 Lo pongo desde el VPS así puedo publicar el error. [2015-08-22 15:31:33] SCRIPT ERROR: shaders/BlurShader.fx:1: '=' expected near 'ScreenSource' [2015-08-22 15:31:33] ERROR: Loading script failed: shaders/BlurShader.fx:1: '=' expected near 'ScreenSource' [2015-08-22 15:31:33] shaders restarted successfully Link to comment
Platin Posted August 22, 2015 Share Posted August 22, 2015 Lo pongo desde el VPS así puedo publicar el error. [2015-08-22 15:31:33] SCRIPT ERROR: shaders/BlurShader.fx:1: '=' expected near 'ScreenSource' [2015-08-22 15:31:33] ERROR: Loading script failed: shaders/BlurShader.fx:1: '=' expected near 'ScreenSource' [2015-08-22 15:31:33] shaders restarted successfully En caso de que sea un if: if (he == you) then -- No tenes que poner un =, tenes que poner dos. Si no es eso, pasa la linea. Link to comment
aka Blue Posted August 22, 2015 Author Share Posted August 22, 2015 La línea es lo que pasó el zorro. Ni idea de por qué me da ese error cuando ahí no hay ningun "=". texture ScreenSource; float BlurStrength; float2 UVSize; Link to comment
El_Zorro Posted August 22, 2015 Share Posted August 22, 2015 Como ejemplo: Link Resource: https://community.multitheftauto.com/ind ... s&id=11964 Link to comment
aka Blue Posted August 22, 2015 Author Share Posted August 22, 2015 No puse bien el meta.xml :facepalm: PD: Voy a probar ahora. Link to comment
El_Zorro Posted August 23, 2015 Share Posted August 23, 2015 Ya depende de vos. Allí tienes toda la información. Link to comment
Recommended Posts