MAB Posted September 8, 2015 Share Posted September 8, 2015 i made a custom cross hair .png with photoshop now how to replace the default cross hair with the one i made?! Link to comment
KariiiM Posted September 8, 2015 Share Posted September 8, 2015 (edited) First of all, you have to disable the current crosshair of the player. You can hide this with showPlayerHudComponent. After that, you should add an event handler with the event onClientRender whenever the user is using the control 'aim' ( getControlState if I'm not mistaken. ). In the render, you should use dxDrawImage to render the actual image. Don't forget to remove the event handler when the user stops aiming! so, you need to use NOTE: almost all of these functions are client sided only --functions guiGetScreenSize dxDrawImage getPedTargetEnd getScreenFromWorldPosition --events onClientRender or onClientPreRender for hiding the default crosshair, you have to use this code: addEventHandler ( "onResourceStart", getRootElement(), function () setPlayerHudComponentVisible ( source, "crosshair", false ) end ) ~Good luck with scripting Regards, KariM Edited September 8, 2015 by Guest Link to comment
Markeloff Posted September 8, 2015 Share Posted September 8, 2015 function crosshair() local texture = dxCreateTexture ("YOURCROSSHAIR.png") local shader = dxCreateShader ( "sh.fx" ) dxSetShaderValue ( shader, "gTexture", texture ) engineApplyShaderToWorldTexture ( shader, "sitem16") end addEventHandler( "onClientResourceStart", resourceRoot,crosshair) This is sh.fx, just create a .fx and copy these lines. The file must be included in meta.xml. texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } Link to comment
Castillo Posted September 8, 2015 Share Posted September 8, 2015 for hiding the default crosshair, you have to use this code: addEventHandler ( "onResourceStart", getRootElement(), function () setPlayerHudComponentVisible ( source, "crosshair", false ) end ) 'source' is not a player when using 'onResourceStart', it's the root element in the resource that started. Link to comment
KariiiM Posted September 8, 2015 Share Posted September 8, 2015 'source' is not a player when using 'onResourceStart', it's the root element in the resource that started. Yes you're right ,i didn't take attention as the wiki said The source of this event is the root element in the resource that started. So , since almost all of these events are client sided so you can hide the default crosshair in client side too addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), function () setPlayerHudComponentVisible ("crosshair", false ) end) Link to comment
MAB Posted September 9, 2015 Author Share Posted September 9, 2015 function crosshair() local texture = dxCreateTexture ("YOURCROSSHAIR.png") local shader = dxCreateShader ( "sh.fx" ) dxSetShaderValue ( shader, "gTexture", texture ) engineApplyShaderToWorldTexture ( shader, "sitem16") end addEventHandler( "onClientResourceStart", resourceRoot,crosshair) This is sh.fx, just create a .fx and copy these lines. The file must be included in meta.xml. texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } nice but my .png is just a red circle that was meant to look like if the player is aiming with laser anyway i tried what you said and it works but when i aim it is showing me a white point and four of my .png around it and when i shoot the white point goes and the four points move.... so this wasn't what i meant i just wanted to replace the gta sa cross hair with a red circle.. Link to comment
MAB Posted September 10, 2015 Author Share Posted September 10, 2015 someone can help please? Link to comment
KariiiM Posted September 10, 2015 Share Posted September 10, 2015 With what? try something by yourself we gave you the light to start, so try if you failed post the code Link to comment
MAB Posted September 10, 2015 Author Share Posted September 10, 2015 With what? try something by yourself we gave you the light to start, so try if you failed post the code this light isn't what i wanted.... it creates four of my .png around a white point and when i shoot they moves.. this wasn't what i needed.. i want to replace the gta cross hair with my .png just that .. my .png is just a red point Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 (edited) Okay, follow me step by step --Create your Meta and full it with that 1) create file name it client.lua 2) create file name it shader.fx 3)create file name it texreplace.fx note: you can change crosshair.png to your image name --After creating the files and defining them in the meta.xml, now it's the time to fill them with codes: --client.lua : local texture = { --don't forget to change this to your image.png name ! or it won't works or simply change your image to crosshair.png name { "crosshair.png", "crosshair"} } addEventHandler("onClientResourceStart", resourceRoot, function() for i = 1, #texture do --looping the table texture for create texture local shader = dxCreateShader("shader.fx") engineApplyShaderToWorldTexture(shader, texture[i][2]) dxSetShaderValue(shader, "gTexture", dxCreateTexture(texture[i][1])) end end) --shader.fx texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } Edited September 11, 2015 by Guest Link to comment
MAB Posted September 11, 2015 Author Share Posted September 11, 2015 Okay, follow me step by step --Create your Meta and full it with that 1) create file name it client.lua 2) create file name it shader.fx 3)create file name it texreplace.fx note: you can change crosshair.png to your image name --After creating the files and defining them in the meta.xml, now it's the time to fill them with codes: --client.lua : local texture = { --don't forget to change this to your image.png name ! or it won't works or simply change your image to crosshair.png name { "crosshair.png", "crosshair"} } addEventHandler("onClientResourceStart", resourceRoot, function() for i = 1, #texture do --looping the table texture for create texture local shader = dxCreateShader("shader.fx") engineApplyShaderToWorldTexture(shader, texture[i][2]) dxSetShaderValue(shader, "gTexture", dxCreateTexture(texture[i][1])) end end) --texreplace.fx texture gTexture; technique TexReplace { pass P0 { // Set the texture Texture[0] = gTexture; } } --shader.fx texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } you didn't mention what is the resourceRoot anyway i did and it still not working Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 Why 2 shaders that do the exact same thing? Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 Why 2 shaders that do the exact same thing? My bad i forgot,i was going to change the files name edited, thanks ! you didn't mention what is the resourceRoot anyway i did and it still not working it working now (tested) --client.lua local texture = { { "crosshair.png", "sitem16"} } addEventHandler("onClientResourceStart", resourceRoot, function() for i = 1, #texture do local shader = dxCreateShader("shader.fx") engineApplyShaderToWorldTexture(shader, texture[i][2]) dxSetShaderValue(shader, "gTexture", dxCreateTexture( texture[i][1])) end end) addEventHandler ( "onClientResourceStart", resourceRoot,function () setPlayerHudComponentVisible ("crosshair", true ) end) --shader.fx texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } --meta.xml Link to comment
MAB Posted September 11, 2015 Author Share Posted September 11, 2015 -_______- i said i want to replace my .png with the fking cross hair -____- these codes does the same of the other codes up there the fking codes create a dam white point and 4 red points around it that is 4 of my .png and also that white point goes when i shoot and the 4 .pngs moves -____- just want to replace my .png which is a god dam red point with the gta cross hair .. is that hard?! Link to comment
Markeloff Posted September 11, 2015 Share Posted September 11, 2015 Can you post your crosshair png? This is an example of a crosshair. It has to be 1/4 circular cropped like this. Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 is that hard?! You tell me? If it's not hard, why are you posting for help? How about you chill? YOU are the one who's failing, and THEY are trying to help you. Your English isn't helping either. Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 -_______-i said i want to replace my .png with the fking cross hair -____- these codes does the same of the other codes up there the fking codes create a dam white point and 4 red points around it that is 4 of my .png and also that white point goes when i shoot and the 4 .pngs moves -____- just want to replace my .png which is a god dam red point with the gta cross hair .. is that hard?! Some respect please we are not your personal scripting assistant , i tried to help you and what i wrote is tested and working before i post it here also it do what you're looking for ,if it doesn't works for you that's mean you failed something it's your problem then. Link to comment
MAB Posted September 11, 2015 Author Share Posted September 11, 2015 here is a pic of it.. idk how to share it http://prntscr.com/8f9vz4 Link to comment
MAB Posted September 11, 2015 Author Share Posted September 11, 2015 is that hard?! You tell me? If it's not hard, why are you posting for help? How about you chill? YOU are the one who's failing, and THEY are trying to help you. Your English isn't helping either. why don't u help? u just show up when it is time to lock a topic Link to comment
KariiiM Posted September 11, 2015 Share Posted September 11, 2015 here is a pic of it.. idk how to share ithttp://prntscr.com/8f9vz4 Just name your picture to crosshair.png and do what i did exactly it's tested and working fine Okay, follow me step by step --Create your Meta and full it with that 1) create file name it client.lua 2) create file name it shader.fx 3)create file name it texreplace.fx note: you can change crosshair.png to your image name --After creating the files and defining them in the meta.xml, now it's the time to fill them with codes: --client.lua : local texture = { --don't forget to change this to your image.png name ! or it won't works or simply change your image to crosshair.png name { "crosshair.png", "crosshair"} } addEventHandler("onClientResourceStart", resourceRoot, function() for i = 1, #texture do --looping the table texture for create texture local shader = dxCreateShader("shader.fx") engineApplyShaderToWorldTexture(shader, texture[i][2]) dxSetShaderValue(shader, "gTexture", dxCreateTexture(texture[i][1])) end end) --shader.fx texture gTexture; technique TexReplace { pass P0 { Texture[0] = gTexture; } } Link to comment
JR10 Posted September 11, 2015 Share Posted September 11, 2015 I don't help? Take a look around on the forums. Please refrain from being aggressive and understand that they're actually spending their time trying to help you. Now, let's stay on-topic. Link to comment
MAB Posted September 11, 2015 Author Share Posted September 11, 2015 Karim ik it is working but i don't want a moving five points i want just a red point that doesn't move when i shoot and that red point is my .png Link to comment
KariiiM Posted September 12, 2015 Share Posted September 12, 2015 Karim ik it is working but i don't want a moving five points i want just a red point that doesn't move when i shoot and that red point is my .png Do you know why it showing five red points on your screen?,because you didn't make it like an crosshair. Here is a list of crosshairs http://crosshairs.cali-kartell.de But oks, i have another way maybe it fit your problem i just made it for you local width, height = guiGetScreenSize() -- getting the screensize local x, y = width/1360, height/768 --it's my MTA Resolutions addEventHandler("onClientRender", root, function () if getControlState("aim_weapon") then -- checking if the player is aiming dxDrawImage (width-(27*x),height-(27*y),56*x,56*y,"crosshair.png") --it will draw the image in middle of the screen at the crosshair place. end end) --This function for hiding the default crosshair addEventHandler ( "onClientResourceStart", getResourceRootElement(getThisResource()), function () setPlayerHudComponentVisible ("crosshair", false ) end) ~Regards KariM 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