3eBpA Posted January 27, 2014 Posted January 27, 2014 Hello guys, I'm asking u to help me to create one vehicle for one player, if vehicle exists, it should spawn near player, I've got something like this : local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') then createVehicle(403, 872, -1216, 18, 0 , 0 , 180); else outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit )
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit )
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) ok, one more nooby question, how to delete spawned vehicle ?
iPrestege Posted January 27, 2014 Posted January 27, 2014 local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) ok, one more nooby question, how to delete spawned vehicle ? destroyElement
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) thanks ok, one more nooby question, how to delete spawned vehicle ? destroyElement
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 Try this, tho i don't know if it will work, i'm from my cell local vehicles = { } local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) local veh = createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) table.insert(vehicles,hitElement,veh) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) function delete () destroyElement(vehicles[source] table.remove(vehicles,vehicles[source]) setElementData(hitElement,"vehicle",false) end addCommandHandler("delete",delete)
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Try this, tho i don't know if it will work, i'm from my cell local vehicles = { } local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) local veh = createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) table.insert(vehicles,hitElement,veh) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) function delete () destroyElement(vehicles[source] table.remove(vehicles,vehicles[source]) setElementData(hitElement,"vehicle",false) end addCommandHandler("delete",delete) hey wait, client sided scripts works only for 1 client ? Or for all clients on the server ?
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 Yes, they work only for the client that uses it. Didn't know how you wanted to use it, tho you can use it client side this way: local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) veh = createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) function delete () destroyElement(veh) setElementData(hitElement,"vehicle",false) end addCommandHandler("delete",delete) PD: Do know that this way, you can't enter the vehicle.
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Yes, they work only for the client that uses it. Didn't know how you wanted to use it, tho you can use it client side this way: local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) veh = createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) function delete () destroyElement(veh) setElementData(hitElement,"vehicle",false) end addCommandHandler("delete",delete) PD: Do know that this way, you can't enter the vehicle. ohh, well, I just need to create a script that can change color and destroy car on the markers
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Try this, tho i don't know if it will work, i'm from my cell local vehicles = { } local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) local veh = createVehicle(403, x, y+1, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) table.insert(vehicles,hitElement,veh) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler( "onMarkerHit", marker1, MarkerHit ) function delete () destroyElement(vehicles[source] table.remove(vehicles,vehicles[source]) setElementData(hitElement,"vehicle",false) end addCommandHandler("delete",delete) also, one more question in setElementData I can put any data that I want ?
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Well, guys, I know that I'm very annoying but can you help me again ? :3 why this code doesn't works ? local workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); function TakeJob(hitElement, matchingDimension) local element = getElementType(hitElement); if(getElementType(hitElement) == 'Player') and getElementData(hitElement,"trucker") == false then setPedSkin(source, 202); setElementData(hitElement,"trucker",true); setPlayerTeam(source, truckers); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You are already a trucker"); end end addEventHandler("onMarkerHit", workmarker, TakeJob);
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 local workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); trucks = createTeam("Truckers",255,0,0) function TakeJob(hitElement, matchingDimension) local element = getElementType(hitElement); if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false then setPedSkin(source, 202); setElementData(hitElement,"trucker",true); setPlayerTeam(hitElement, trucks); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You are already a trucker"); end end addEventHandler("onMarkerHit", workmarker, TakeJob);
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 local workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); trucks = createTeam("Truckers",255,0,0) function TakeJob(hitElement, matchingDimension) local element = getElementType(hitElement); if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false then setPedSkin(source, 202); setElementData(hitElement,"trucker",true); setPlayerTeam(hitElement, trucks); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You are already a trucker"); end end addEventHandler("onMarkerHit", workmarker, TakeJob); oh, I've got team creation, I forgot to share it here , ohh, I'm stupid, forgot to setElementData, thanks again, I hope I won't disturb u today anymore with my stupid questions
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 Relax man, no problem we are here to help you out
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Relax man, no problem we are here to help you out ok, well, then my last script, it always writes me that I'm a trucker but I am not local truckers = createTeam("Truckers", 222, 153, 25); local marker1 = createMarker(872, -1208, 16, 'cylinder', 2.0, 255, 0, 0, 150) -- create myMarker local workmarker = createMarker(860, -1208, 16, 'cylinder', 2.0, 0, 255, 0 , 150); function MarkerHit( hitElement, matchingDimension ) local elementType = getElementType( hitElement ) local playermoney = getPlayerMoney(hitElement) if(getElementType(hitElement) == 'player') and getElementData(hitElement,"vehicle") == false then local x,y,z = getElementPosition(hitElement) createVehicle(403, x + 10, y, z, 0 , 0 , 180) setElementData(hitElement,"vehicle",true) elseif getElementData(hitElement,"vehicle") == true then outputChatBox("You have got already a vehicle"); end end addEventHandler("onMarkerHit", marker1, MarkerHit ) function TakeJob(hitElement, matchingDimension) local element = getElementType(hitElement); if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false then setPedSkin(source, 202); setElementData(hitElement,"trucker",true); setPlayerTeam(hitElement, truckers); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You are already a trucker"); end end addEventHandler("onMarkerHit", workmarker, TakeJob);
iPrestege Posted January 27, 2014 Posted January 27, 2014 Make sure the trucker data value is false and keep in mind if you restart the resource the data won't reset!
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Make sure the trucker data value is false and keep in mind if you restart the resource the data won't reset! hey, If I want to keep my players data, I should create mysql database and store there data ?
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 That's because you're obtaining an element data representing if you're a trucker or not. The element data is not cleared unless you re join the server. You can also clear the element data, by using this: setElementData(hitElement,"trucker",false) You can store the data using: setAccountData Or using the SQL functions.
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 That's because you're obtaining an element data representing if you're a trucker or not. The element data is not cleared unless you re join the server. You can also clear the element data, by using this: setElementData(hitElement,"trucker",false) You can store the data using: setAccountData Or using the SQL functions. yes, I have analyzed the situation and I'm thinking about creating a /exit command so I can exit trucker's team, this is a topic about commands, yes ? https://forum.multitheftauto.com/viewtopic.php?f=148&t=43227
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 I strongly recommend not to use that if you're new to lua because that is mainly OOP. Use this: function kickme() if getElementData(source,"trucker") == true then setElementData(source,"trucker",false) setPlayerTeam(source,nil) end addCommandHandler("notrucker",kickme)
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 I strongly recommend not to use that if you're new to lua because that is mainly OOP.Use this: function kickme() if getElementData(source,"trucker") == true then setElementData(source,"trucker",false) setPlayerTeam(source,nil) end addCommandHandler("notrucker",kickme) well, I'm .Net programmer, who wants to learn Lua, so I'm not new to OOP =\ and I think, I'll create a gui window with "hire" and "exit" buttons
MTA Team 0xCiBeR Posted January 27, 2014 MTA Team Posted January 27, 2014 Well, if you do know OOP then you have a lot of points in favor if you plan on using OOP to programm. In MTA 1.4 OOP will be incorporated in the MTA engine functions. Please let me know if you need any further assistance.
3eBpA Posted January 27, 2014 Author Posted January 27, 2014 Well, if you do know OOP then you have a lot of points in favor if you plan on using OOP to programm. In MTA 1.4 OOP will be incorporated in the MTA engine functions.Please let me know if you need any further assistance. why does skin don't puts on the player ? function TakeJob(hitElement, matchingDimension, thePlayer) local element = getElementType(hitElement); if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false and getElementData(hitElement,"vehicle") == false then setPedSkin(source, 206); setElementData(hitElement,"trucker",true); setPlayerTeam(hitElement, truckers); setMarkerColor(marker1, 255, 0, 0, 150); outputChatBox("To end you job stand back on this marker and you will automatically end your job"); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You have ended your job"); setPlayerTeam(hitElement, unemployedteam); setElementData(hitElement,"trucker",false); setMarkerColor(marker1, 255, 0, 0, 0); end end addEventHandler("onMarkerHit", workmarker, TakeJob);
iPrestege Posted January 27, 2014 Posted January 27, 2014 Well, if you do know OOP then you have a lot of points in favor if you plan on using OOP to programm. In MTA 1.4 OOP will be incorporated in the MTA engine functions.Please let me know if you need any further assistance. why does skin don't puts on the player ? function TakeJob(hitElement, matchingDimension, thePlayer) local element = getElementType(hitElement); if(getElementType(hitElement) == 'player') and getElementData(hitElement,"trucker") == false and getElementData(hitElement,"vehicle") == false then setPedSkin(source, 206); setElementData(hitElement,"trucker",true); setPlayerTeam(hitElement, truckers); setMarkerColor(marker1, 255, 0, 0, 150); outputChatBox("To end you job stand back on this marker and you will automatically end your job"); elseif getElementData(hitElement,"trucker") == true then outputChatBox("You have ended your job"); setPlayerTeam(hitElement, unemployedteam); setElementData(hitElement,"trucker",false); setMarkerColor(marker1, 255, 0, 0, 0); end end addEventHandler("onMarkerHit", workmarker, TakeJob); Replace it with: setElementModel(hitElement, 206);
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