Faw[Ful] Posted July 26, 2011 Share Posted July 26, 2011 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
Castillo Posted July 26, 2011 Share Posted July 26, 2011 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
Faw[Ful] Posted July 26, 2011 Author Share Posted July 26, 2011 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. Link to comment
Castillo Posted July 26, 2011 Share Posted July 26, 2011 So, you want to create a own pickup? that's not so hard.. I done it some days ago for my 'horseshoes' script (there was no horseshoe pickup), it's pretty easy, I just made a object + a marker and made it rotate with a little script. Link to comment
HunT Posted July 26, 2011 Share Posted July 26, 2011 Call the function with triggerClientEvent in marker or ServerEvent Link to comment
Faw[Ful] Posted July 26, 2011 Author Share Posted July 26, 2011 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
eAi Posted July 26, 2011 Share Posted July 26, 2011 You've got the right basic idea, just move the createMarker inside your for loop. Link to comment
Faw[Ful] Posted July 27, 2011 Author Share Posted July 27, 2011 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
Castillo Posted July 27, 2011 Share Posted July 27, 2011 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
Faw[Ful] Posted July 27, 2011 Author Share Posted July 27, 2011 No d'ont work I just want to play a sound onClientMarkerHit, but I d'ont want to add all those objects position in the script, I have to take this step first, I will need to think about another way to do this. hm ! Link to comment
diegofkda Posted July 27, 2011 Share Posted July 27, 2011 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
Faw[Ful] Posted July 27, 2011 Author Share Posted July 27, 2011 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
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