Jump to content

[HELP]attachElements question


Chrimam

Recommended Posts

How can i attach something to a ped's/player's weapon? I tried to attach a marker to a weapon so that wherever you aim, the marker will go there. I tried aimX, aimY, aimZ = getPedWeaponMuzzlePosition(getLocalPlayer()) but i think i made it wrong. and i don't know how to attach something to coordinates/weapon's muzzle position. Can you help me?

function myWeaponMarker(weapon) 
    if weapon == 24 then 
                playerX, playerY, playerZ = getElementPosition(getLocalPlayer()) 
                muzX, muzY, muzZ = getPedWeaponMuzzlePosition(getLocalPlayer()) 
                   weaponMarker = createMarker(playerX, playerY, playerZ, "corona", 0.5, 255, 0, 0, 170) 
///this is where the attaching script will go. 
end              
end 
addEventHandler("onClientPlayerTarget", getRootElement(), myWeaponMarker) 

Edited by Guest
Link to comment

hmm this event will be handled when you face a player or aim him

addEventHandler ( "onPlayerTarget",root, 
function (target) 
if getElementType (target) == "player" then -- if target is a player then 
local playerX, playerY, playerZ = getElementPosition(target) -- get his position 
weaponMarker = createMarker(playerX, playerY, playerZ, "corona", 0.5, 255, 0, 0, 170) -- create marker in his position 
attachElements(weaponMarker,target) -- attach the marker to the target 
end 
end) 

and this will be handled if you clicked the right button of mouse and checks the element etc..

addEventHandler("onPlayerClick",root, 
function (b,s) 
if p == "right" and s == "down" then -- if clicked button was right and buttons state is down then 
if  getElementType (getPedTarget(source)) == "player" then -- if target is a player then 
local playerX, playerY, playerZ = getElementPosition(getPedTarget (source)) -- get his position 
weaponMarker = createMarker(playerX, playerY, playerZ, "corona", 0.5, 255, 0, 0, 170) -- create a marker in his position 
attachElements(weaponMarker,getPedTarget (source)) -- attach the marker to the target 
end 
end 
end) 

i hope this will help you

i've wrote it quickly, forgive me if there's mistake in it

Link to comment

I don't get any errors but "badArgument @ destroyObject" which works fine for me. But anyways, I can't attach my marker to weapon (i mean set the marker's position everytime frame changes) :/

function powerTeleport(weapon, ammo, ammoInClip, hitX, hitY, hitZ, hitElement) 
    if weapon == 24 then 
        playerX, playerY, playerZ = getElementPosition(getLocalPlayer()) 
            rotX, rotY, rotZ = getElementRotation(getLocalPlayer()) 
                teleportObject = createObject(1337, playerX, playerY, playerZ) 
                    setElementCollisionsEnabled(teleportObject, false) 
                        setElementAlpha(teleportObject, 0) 
                            attachElements(getLocalPlayer(), teleportObject, 0, 0, 0, 0, 0, 0) 
                                moveObject( teleportObject, 1000, hitX, hitY, hitZ, rotX, rotY, rotZ ) 
                                    setTimer(destroyTeleportObject, 1100, 1) 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), powerTeleport) 
  
function destroyTeleportObject(teleportObject) 
    detachElements(getLocalPlayer(), teleportObject) 
        destroyElement(teleportObject) 
end 
  
  
function powerTeleportMarker(weapon, playerX, playerY, playerZ) 
    if weapon == 24 then 
        muzX, muzY, muzZ = getPedWeaponMuzzlePosition(getLocalPlayer()) 
            teleportMarker = createMarker(0, 0, 10, "corona", 1, 255, 0, 0, 170) 
                setElementPosition(teleportMarker, playerX, playerY, playerZ) 
                    addEventHandler("onClientPreRender", getRootElement(), 
function(teleportMarker, muzX, muzY, muzZ) 
setElementPosition(teleportMarker, muzX, muzY, muzZ) 
end) 
    end 
end 
addEventHandler("onClientPlayerTarget", getRootElement(), powerTeleportMarker) 

Link to comment
x,y,z = getElementPosition(getLocalPlayer()) 
weaponMarker = createMarker(x, y, z, "corona", 0.5, 255, 0, 0, 170) 
addEventHandler ( "onClientPreRender", root, 
function () 
if getPlayerWeapon(getLocalPlayer()) == 24 then 
muzX, muzY, muzZ = getPedWeaponMuzzlePosition(getLocalPlayer()) 
setElementPosition(weaponMarker,muzX, muzY, muzZ) 
end 
end) 

hmm i didn't try it but it should work

Link to comment

Uh it attaches marker to the weapon but i got a problem. whenever i look to an object (vehicles, peds or things added by scripts/maps), it creates a red marker on it (no it doesn't attach). and i don't want my marker to appear everytime i get desert eagle, i want it to appear when i aim. Hope you got the point :/ (the red marker on my leg is the marker attached to the weapon)

mta-screen_2013-02-20_17-49-03.png

Link to comment

Try this: (Not Tested)

addEventHandler("onClientPreRender", root, 
function() 
    if getControlState("aim_weapon") and getPedWeapon(localPlayer) == 24 then 
        local muzX, muzY, muzZ = getPedWeaponMuzzlePosition(localPlayer) 
        if not isElement(weaponMarker) then 
            weaponMarker = createMarker(muzX, muzY, muzZ, "corona", 0.5, 255, 0, 0, 170) 
        end 
        setElementPosition(weaponMarker, muzX, muzY, muzZ) 
    else 
        if isElement(weaponMarker) then 
            destroyElement(weaponMarker) 
        end 
    end 
end) 

And, of course, you are the only who will see the marker when you aim (local player), other players won't see the marker.

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...