Other Languages Moderators Lord Henry Posted April 13, 2017 Other Languages Moderators Share Posted April 13, 2017 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? Link to comment
Mr.Loki Posted April 13, 2017 Share Posted April 13, 2017 Try this: getAttachedElements setBlipColor 1 Link to comment
Other Languages Moderators Lord Henry Posted April 14, 2017 Author Other Languages Moderators Share Posted April 14, 2017 20 hours ago, Mr.Loki said: Try this: getAttachedElements setBlipColor getAttachedElements doesn't work, because it returns a table, not the element. Link to comment
Fist Posted April 14, 2017 Share Posted April 14, 2017 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 Link to comment
Mr.Loki Posted April 14, 2017 Share Posted April 14, 2017 2 hours ago, Lord Henry said: getAttachedElements doesn't work, because it returns a table, not the element. A table containing the element Link to comment
Gordon_G Posted April 14, 2017 Share Posted April 14, 2017 (edited) In order to reduce lag, you should use for i,v in pairs(getAttachedElements(yourProjectileElementHere) do setBlipColor(v,255,0,0,255); end instead of for i,v in ipairs(getAttachedElements(yourProjectileElementHere) do setBlipColor(v,255,0,0,255); end 'Cause you don't need to order the execution. Edited April 14, 2017 by Gordon_G Link to comment
Other Languages Moderators Lord Henry Posted April 15, 2017 Author Other Languages Moderators Share Posted April 15, 2017 (edited) 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 April 15, 2017 by Lord Henry Link to comment
Mr.Loki Posted April 15, 2017 Share Posted April 15, 2017 (edited) 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 April 15, 2017 by Mr.Loki Link to comment
Other Languages Moderators Lord Henry Posted April 16, 2017 Author Other Languages Moderators Share Posted April 16, 2017 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. Link to comment
Mr.Loki Posted April 16, 2017 Share Posted April 16, 2017 Damn... then i have no idea how lol Link to comment
Fist Posted April 16, 2017 Share Posted April 16, 2017 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. Link to comment
Ayush Rathore Posted April 17, 2017 Share Posted April 17, 2017 (edited) 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 April 17, 2017 by Ayush Rathore 1 Link to comment
Other Languages Moderators Lord Henry Posted April 17, 2017 Author Other Languages Moderators Share Posted April 17, 2017 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. Link to comment
Mr.Loki Posted April 17, 2017 Share Posted April 17, 2017 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 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