novo Posted June 1, 2012 Share Posted June 1, 2012 (edited) Hi all. Today i'll learn you how to create a marker for random vehicles. This idea is taken from a Mr. Green's map. Let's begin... 1. You must get all IDs that you want to use. You can see all vehicles ID's here: https://wiki.multitheftauto.com/wiki/Vehicle_IDs#2-Door_and_Compact_cars 2. I'll use all vehicles in mta. 3. Now, let's create the marker: marker = createMarker(1314,-1575,12,"corona",2,0,255,0) You must change "1314,-1575,12" for the x,y,z of where you want to locate the marker. 4. Now, we add a handled function that will happen when player (source) hits the marker: addEventHandler("onClientMarkerHit",marker, function() local vh = getPedOccupiedVehicle ( source ) vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) end) 5. Finally, we gotta put together these two codes, like this: marker = createMarker(x, y, z,"corona",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function() local vh = getPedOccupiedVehicle ( source ) vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) end) 6. Save that code as "client.lua" into the map folder. 7. Open the file meta.xml located inside the map folder. 8. Add at the beginning below this code: <script src="client.lua" type="client" /> 9. Save the meta.xml 10. We finished. NOTE: THIS CODE WASN'T TESTED YET, IF YOU HAVE PROBLEMS WITH IT TELL IT TO ME WITH A REPLY. I hope you like it! Bye Edited June 2, 2012 by Guest Link to comment
mjau Posted June 1, 2012 Share Posted June 1, 2012 Wong place, we got a tutorials section... Nice tut but instead of writing comments in a string inside the variable you could just do --Comment here behind the variable... Link to comment
Castillo Posted June 2, 2012 Share Posted June 2, 2012 Topic moved to: "Scripting > Tutorials" section. Link to comment
X-SHADOW Posted June 3, 2012 Share Posted June 3, 2012 Nice Tutorials Man Realy Good Keep up the good work . Link to comment
Guest Guest4401 Posted June 3, 2012 Share Posted June 3, 2012 marker = createMarker(x, y, z,"corona",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function() local vh = getPedOccupiedVehicle ( source ) vehicles = { --[[YOUR ID'S HERE, SEPARATED BY A COMA (Ex: 1, 2, 3)]] } nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) end) It has a few errors source in getPedOccupiedVehicle is the marker, not the player. nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) This picks a random number from 1 to count of table, not a random vehicle model. It should be something like: nm = tonumber(vehicles[math.random(#vehicles)]) Link to comment
qaisjp Posted June 29, 2012 Share Posted June 29, 2012 Also the table shouldn't be declared on every hit, declare it at the start of the code. Use locals. Link to comment
codeluaeveryday Posted June 30, 2012 Share Posted June 30, 2012 It appears no one in MTA knows how to speak good English but Karthik. Link to comment
robhol Posted June 30, 2012 Share Posted June 30, 2012 Posting untested (and error-riddled) code in a Tutorial section is probably not something you want to do. I mean, effort appreciated and all, but seriously, this won't help anyone. Testing such a basic script wouldn't take much time, either. 1 Link to comment
qaisjp Posted July 1, 2012 Share Posted July 1, 2012 It appears no one in MTA knows how to speak good English but Karthik. lol, 1) That was totally offtopic 2) I'm pretty sure I have great English 3) He is indian 4) OThers can speak perfect english too. God, chris e_e! Link to comment
Callum Posted July 3, 2012 Share Posted July 3, 2012 It appears no one in MTA knows how to speak good English but Karthik. Ironic, the correct phrasing would be; It appears that nobody in the MTA community speaks good English, except 'Karthik'. Link to comment
qaisjp Posted July 4, 2012 Share Posted July 4, 2012 Put 'Karthik' within quotations isn't required though as he wasn't referencing a common noun. Link to comment
Callum Posted July 4, 2012 Share Posted July 4, 2012 Nobody knows for a fact that Karthik is his name though. Link to comment
damien111 Posted August 8, 2012 Share Posted August 8, 2012 Can someone re write this tutorial 4 me! And message me it. It would be greatley appreciated. Link to comment
dazzlepoint Posted May 22, 2013 Share Posted May 22, 2013 what did i wrong ? can you help me ? marker = createMarker(2121, 1402, 10,"cylinder",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function() local vh = getPedOccupiedVehicle ( source ) vehicles = 4, 3, 1 nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) end) Link to comment
iPrestege Posted May 22, 2013 Share Posted May 22, 2013 -- # Client Side local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function ( player ) if getElementType ( player ) == "player" then local vehicle = getPedOccupiedVehicle ( player ) if not vehicle then return end local vehicles = { 411,412,413 } local ID = (vehicles[math.random(#vehicles)]) setElementModel ( vehicle, ID ) end end,false ) Erros : -- You're entered id was wrong -- Check the vehicle with a source element ? -- Get a random model was wrong . Link to comment
dazzlepoint Posted May 22, 2013 Share Posted May 22, 2013 hi #Mr.Pres[T]ege you are really PRO but is this also for the server side -- # Client Side local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function ( player ) if getElementType ( player ) == "player" then local vehicle = getPedOccupiedVehicle ( player ) if not vehicle then return end local vehicles = { 411,412,413 } local ID = (vehicles[math.random(#vehicles)]) setElementModel ( vehicle, ID ) end end,false ) Erros : -- You're entered id was wrong -- Check the vehicle with a source element ? -- Get a random model was wrong . Link to comment
iPrestege Posted May 22, 2013 Share Posted May 22, 2013 hi #Mr.Pres[T]ege you are really PRO but is this also for the server side -- # Client Side local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function ( player ) if getElementType ( player ) == "player" then local vehicle = getPedOccupiedVehicle ( player ) if not vehicle then return end local vehicles = { 411,412,413 } local ID = (vehicles[math.random(#vehicles)]) setElementModel ( vehicle, ID ) end end,false ) Erros : -- You're entered id was wrong -- Check the vehicle with a source element ? -- Get a random model was wrong . No it's only client side you can use this server side : -- # Server Side local marker = createMarker(2121, 1402,10,"cylinder",2,0,255,0) addEventHandler("onMarkerHit",marker, function ( player ) if getElementType ( player ) == "player" then local vehicle = getPedOccupiedVehicle ( player ) if not vehicle then return end local vehicles = { 411,412,413 } local ID = (vehicles[math.random(#vehicles)]) setElementModel ( vehicle, ID ) end end,false ) Link to comment
PeteyFTW Posted November 28, 2016 Share Posted November 28, 2016 (edited) Greetings, I have followed your steps but unfortunately, nothing happened, even the ' debug script 3 ' did not inform me if there are errors! Here is my work: Client.lua: Spoiler marker = createMarker(2226, 1512, 10, "corona",2,0,255,0) addEventHandler("onClientMarkerHit",marker, function() local vh = getPed0ccupiedVehicle ( source ) vehicles = { 4, 1, 0 } nm = tonumber ( math.random( #vehicles ) ) setElementModel ( vh, nm ) end) meta.xml file: Spoiler <script src="client.lua" type="client" /> What is the wrong?! Edited November 28, 2016 by Petey99 Link to comment
qaisjp Posted December 10, 2016 Share Posted December 10, 2016 Hi Petey99, Keep in mind that the command does not have any spaces. You should type in: /debugscript 3 You will also find that you typed getPed0ccupiedVehicle, and not getPedOccupiedVehicle. Does that help? Link to comment
Recommended Posts