Norhy Posted January 11, 2013 Posted January 11, 2013 Hey guys. I made an Sell Vehicle system using a Marker, however the script doesn't work. I don't get any errors / warnings. In my meta.xml the script is client type. function sellVehicle ( vehicle ) vehicle = getPedOccupiedVehicle ( player ) reward = math.random ( 2000, 3000 ) sellMarker = createMarker ( 2694.72852, -2226.08911, 13.55008, "cylinder", 1.5, 255, 0, 0 ) if ( isPedInVehicle ( player ) ) then givePlayerMoney ( player, reward ) outputChatBox ( "You have sold the " .. vehicle .. " for " .. reward .. " !", source, 0, 255, 0 ) setTimer ( sellVehicle, 1800000, 0 ) else outputChatBox ( "You need to be in a Vehicle to sell it.", source, 255, 0, 0 ) end end addEventHandler ( "onMarkerHit", sellMarker, sellVehicle ) What's wrong here? PS: The player should be able to sell a vehicle only every half hour, so it won't be abused.
abu5lf Posted January 11, 2013 Posted January 11, 2013 You want to sell the car if hit marker gets a reward and can sell the car every half hour? ╔═╦╦╦╗╔╦═╦═╦═╦═╦╦╦╦╦╦╦═╦╦╦╦╗ ║║║║║╠╝║║╚╣║║║║║║║║║║║║║║║║║ ║║║║║╚╦╦═╦╦╦╦╣║║║║║║║║║║║║║║ ║║║║╠═╣╠╝╔══╝║║║║║╟╢║║║║║╟╢║ ╚╩══╩══╩═╩═══╩╩══╩╩═╩╩╩═╩╩═╝ «سبحانك اللهم وبحمدك أشهد أن لا إله إلا أنت أستغفرك وأتوب إليك» M7mdAl7arthy : لتواصل سكايب
abu5lf Posted January 11, 2013 Posted January 11, 2013 sellMarker = createMarker ( 2694.72852, -2226.08911, 13.55008, "cylinder", 1.5, 255, 0, 0 ) setElementData( root, 'sellCar', true ) function sellVehicle( hit ) if getElementType( hit ) == 'vehicle' then local player = getVehicleOccupant( hit ) if player and getElementData( player, 'sellCar' ) then local reward = math.random( 2000, 3000 ) givePlayerMoney( player, reward ) outputChatBox ( "You have sold the " .. getVehicleName( hit ) .. " for " .. reward .. " !", player, 0, 255, 0 ) destroyElement( hit ) setElementData( player, 'sellCar', false ) setTimer( setElementData, 1800000, 1, player, 'sellCar', true ) else outputChatBox( 'Should you wait a half hour!', player, 255, 0, 0 ) end end end addEventHandler( 'onMarkerHit', sellMarker, sellVehicle ) ╔═╦╦╦╗╔╦═╦═╦═╦═╦╦╦╦╦╦╦═╦╦╦╦╗ ║║║║║╠╝║║╚╣║║║║║║║║║║║║║║║║║ ║║║║║╚╦╦═╦╦╦╦╣║║║║║║║║║║║║║║ ║║║║╠═╣╠╝╔══╝║║║║║╟╢║║║║║╟╢║ ╚╩══╩══╩═╩═══╩╩══╩╩═╩╩╩═╩╩═╝ «سبحانك اللهم وبحمدك أشهد أن لا إله إلا أنت أستغفرك وأتوب إليك» M7mdAl7arthy : لتواصل سكايب
Smart. Posted January 11, 2013 Posted January 11, 2013 sellMarker = createMarker ( 2694.72852, -2226.08911, 13.55008, "cylinder", 1.5, 255, 0, 0 ) setElementData( root, 'sellCar', true ) function sellVehicle( hit ) if getElementType( hit ) == 'vehicle' then local player = getVehicleOccupant( hit ) if player and getElementData( player, 'sellCar' ) then local reward = math.random( 2000, 3000 ) givePlayerMoney( player, reward ) outputChatBox ( "You have sold the " .. getVehicleName( hit ) .. " for " .. reward .. " !", player, 0, 255, 0 ) destroyElement( hit ) setElementData( player, 'sellCar', false ) setTimer( setElementData, 1800000, 1, player, 'sellCar', true ) else outputChatBox( 'Should you wait a half hour!', player, 255, 0, 0 ) end end end addEventHandler( 'onMarkerHit', sellMarker, sellVehicle ) why are you using elementdata with a timer? just use getTickCount lol
3NAD Posted January 11, 2013 Posted January 11, 2013 (edited) -- Server Side !! addEventHandler ( "onPlayerJoin", root, function ( ) setElementData ( source, "CanSell", true ) end ) sellMarker = createMarker ( 2694.72852, -2226.08911, 13.55008, "cylinder", 1.5, 255, 0, 0 ) function sellVehicle ( thePlayer ) if getElementType ( thePlayer ) == "player" then if getElementData ( thePlayer, "CanSell" ) then if isPedInVehicle ( thePlayer ) then local vehicle = getPedOccupiedVehicle ( thePlayer ) local reward = math.random ( 2000, 3000 ) givePlayerMoney ( thePlayer, reward ) outputChatBox ( "You have sold the " .. getVehicleName ( vehicle ) .. " for " .. reward .. " !", thePlayer, 0, 255, 0, true ) setElementData ( thePlayer, "CanSell", false ) setTimer ( setElementData, 1800000, 1, thePlayer, "CanSell", true ) else outputChatBox ( "You need to be in a Vehicle to sell it.", thePlayer, 255, 0, 0, true ) end else outputChatBox ( "Wait 30 Minuts.", thePlayer, 255, 0, 0, true ) end end end addEventHandler ( "onMarkerHit", sellMarker, sellVehicle, false ) Edited January 11, 2013 by Guest
abu5lf Posted January 11, 2013 Posted January 11, 2013 This code didn't work. Works with me show your meta.xml. ╔═╦╦╦╗╔╦═╦═╦═╦═╦╦╦╦╦╦╦═╦╦╦╦╗ ║║║║║╠╝║║╚╣║║║║║║║║║║║║║║║║║ ║║║║║╚╦╦═╦╦╦╦╣║║║║║║║║║║║║║║ ║║║║╠═╣╠╝╔══╝║║║║║╟╢║║║║║╟╢║ ╚╩══╩══╩═╩═══╩╩══╩╩═╩╩╩═╩╩═╝ «سبحانك اللهم وبحمدك أشهد أن لا إله إلا أنت أستغفرك وأتوب إليك» M7mdAl7arthy : لتواصل سكايب
Smart. Posted January 11, 2013 Posted January 11, 2013 Use this code instead of using setElementData and a timer, not tested but should work. local sellMarker = createMarker(2694.72852, -2226.08911, 13.55008, "cylinder", 1.5, 255, 0, 0) local tick = {} function sellVehicle(player) if (getElementType(player) == "player") then if (not getPedOccupiedVehicle(player)) then outputChatBox("You need to be in a Vehicle to sell it.", player, 255, 0, 0) return end if (tick[player]) then local theTick = getTickCount() if (theTick - tick[player] < 1800000) then outputChatBox("Wait 30 minutes.", player, 255, 0, 0) return end end tick[player] = getTickCount() local vehicle = getPedOccupiedVehicle(player) local reward = math.random(2000, 3000) givePlayerMoney(player, reward) outputChatBox("You have sold the "..getVehicleName(vehicle).. " for "..reward.."!", player, 0, 255, 0) end end addEventHandler("onMarkerHit", sellMarker, sellVehicle) lol
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