steve123 Posted August 23, 2016 Share Posted August 23, 2016 Hi It is possible to make a script which will be change vehicle for random if player touch it ? Because I want give 5 cars id's and on my server when checkpoint will be have a color ( 225,0,0 ) - only this color of checkpoint it will be give random car of these id's ( 429, 541, 480 , 411 , 565 ) And if it is possible can you tell me which function should I use ? Link to comment
Gordon_G Posted August 23, 2016 Share Posted August 23, 2016 vehiclesid = {429, 541, 480 , 411 , 565} changermarker = createMarker(x, y, z, "typeofmarker", size,255, 0, 0, alpha) function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player if getMarkerColor(source) == 255,0,0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table end end end addEventHandler( "onMarkerHit", getRootElement() , MarkerHit) I don't try this but it should work Link to comment
StefanAlmighty Posted August 23, 2016 Share Posted August 23, 2016 vehiclesid = {429, 541, 480 , 411 , 565} changermarker = createMarker(x, y, z, "typeofmarker", size,255, 0, 0, alpha) function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player if getMarkerColor(source) == 255,0,0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table end end end addEventHandler( "onMarkerHit", getRootElement() , MarkerHit) I don't try this but it should work In no way is this helping the OP. The OP directly asked for a list of functions and never asked for the full code because he is not learning from it. Anyone can copy and paste. To answer the topic, you can use createMarker, onMarkerHit, createVehicle and setElementModel. Bold means it's an event rather than function. It would also be a good idea to put the list of models you wish to use in a table using curly brackets. By doing this you can easily loop through each of the vehicles and even choose one from random. For example if the table was called 'vehicles', you can use vehicles[math.random(1, #vehicles)] which would fetch a random vehicle from the table. Link to comment
steve123 Posted August 23, 2016 Author Share Posted August 23, 2016 Thank you guys for help, but script don't work I looked on code and I have no idea what is wrong I checked color of race checkpoints (on the map) and it is correctly with it what is in script Link to comment
Gordon_G Posted August 23, 2016 Share Posted August 23, 2016 function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player local r,g,b = getMarkerColor(source) if r == 255 and g == 0 and b == 0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle end end end end This code work. I just edit a little bit. Link to comment
steve123 Posted August 24, 2016 Author Share Posted August 24, 2016 Are you sure it works ? Because I tested it and nothing happened - it should work like on this video but with my few ID's only Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 Try this: vehiclesid = {429, 541, 480, 411, 565} marker = createMarker(x, y, z, "typeofmarker", size, 255, 0, 0, 255) addEventHandler( "onMarkerHit", marker, function (element) if getElementType(element) == "player" then local x,y,z = getElementPosition(element) local rx,ry,rz = getElementRotation(element) local r, g, b, a = getMarkerColor(marker) if r == 255 and g == 0 and b == 0 and a == 255 then local vehicle = math.random(1,#vehiclesid) local veh = createVehicle(vehicle, x, y, z, 0, 0, rx, ry, rz) warpPedIntoVehicle(element, veh) end end end ) Link to comment
steve123 Posted August 24, 2016 Author Share Posted August 24, 2016 still somethig is wrong Link to comment
Gordon_G Posted August 24, 2016 Share Posted August 24, 2016 function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player local r,g,b = getMarkerColor(source) if r == 255 and g == 0 and b == 0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle end end end end I retry this this moon and, it work perfectly Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player local r,g,b = getMarkerColor(source) if r == 255 and g == 0 and b == 0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle end end end end I retry this this moon and, it work perfectly How does this even work? There is no event handling the function. Link to comment
steve123 Posted August 24, 2016 Author Share Posted August 24, 2016 I swear it dont works :( I checked few times and my color of checkpoints is the same like on the script and nothing happen this is code vehiclesid = {429, 541, 480, 411, 565} function MarkerHit( hitElement) if getElementType(hitElement) == "player" then local r,g,b = getMarkerColor(source) if r == 255 and g == 0 and b == 0 then local x,y,z = getElementPosition(hitElement) if not isPedInVehicle(hitElement) then local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) warpPedIntoVehicle(hitElement, vehicle) end end end end PS: I tried with every codes on this thread Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 Anything in the debug? Link to comment
steve123 Posted August 24, 2016 Author Share Posted August 24, 2016 I think you will be laught, but i have no idea about what you said ( debug) Link to comment
Gravestone Posted August 24, 2016 Share Posted August 24, 2016 https://wiki.multitheftauto.com/wiki/Debugging Link to comment
Gordon_G Posted August 25, 2016 Share Posted August 25, 2016 function MarkerHit( hitElement) if getElementType(hitElement) == "player" then -- getElementType because theElement must be a player local r,g,b = getMarkerColor(source) if r == 255 and g == 0 and b == 0 then -- We check the color of the marker local x,y,z = getElementPosition(hitElement) -- Get the position of the player if not isPedInVehicle(hitElement) then -- Check if the player is already in vehicle local vehicle = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getPedRotation(hitElement)) -- The math.random will take an aleatory number in the table 'vehiclesid'. The # count the lines in a table so, like this you can add some other IDs in your table warpPedIntoVehicle(hitElement, vehicle) -- Warp the player into the vehicle end end end end I retry this this moon and, it work perfectly How does this even work? There is no event handling the function. Oh, f*ck I'm so stupid ... Write that after the last "end" ... addEventHandler( "onMarkerHit", getRootElement(), MarkerHit ) Link to comment
homie99 Posted November 3, 2019 Share Posted November 3, 2019 Hi I was browsing the forum and I' ve found this topic, I know it's very old topic ,but I can use this script in other way for the server, how can I fix this script ? and make it useful, cause This code does't work ( I' ve specially made account in this forum to solve this problem guys ) Can you help me with this ? Link to comment
komal Posted November 3, 2019 Share Posted November 3, 2019 (edited) 2 hours ago, homie99 said: Hi I was browsing the forum and I' ve found this topic, I know it's very old topic ,but I can use this script in other way for the server, how can I fix this script ? and make it useful, cause This code does't work ( I' ve specially made account in this forum to solve this problem guys ) Can you help me with this ? if you want try this script with only red marks try this server only vehiclesid = {429, 541, 480 , 411 , 565} function giveRandomCar( hitElement) local r = getMarkerColor(source) local x,y,z = getElementPosition(hitElement) if r == 255 and getElementType(getVehicleController(hitElement)) == "Player" then local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement)) if veh then warpPedIntoVehicle(getVehicleController(hitElement),veh) if getElementType(hitElement) == "Vehicle" then destroyElement (hitElement) end end end end addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) and this with all marks colors vehiclesid = {429, 541, 480 , 411 , 565} function giveRandomCar( hitElement) local x,y,z = getElementPosition(hitElement) if getElementType(getVehicleController(hitElement)) == "Player" then local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement)) if veh then warpPedIntoVehicle(getVehicleController(hitElement),veh) if getElementType(hitElement) == "Vehicle" then destroyElement (hitElement) end end end end addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) Edited November 3, 2019 by komal Link to comment
homie99 Posted November 4, 2019 Share Posted November 4, 2019 Hi Thank you komal for your job, but I don't know why It still doesn't works. This is a link for this which i used. Can you check it ? (I checked the race checkpoint and there was to color r-225 ) http://www.mediafire.com/file/7c1njkk0hns9j5s/test.rar/file Link to comment
homie99 Posted November 5, 2019 Share Posted November 5, 2019 Any ideas ? , any body ? Link to comment
Moderators IIYAMA Posted November 6, 2019 Moderators Share Posted November 6, 2019 17 hours ago, homie99 said: Any ideas ? , any body ? What is this entire topic all about if you haven't even wrote a single line of code? Also not even debug and validate the code in a single way? If you did not come here to script, please go discus this in a personal message with the one that did donate the code. This section is not for requesting free code, it is for learning how to code. Link to comment
homie99 Posted November 6, 2019 Share Posted November 6, 2019 Okay, Okay I think the problem is getMarkerColor, in my view it should be something with checkpoints, I made this part of code with tutorial and it still doen'st works ? what Can I change ? ;) function checkpoint:getCheckpoint(i) local realcheckpoint = g_Checkpoints[i] local checkpoint = {} for k,v in pairs(realcheckpoint) do checkpoint[k] = v end checkpoint.vehicle = self:getRandomVehicle(checkpoint) return checkpoint vehiclesid = {429, 541, 480 , 411 , 565} function giveRandomCar( hitElement) local r = getMarkerColor(source) local x,y,z = getElementPosition(hitElement) if r == 255 and getElementType(getVehicleController(hitElement)) == "Player" then local veh = createVehicle(vehiclesid[math.random(1,#vehiclesid)],x,y,z,0,0,getElementRotation(hitElement)) if veh then warpPedIntoVehicle(getVehicleController(hitElement),veh) if getElementType(hitElement) == "Vehicle" then destroyElement (hitElement) end end end end addEventHandler( "onMarkerHit", getRootElement() ,giveRandomCar) Link to comment
Moderators IIYAMA Posted November 6, 2019 Moderators Share Posted November 6, 2019 1 hour ago, homie99 said: I think the problem is getMarkerColor, in my view it should be something with checkpoints, I made this part of code with tutorial and it still doen'st works ? what Can I change ? What you can change is learning the basics of Lua, so that you read code and understand that copying and pasting more advance code is not clever... Link to comment
homie99 Posted November 6, 2019 Share Posted November 6, 2019 Okay IIYAMA, You can close this topic. I don"t have time to learn Lua . Link to comment
Moderators IIYAMA Posted November 6, 2019 Moderators Share Posted November 6, 2019 5 minutes ago, homie99 said: Okay IIYAMA, You can close this topic. I don"t have time to learn Lua . In that case you should also respect other people their time. Link to comment
Recommended Posts