Xwad Posted July 25, 2015 Share Posted July 25, 2015 Hi. I want to make a script that makes possible that when i press mouse2 in the rhino then it will aim with a scope. Here is a script but its not working:/ Whats the problem?? local textures = {}; local function render_crosshair () local screenw, screenh = guiGetScreenSize (); local s = screenw * 0.5; local u,v = (screenw - s)*0.5, (screenh - s)*0.5; local black = tocolor (0, 0, 0, 255); dxDrawRectangle (0, 0, screenw, v, black); dxDrawRectangle (0, 0, u, screenh, black); dxDrawRectangle (0, screenh, screenw, -v, black); dxDrawRectangle (screenw, screenh, -u, -screenh, black); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair_background"]); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); end; local function on_weapon_aimed (key, state) if isPedInVehicle(source) then if (getElementModel(source) == 432) then if state == "down" then showPlayerHudComponent ("crosshair", false); addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); else removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); end; end; end; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () -- load textures. textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap"); if not textures ["crosshair"] then outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1); return; end; textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap"); if not textures ["crosshair_background"] then outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1); return; end; bindKey ("aim_weapon", "both", on_weapon_aimed); addEventHandler ("onClientPlayerWeaponSwitch", getRootElement (), function (previousWeaponSlot) local weaponslot_type_sniper = 6; if previousWeaponSlot == weaponslot_type_sniper then if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end; end); end); addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), function () unbindKey ("aim_weapon", "both", on_weapon_aimed); if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end); Link to comment
Xwad Posted July 25, 2015 Author Share Posted July 25, 2015 eeror loading script failed: scope=client.lua64: 'end' expected to close 'function' at line 19) near ' ' Link to comment
GTX Posted July 25, 2015 Share Posted July 25, 2015 local textures = {}; local function render_crosshair () local screenw, screenh = guiGetScreenSize (); local s = screenw * 0.5; local u,v = (screenw - s)*0.5, (screenh - s)*0.5; local black = tocolor (0, 0, 0, 255); dxDrawRectangle (0, 0, screenw, v, black); dxDrawRectangle (0, 0, u, screenh, black); dxDrawRectangle (0, screenh, screenw, -v, black); dxDrawRectangle (screenw, screenh, -u, -screenh, black); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair_background"]); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); end; local function on_weapon_aimed (key, state) if isPedInVehicle(source) then if (getElementModel(source) == 432) then if state == "down" then showPlayerHudComponent ("crosshair", false); addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); else removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); end; end; end end; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () -- load textures. textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap"); if not textures ["crosshair"] then outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1); return; end; textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap"); if not textures ["crosshair_background"] then outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1); return; end; bindKey ("aim_weapon", "both", on_weapon_aimed); addEventHandler ("onClientPlayerWeaponSwitch", getRootElement (), function (previousWeaponSlot) local weaponslot_type_sniper = 6; if previousWeaponSlot == weaponslot_type_sniper then if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end; end); end); addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), function () unbindKey ("aim_weapon", "both", on_weapon_aimed); if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end); Link to comment
Army@1 Posted July 25, 2015 Share Posted July 25, 2015 Well, that is really a self-explanatory thing. It says you forgot to put an 'end' to close the function which starts at line 19. In that case, the below code will work: local textures = {}; local function render_crosshair () local screenw, screenh = guiGetScreenSize (); local s = screenw * 0.5; local u,v = (screenw - s)*0.5, (screenh - s)*0.5; local black = tocolor (0, 0, 0, 255); dxDrawRectangle (0, 0, screenw, v, black); dxDrawRectangle (0, 0, u, screenh, black); dxDrawRectangle (0, screenh, screenw, -v, black); dxDrawRectangle (screenw, screenh, -u, -screenh, black); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair_background"]); dxDrawImage (u, v, screenw-2*u, screenh-2*v, textures ["crosshair"]); end; local function on_weapon_aimed (key, state) if isPedInVehicle(source) then if (getElementModel(source) == 432) then if state == "down" then showPlayerHudComponent ("crosshair", false); addEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); else removeEventHandler ("onClientHUDRender", getRootElement (), render_crosshair); end; end; end; end; addEventHandler ("onClientResourceStart", getResourceRootElement (getThisResource ()), function () -- load textures. textures ["crosshair"] = dxCreateTexture ("images/PKS-07_crosshair.png", "argb", true, "wrap"); if not textures ["crosshair"] then outputDebugString ("failed to load \"images/PKS-07_crosshair.png\" texture", 1); return; end; textures ["crosshair_background"] = dxCreateTexture ("images/PKS-07_crosshair_background.png", "argb", true, "wrap"); if not textures ["crosshair_background"] then outputDebugString ("failed to load \"images/PKS-07_crosshair_background.png\" texture", 1); return; end; bindKey ("aim_weapon", "both", on_weapon_aimed); addEventHandler ("onClientPlayerWeaponSwitch", getRootElement (), function (previousWeaponSlot) local weaponslot_type_sniper = 6; if previousWeaponSlot == weaponslot_type_sniper then if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end; end); end); addEventHandler ("onClientResourceStop", getResourceRootElement (getThisResource ()), function () unbindKey ("aim_weapon", "both", on_weapon_aimed); if not isPlayerHudComponentVisible ("crosshair") then showPlayerHudComponent ("crosshair", true); end; end); Link to comment
Arnold-1 Posted July 26, 2015 Share Posted July 26, 2015 i'm pretty sure there is no function to detect where is the rhino aiming so you would aim in that direction. Link to comment
Xwad Posted July 28, 2015 Author Share Posted July 28, 2015 ok i fixed but there is a problem that i still cant fix. Its the camera zoom. When i press mouse2 then itt will show the crosshair but its not zooming and i can see my ped:/ what functions need i use for that? Link to comment
Xwad Posted July 28, 2015 Author Share Posted July 28, 2015 But setCameraMatrix is for set the camera to a fix point no? i want to use this crosshair like a sniper crosshair but in rhino vehicle Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 To zoom in the camera, you need setCameraMatrix, and no, it's not only for a static point. Link to comment
Xwad Posted July 28, 2015 Author Share Posted July 28, 2015 but i want to make that if im in the tanks and press mouse2 then it will aim like a sniper Link to comment
GTX Posted July 28, 2015 Share Posted July 28, 2015 Draw an image over whole screen then. And if you want, set player's alpha to 0, to hide the player. Link to comment
Xwad Posted July 30, 2015 Author Share Posted July 30, 2015 but i dont want to hide the player i just want to zoom. You know for example world of tanks . When you in the tank and press mouse 2 then it will zoom with a scope Link to comment
GTX Posted July 30, 2015 Share Posted July 30, 2015 Zoom in with setCameraMatrix as I told you before. Link to comment
Xwad Posted July 30, 2015 Author Share Posted July 30, 2015 noo you dont understand me. I want to use it like a sniper scope just in vehicle Link to comment
GTX Posted July 30, 2015 Share Posted July 30, 2015 The only way to zoom in is with setCameraMatrix. If you have any other idea, why do you keep asking? Link to comment
Xwad Posted July 30, 2015 Author Share Posted July 30, 2015 nad can i aim with sniper scope in vehicle? 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