Jump to content

attach a marker on all the same objects IDs


Faw[Ful]

Recommended Posts

I want to attach a marker to all the same IDs of an object created by the map editor.

So if I place an object in the map editor with this ID 2846 , it will have a marker on it.

This is my first script , so og course it have alot of errors, but at least I try it in many ways.

local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
function velocityArrow () 
for i,obj in ipairs (getElementsByType("object")) do 
                if getElementModel(magnetObject) == 2846 then 
 attachElements ( magnetMarker, magnetObject, 0, 0, 0 ) 
 end 
 end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), velocityArrow) 

I can set some properties on all the same object ID , like the alpha, but the attach d'ont work.

Link to comment

Maybe because magnetObject doesn't exist? also, you got a missing 'end'.

local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
  
function velocityArrow () 
for i,obj in ipairs (getElementsByType("object")) do 
     if getElementModel(magnetObject) == 2846 then 
        attachElements ( magnetMarker, obj, 0, 0, 0 ) 
       end 
   end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), velocityArrow) 

There's something that is confusing me here... you want to attach ONE marker to more than ONE object...? that makes no sense.

Link to comment
There's something that is confusing me here... you want to attach ONE marker to more than ONE object...? that makes no sense.

Yea thats the problem. I want to create an Accessory object, like the race pickup , you script it only 1 time , but you can add many objects you want in the editor and they will trigger the same event on a certain object model (ID).

It's advanced scripting I guess :/ , I just know how to do it on a single object that you create with create object function, but it takes time to script the same event many times, because the object position change and the marker also or the colshape, it will be nice if other want to use this custom object and when they touch it (the marker or the zone) they will trigger the scripted event, they just need to place it in their .map file.

I will ask an advanced scripter for this , just to understand how to create those Accessory object and after I can script alot of fun events with them. :P

Link to comment

How the script can look in the .map file and detect the object model ID and give the event I script on each of them , otherwise I can create my pickup by script = create object, create marker, add the event on the marker ... , but if I add 80 pickups like this, I need to script the create object and create marker for all :/

Someone know where to find the global idea of this and I can understand it, thanks in advance !

Link to comment
function velocityArrow () 
  
local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
for i,obj in ipairs (getElementsByType("object")) do 
  
     if getElementModel(magnetObject) == 2846 then 
  
        attachElements ( magnetMarker, obj, 0, 0, 0 ) 
  
       end 
  
   end 
  
end 
  
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), velocityArrow) 

No marker on the object when testing in the editor. :/

Link to comment

I think he meant this:

function velocityArrow () 
for i,obj in ipairs (getElementsByType("object")) do 
     local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
     if getElementModel(magnetObject) == 2846 then 
        attachElements ( magnetMarker, obj, 0, 0, 0 ) 
       end 
   end 
end 
addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), velocityArrow) 

Link to comment

Try this:

  
ID = --Put here the ID you want to use. 
  
addEventHandler( "onClientElementStreamIn", root, 
    function () 
        if getElementModel( source ) == ID then 
             local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
             attachElements ( magnetMarker, source, 0, 0, 0 ) 
        end 
    end) 

Link to comment
Try this:
  
ID = --Put here the ID you want to use. 
  
addEventHandler( "onClientElementStreamIn", root, 
    function () 
        if getElementModel( source ) == ID then 
             local magnetMarker = createMarker ( 0, 0, 0, "cylinder", 3, 255, 255, 255, 255 ) 
             attachElements ( magnetMarker, source, 0, 0, 0 ) 
        end 
    end) 

Thanks alot :)

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...