Scripting Posted June 7, 2012 Share Posted June 7, 2012 Hi all, This a code to make a laser for weapon but he not work, pls fix it if have a problem and thx! client-side: addEventHandler( "onClientRender", getRootElement(), function() local players = getElementsByType("player") for k,v in ipairs(players) do DrawLaser(v) end end ) function DrawLaser(player) local targetself = getPedTarget(player) if targetself and targetself == player then targetself = true else targetself = false end if IsPlayerWeaponValidForLaser(player) == true and targetself == false then local x,y,z = getPedWeaponMuzzlePosition(player) if not x then outputDebugString("getPedWeaponMuzzlePosition failed") x,y,z = getPedTargetStart(player) end local x2,y2,z2 = getPedTargetEnd(player) if not x2 then --outputDebugString("getPedTargetEnd failed") return end local x3,y3,z3 = getPedTargetCollision(player) local r,g,b,a = GetLaserColor(player) if x3 then -- collision detected, draw til collision and add a dot dxDrawLine3D(x,y,z,x3,y3,z3, tocolor(r,g,b,a), laserWidth) DrawLaserDot(player, x3,y3,z3) else -- no collision, draw til end of weapons range dxDrawLine3D(x,y,z,x2,y2,z2, tocolor(r,g,b,a), laserWidth) DestroyLaserDot(player) end else DestroyLaserDot(player) -- not aiming, remove dot, no laser end end function IsPlayerWeaponValidForLaser(player) -- returns false for unarmed and awkward weapons local weapon = getPedWeapon(player) if weapon and weapon > 21 and weapon < 39 and weapon ~= 35 and weapon ~= 36 then return true end return false end function DrawLaserDot (player, x,y,z) if not dots[player] then dots[player] = createMarker(x,y,z, "corona", .05, GetLaserColor(player)) else setElementPosition(dots[player], x,y,z) end end function DestroyLaserDot(player) if dots[player] and isElement(dots[player]) then destroyElement(dots[player]) dots[player] = nil end end 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