Jump to content

Problem with my "Car of the day" script.


WolfPire

Recommended Posts

So i'm making my "Car Of The Day" script which allows everyone to buy a brand new car with upgrades and all...

but i got a little problem...

Whenever i try to set the daily ID it will return me in the debug "setElementModel" <--- Bad Argument.

Here's the client, the server won't be necessary.

function IDm() 
    if not IDT then 
        IDT = setTimer(IDs, 86400000, 0) 
    end 
end 
  
addEventHandler("onClientResourceStart", root, IDm) 
  
function IDs() 
        ID = math.random(400,611) 
end 
  
Shop = createMarker( -1658, 1211, 6.4, "cylinder", 1, 0, 255, 0) 
  
function ShopF(theElement) 
    if isPedOnGround(theElement) then 
        if not isPedInVehicle(theElement) then 
            if (theElement ~= localPlayer) then return end -- If the player who hit the colshape isn't the client, cancel the function. 
                CarOfTheDay = createVehicle( 411, -1655, 1209, 21 ) 
                setElementModel(CarOfTheDay, ID) 
                if ( getVehicleType" class="kw2">getVehicleType" class="kw2">getVehicleType( CarOfTheDay ) == "Automobile" ) then 
                showCursor(true) 
                setCameraMatrix( -1664, 1210, 22, 6000, 0, 0, 0, 0) 
                setVehicleColor( CarOfTheDay, math.random(0,255), math.random(0,255), math.random(0,255) ) 
                setElementFrozen( CarOfTheDay, true ) 
                showPlayerHudComponent("all", false) 
                LeftB = guiCreateButton(342,684,176,57,"< Left",false) 
                guiSetFont(LeftB,"default-bold-small") 
                RightB = guiCreateButton(737,684,176,57,"Right >",false) 
                guiSetFont(RightB,"default-bold-small") 
                ExitB = guiCreateButton(539,714,174,26,"Exit",false) 
                guiSetFont(ExitB,"default-bold-small") 
                BuyB = guiCreateButton(539,689,174,26,"Buy",false) 
                guiSetFont(BuyB,"default-bold-small") 
                VehicleL = guiCreateLabel(539,724,174,26,"Vehicle: " .. getVehicleNameFromModel(getElementModel(CarOfTheDay)) .. "",false) 
                guiSetFont(VehicleL,"default-bold-small") 
                guiLabelSetColor ( VehicleL, 0, 0, 255 ) 
                addEventHandler( "onClientGUIClick",LeftB,LeftFEnter,false ) 
                addEventHandler( "onClientGUIClick",RightB,RightFEnter,false ) 
                addEventHandler( "onClientGUIClick",BuyB,BuyF,false ) 
                addEventHandler( "onClientGUIClick",ExitB,ExitF,false ) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(LeftB,false) 
                local x,y = (screenW-windowW)/3.14,(screenH-windowH)/1.01 
                guiSetPosition(LeftB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(RightB,false) 
                local x,y = (screenW-windowW)/1.58,(screenH-windowH)/1.01 
                guiSetPosition(RightB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(ExitB,false) 
                local x,y = (screenW-windowW)/2.1,(screenH-windowH)/1.011 
                guiSetPosition(ExitB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(BuyB,false) 
                local x,y = (screenW-windowW)/2.1,(screenH-windowH)/1.047 
                guiSetPosition(BuyB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(VehicleL,false) 
                local x,y = (screenW-windowW)/1.95,(screenH-windowH)/1.07 
                guiSetPosition(VehicleL,x,y,false) 
            else 
                outputChatBox( "No car found, please re-enter the marker", 255, 0, 0 ) 
                destroyElement(CarOfTheDay) 
                return 
            end 
        end 
    end 
end 
addEventHandler("onClientMarkerHit",Shop,ShopF) 
  
function LeftFEnter() 
    if isElement( CarOfTheDay ) then 
        local RX, RY, RZ = getElementRotation( CarOfTheDay ) 
        setElementRotation(CarOfTheDay, RX, RY, RZ + 10) 
    end 
end 
  
function RightFEnter() 
    if isElement( CarOfTheDay ) then 
        local RX, RY, RZ = getElementRotation( CarOfTheDay ) 
        setElementRotation(CarOfTheDay, RX, RY, RZ - 10) 
    end 
end 
  
function BuyF() 
    CW = guiCreateWindow(470,244,543,180,"Confirmation",false) 
    CL = guiCreateLabel(2,47,545,20,"Are you sure you want to buy this car for $3.000?",false,CW) 
    guiLabelSetColor(CL,0,255,0) 
    guiLabelSetHorizontalAlign(CL,"center",false) 
    guiSetFont(CL,"default-bold-small") 
    YesB = guiCreateButton(59,115,159,39,"Yes",false,CW) 
    NoB = guiCreateButton(322,115,159,39,"No",false,CW) 
    addEventHandler("onClientGUIClick",NoB,NoF,false) 
    addEventHandler("onClientGUIClick",YesB,YesF,false) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(CW,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(CW,x,y,false) 
end 
  
function NoF() 
    destroyElement(CW) 
end 
  
function YesF() 
    destroyElement(CW) 
    destroyElement(LeftB) 
    destroyElement(RightB) 
    destroyElement(ExitB) 
    destroyElement(BuyB) 
    destroyElement(VehicleL) 
    showPlayerHudComponent("all", true) 
    setCameraTarget(localPlayer) 
    showCursor(false) 
    colr1, colg1, colb1, colr2, colg2, colb2, colr3, colg3, colb3, colr4, colg4, colb4 = getVehicleColor(CarOfTheDay, true) 
    Model = getElementModel(CarOfTheDay) 
    destroyElement(CarOfTheDay) 
    triggerServerEvent("spawnCar",getRootElement(),localPlayer, Model, colr1, colg1, colb1, colr2, colg2, colb2, colr3, colg3, colb3, colr4, colg4, colb4) 
    showCursor(false) 
end 
  
function onStop() 
setCameraTarget(localPlayer) 
end 
  
addEventHandler("onClientResourceStop",root,onStop) 
  
function ExitF() 
    if not CW then 
        destroyElement(LeftB) 
        destroyElement(RightB) 
        destroyElement(ExitB) 
        destroyElement(BuyB) 
        destroyElement(VehicleL) 
        destroyElement(CarOfTheDay) 
        showPlayerHudComponent("all", true) 
        setCameraTarget(localPlayer) 
        showCursor(false) 
    else if CW then 
        destroyElement(LeftB) 
        destroyElement(RightB) 
        destroyElement(ExitB) 
        destroyElement(BuyB) 
        destroyElement(VehicleL) 
        destroyElement(CarOfTheDay) 
        destroyElement(CW) 
        showPlayerHudComponent("all", true) 
        setCameraTarget(localPlayer) 
        showCursor(false) 
        end 
    end 
end 
 

Link to comment
function IDm() 
    IDs() 
    if not IDT then 
        IDT = setTimer(IDs, 86400000, 0) 
    end 
end 
addEventHandler("onClientResourceStart", resourceRoot, IDm) 
  
function IDs() 
    repeat 
        ID = math.random(400, 611) 
    until getVehicleType(ID) == "Automobile" 
end 
  
Shop = createMarker( -1658, 1211, 6.4, "cylinder", 1, 0, 255, 0) 
  
function ShopF(theElement) 
    if isPedOnGround(theElement) then 
        if not isPedInVehicle(theElement) then 
            if (theElement ~= localPlayer) then return end -- If the player who hit the colshape isn't the client, cancel the function. 
                CarOfTheDay = createVehicle( 411, -1655, 1209, 21 ) 
                setElementModel(CarOfTheDay, ID or 411) 
                if ( getVehicleType" class="kw2">getVehicleType( CarOfTheDay ) == "Automobile" ) then 
                showCursor(true) 
                setCameraMatrix( -1664, 1210, 22, 6000, 0, 0, 0, 0) 
                setVehicleColor( CarOfTheDay, math.random(0,255), math.random(0,255), math.random(0,255) ) 
                setElementFrozen( CarOfTheDay, true ) 
                showPlayerHudComponent("all", false) 
                LeftB = guiCreateButton(342,684,176,57,"< Left",false) 
                guiSetFont(LeftB,"default-bold-small") 
                RightB = guiCreateButton(737,684,176,57,"Right >",false) 
                guiSetFont(RightB,"default-bold-small") 
                ExitB = guiCreateButton(539,714,174,26,"Exit",false) 
                guiSetFont(ExitB,"default-bold-small") 
                BuyB = guiCreateButton(539,689,174,26,"Buy",false) 
                guiSetFont(BuyB,"default-bold-small") 
                VehicleL = guiCreateLabel(539,724,174,26,"Vehicle: " .. getVehicleNameFromModel(getElementModel(CarOfTheDay)) .. "",false) 
                guiSetFont(VehicleL,"default-bold-small") 
                guiLabelSetColor ( VehicleL, 0, 0, 255 ) 
                addEventHandler( "onClientGUIClick",LeftB,LeftFEnter,false ) 
                addEventHandler( "onClientGUIClick",RightB,RightFEnter,false ) 
                addEventHandler( "onClientGUIClick",BuyB,BuyF,false ) 
                addEventHandler( "onClientGUIClick",ExitB,ExitF,false ) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(LeftB,false) 
                local x,y = (screenW-windowW)/3.14,(screenH-windowH)/1.01 
                guiSetPosition(LeftB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(RightB,false) 
                local x,y = (screenW-windowW)/1.58,(screenH-windowH)/1.01 
                guiSetPosition(RightB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(ExitB,false) 
                local x,y = (screenW-windowW)/2.1,(screenH-windowH)/1.011 
                guiSetPosition(ExitB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(BuyB,false) 
                local x,y = (screenW-windowW)/2.1,(screenH-windowH)/1.047 
                guiSetPosition(BuyB,x,y,false) 
                local screenW,screenH=guiGetScreenSize() 
                local windowW,windowH=guiGetSize(VehicleL,false) 
                local x,y = (screenW-windowW)/1.95,(screenH-windowH)/1.07 
                guiSetPosition(VehicleL,x,y,false) 
            else 
                outputChatBox( "No car found, please re-enter the marker", 255, 0, 0 ) 
                destroyElement(CarOfTheDay) 
                return 
            end 
        end 
    end 
end 
addEventHandler("onClientMarkerHit",Shop,ShopF) 
  
function LeftFEnter() 
    if isElement( CarOfTheDay ) then 
        local RX, RY, RZ = getElementRotation( CarOfTheDay ) 
        setElementRotation(CarOfTheDay, RX, RY, RZ + 10) 
    end 
end 
  
function RightFEnter() 
    if isElement( CarOfTheDay ) then 
        local RX, RY, RZ = getElementRotation( CarOfTheDay ) 
        setElementRotation(CarOfTheDay, RX, RY, RZ - 10) 
    end 
end 
  
function BuyF() 
    CW = guiCreateWindow(470,244,543,180,"Confirmation",false) 
    CL = guiCreateLabel(2,47,545,20,"Are you sure you want to buy this car for $3.000?",false,CW) 
    guiLabelSetColor(CL,0,255,0) 
    guiLabelSetHorizontalAlign(CL,"center",false) 
    guiSetFont(CL,"default-bold-small") 
    YesB = guiCreateButton(59,115,159,39,"Yes",false,CW) 
    NoB = guiCreateButton(322,115,159,39,"No",false,CW) 
    addEventHandler("onClientGUIClick",NoB,NoF,false) 
    addEventHandler("onClientGUIClick",YesB,YesF,false) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(CW,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(CW,x,y,false) 
end 
  
function NoF() 
    destroyElement(CW) 
end 
  
function YesF() 
    destroyElement(CW) 
    destroyElement(LeftB) 
    destroyElement(RightB) 
    destroyElement(ExitB) 
    destroyElement(BuyB) 
    destroyElement(VehicleL) 
    showPlayerHudComponent("all", true) 
    setCameraTarget(localPlayer) 
    showCursor(false) 
    colr1, colg1, colb1, colr2, colg2, colb2, colr3, colg3, colb3, colr4, colg4, colb4 = getVehicleColor(CarOfTheDay, true) 
    Model = getElementModel(CarOfTheDay) 
    destroyElement(CarOfTheDay) 
    triggerServerEvent("spawnCar",getRootElement(),localPlayer, Model, colr1, colg1, colb1, colr2, colg2, colb2, colr3, colg3, colb3, colr4, colg4, colb4) 
    showCursor(false) 
end 
  
function onStop() 
    setCameraTarget(localPlayer) 
end 
addEventHandler("onClientResourceStop",resourceRoot,onStop) 
  
function ExitF() 
    if not CW then 
        destroyElement(LeftB) 
        destroyElement(RightB) 
        destroyElement(ExitB) 
        destroyElement(BuyB) 
        destroyElement(VehicleL) 
        destroyElement(CarOfTheDay) 
        showPlayerHudComponent("all", true) 
        setCameraTarget(localPlayer) 
        showCursor(false) 
    elseif CW then 
        destroyElement(LeftB) 
        destroyElement(RightB) 
        destroyElement(ExitB) 
        destroyElement(BuyB) 
        destroyElement(VehicleL) 
        destroyElement(CarOfTheDay) 
        destroyElement(CW) 
        showPlayerHudComponent("all", true) 
        setCameraTarget(localPlayer) 
        showCursor(false) 
    end 
end 

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...