Jump to content

Sell Vehicle


Norhy

Recommended Posts

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.

Link to comment
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 ) 

Link to comment
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

Link to comment
-- 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 by Guest
Link to comment

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) 

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...