Sign in to follow this  
Lord Henry

How to change a projectile's blip color?

Recommended Posts

Hello.
I have a script that create a missile that follows the player when he enters the specified collision shape using createProjectile.
The projectile elements have a white blip by default and I need to change it to Red.
Is there a way to do it?

Share this post


Link to post
1 hour ago, Lord Henry said:

getAttachedElements doesn't work, because it returns a table, not the element.

If you didn't read carefuly enough function name is getAttachedElements not getAttachedElement. Just loop through that table it will get ALL attached elements, 'cause there can be more than 1 attached element to an element. Just in case if you have other elements attached to the projectile then just add check variable if element is the blip and then set blip color.

for i,v in ipairs(getAttachedElements(yourProjectileElementHere) do
    setBlipColor(v,255,0,0,255);
end

 

Share this post


Link to post
2 hours ago, Lord Henry said:

getAttachedElements doesn't work, because it returns a table, not the element.

A table containing the element :D

Share this post


Link to post
9 hours ago, Fist said:

If you didn't read carefuly enough function name is getAttachedElements not getAttachedElement. Just loop through that table it will get ALL attached elements, 'cause there can be more than 1 attached element to an element. Just in case if you have other elements attached to the projectile then just add check variable if element is the blip and then set blip color.


for i,v in ipairs(getAttachedElements(yourProjectileElementHere) do
    setBlipColor(v,255,0,0,255);
end

 

When I use this, the Projectile is not spawned anymore.

-------------------------------------------------------------------------------

Hey guys, test using this, client-side:
 

function attackIntruderA51 ()
	local a51MissileA = createProjectile (localPlayer, 20, 15.49994, 1719.1, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
	local a51MissileB = createProjectile (localPlayer, 20, 237.7, 1696.8, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
end
addCommandHandler ("attack", localPlayer, attackIntruderA51)

 

Edited by Lord Henry

Share this post


Link to post

addCommandHandler only has 2 main args please use /debugscript 3 to debug your code and show errors

I just tried the function myself and it seems that the blip isn't attached to the projectile so, i just made a little hack.

Not perfect but it works. :)

function attackIntruderA51 ()
    local t={}
    -- store the projectiles in a table so you can simply loops it and easily add more projectiles.
    t[#t+1] = createProjectile (localPlayer, 20, 15.49994, 1719.1, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
    t[#t+1] = createProjectile (localPlayer, 20, 237.7, 1696.8, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
  
    for _,projectile in pairs (t) do
        local blip = createBlipAttachedTo( projectile, 0, 1, 255, 0, 0, 255, 1 )
        setElementParent( blip, projectile ) -- parent the blip to the projectile so it gets destroyed when the projectile explodes.
    end
end
addCommandHandler ("attack", attackIntruderA51)

 

Edited by Mr.Loki

Share this post


Link to post
On 14/04/2017 at 23:30, Mr.Loki said:

addCommandHandler only has 2 main args please use /debugscript 3 to debug your code and show errors

I just tried the function myself and it seems that the blip isn't attached to the projectile so, i just made a little hack.

Not perfect but it works. :)


function attackIntruderA51 ()
    local t={}
    -- store the projectiles in a table so you can simply loops it and easily add more projectiles.
    t[#t+1] = createProjectile (localPlayer, 20, 15.49994, 1719.1, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
    t[#t+1] = createProjectile (localPlayer, 20, 237.7, 1696.8, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
  
    for _,projectile in pairs (t) do
        local blip = createBlipAttachedTo( projectile, 0, 1, 255, 0, 0, 255, 1 )
        setElementParent( blip, projectile ) -- parent the blip to the projectile so it gets destroyed when the projectile explodes.
    end
end
addCommandHandler ("attack", attackIntruderA51)

 

I'm already doing this. But sometimes the original Projectile's blip keep upon the custom blip, even if I put the ordering arg to 32767.

Share this post


Link to post
10 hours ago, Lord Henry said:

I'm already doing this. But sometimes the original Projectile's blip keep upon the custom blip, even if I put the ordering arg to 32767.

you could destroy original blip with destroyElement and then create your own. 

Share this post


Link to post
On 4/13/2017 at 06:26, Lord Henry said:

Hello.
I have a script that create a missile that follows the player when he enters the specified collision shape using createProjectile.
The projectile elements have a white blip by default and I need to change it to Red.
Is there a way to do it?




function attackIntruderA51 ()
    local t={}
    t[#t+1] = createProjectile (localPlayer, 20, 15.49994, 1719.1, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
    t[#t+1] = createProjectile (localPlayer, 20, 237.7, 1696.8, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
  
    for _,projectile in pairs (t) do
       for i,v in pairs(getAttachedElements(projectile)) do
       if (getElementType(v)=='blip') then
       setBlipColor(v,255,0,0,255);
       end
       end
    end
end
addCommandHandler ("attack", attackIntruderA51)

Use this it might fulfill your need :)

Edited by Ayush Rathore
  • Like 1

Share this post


Link to post
14 hours ago, Fist said:

you could destroy original blip with destroyElement and then create your own. 

I can't access the original blip. If I could, I would just change the original blip's color.

Share this post


Link to post
7 hours ago, Ayush Rathore said:



function attackIntruderA51 ()
    local t={}
    t[#t+1] = createProjectile (localPlayer, 20, 15.49994, 1719.1, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
    t[#t+1] = createProjectile (localPlayer, 20, 237.7, 1696.8, 25.5, 5, localPlayer, 0, 0, 0, 0, 0, 1)
  
    for _,projectile in pairs (t) do
       for i,v in pairs(getAttachedElements(projectile)) do
       if (getElementType(v)=='blip') then
       setBlipColor(v,255,0,0,255);
       end
       end
    end
end
addCommandHandler ("attack", attackIntruderA51)

Use this it might fulfill your need :)

 

We tried this already does not work

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.