Xeno Posted August 13, 2012 Posted August 13, 2012 local objects = { {model=1210, x=-1318, y=-145, z=13.25, rot=90, rot2=0,rot3=90}, {model=1210, x=-1322, y=-145, z=13.25, rot=90, rot2=0,rot3=90}, {model=1210, x=-1330, y=-145, z=13.25, rot=90, rot2=0,rot3=90} } for index, object in ipairs(objects) do myobject = createObject(object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot) local x,y,z = getElementPosition(myobject) mymarker = createMarker(x,y,z,"cylinder",4,200,0,0,255) end at the moment it spawns all objects, but I want it so it only spawns 1, how do I do this?
Castillo Posted August 13, 2012 Posted August 13, 2012 local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x,y,z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) Did you mean that? San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Xeno Posted August 13, 2012 Author Posted August 13, 2012 Thank you, thats what I wanted. I'm trying to make it so when you hit the marker it sets a new location for the object, local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x,y,z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) function giveCash(player) givePlayerMoney(player, 20000) destroyElement(mymarker) destroyElement(myobject) myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) end addEventHandler("onMarkerHit", mymarker, giveCash) But this doesn't seem to work..
Castillo Posted August 13, 2012 Posted August 13, 2012 local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } function giveCash ( player ) givePlayerMoney ( player, 20000 ) destroyElement ( mymarker ) destroyElement ( myobject ) createRandomLocation ( ) end function createRandomLocation ( ) local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x, y, z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) addEventHandler ( "onMarkerHit", mymarker, giveCash ) end createRandomLocation ( ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Anderl Posted August 13, 2012 Posted August 13, 2012 local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } function giveCash ( player ) givePlayerMoney ( player, 20000 ) destroyElement ( mymarker ) destroyElement ( myobject ) createRandomLocation ( ) end function createRandomLocation ( ) local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x, y, z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) addEventHandler ( "onMarkerHit", mymarker, giveCash ) end createRandomLocation ( ) Why "createRandomLocation ( )" in the end? "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
Castillo Posted August 13, 2012 Posted August 13, 2012 Because if you put it at the top, the function won't exist yet, other way would be using onResourceStart event. local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } addEventHandler ( "onResourceStart", resourceRoot, function ( ) createRandomLocation ( ) end ) function giveCash ( player ) givePlayerMoney ( player, 20000 ) destroyElement ( mymarker ) destroyElement ( myobject ) createRandomLocation ( ) end function createRandomLocation ( ) local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x, y, z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) addEventHandler ( "onMarkerHit", mymarker, giveCash ) end San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Castillo Posted August 13, 2012 Posted August 13, 2012 You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Anderl Posted August 13, 2012 Posted August 13, 2012 Because if you put it at the top, the function won't exist yet, other way would be using onResourceStart event. local objects = { { model = 1210, x = -1318, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1322, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 }, { model = 1210, x = -1330, y = -145, z = 13.25, rot = 90, rot2 = 0, rot3 = 90 } } addEventHandler ( "onResourceStart", resourceRoot, function ( ) createRandomLocation ( ) end ) function giveCash ( player ) givePlayerMoney ( player, 20000 ) destroyElement ( mymarker ) destroyElement ( myobject ) createRandomLocation ( ) end function createRandomLocation ( ) local object = objects [ math.random ( #objects ) ] myobject = createObject ( object.model, object.x, object.y, object.z, object.rot3, object.rot2, object.rot ) local x, y, z = getElementPosition ( myobject ) mymarker = createMarker ( x, y, z, "cylinder", 4, 200, 0, 0, 255 ) addEventHandler ( "onMarkerHit", mymarker, giveCash ) end Oh, I just didn't understand this. I thought it should just run "createRandomLocation" when something would happen, you know, not when resource start. Dumbass head "[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007
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