Jump to content

Error when detecting a number


Recommended Posts

Posted

Ok! Yours seems to spawn the vehicle and display the message, but fails to display any messages if you enter a incorrect vehicle id, but will display it if you input a invalid name :roll: strange.. :P

All kinds of feedback are welcome on all of my posts.

Posted

Now fix it! xD all joking aside, I'm trying to fix it myself :roll:

EDIT:

Revised it a little bit and I fixed it!

For anyone wanting to use it:

function createVehicleCommand ( thePlayer, commandName, carName ) 
    if not carName then 
        outputChatBox("Syntax: /v [vehicle id/model]", thePlayer, 255, 0, 0) 
        return 
    end 
    local x, y, z = getElementPosition ( thePlayer ) 
    local carModel = tonumber ( carName ) 
    if (type(carModel) == "number") then 
         if (carModel < 400 or carModel > 611) then 
            outputChatBox("Invalid vehicle ID!", thePlayer, 255, 0, 0) 
            return 
        else 
            createVehicle(carModel, x + 5, y, z) 
            outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (#" .. carModel .. ") was spawned with an ID of " .. vehicles.id, thePlayer, 0, 255, 0) 
            vehicles.id = (vehicles.id + 1) 
            return 
        end 
    else 
        local carModel = getVehicleModelFromName(carName) 
        if (not carModel) then 
            outputChatBox("Invalid vehicle name!", thePlayer, 255, 0, 0) 
            return 
        else 
            createVehicle(carModel, x + 5, y, z) 
            outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, thePlayer, 0, 255, 0) 
            vehicles.id = (vehicles.id + 1) 
            return 
        end 
    end 
end 
addCommandHandler ( "v", createVehicleCommand ) 

All kinds of feedback are welcome on all of my posts.

Posted (edited)
function createVehicleCommand ( thePlayer, commandName, carName ) 
            local x, y, z = getElementPosition ( thePlayer ) 
            if (type(tonumber(carName)) == "number") then 
                if tonumber(carName) > 400 and tonumber(carName) < 611 then 
                    outputChatBox("Invalid Vehicle", player, 255, 0, 0) 
                else 
                    local veh = createVehicle(carName, x+5, y, z) 
                    outputChatBox("Your " .. getVehicleName(veh) .. " (#" .. tonumber(carName) .. ") was spawned with an ID of " .. vehicles.id, player, 0, 255, 0) 
                    vehicles.id = vehicles.id+1 
                end 
            else 
                local carModel = getVehicleModelFromName(carName) 
                if not carModel then 
                    outputChatBox("That is not a valid car name") 
                else 
                    createVehicle(carModel, x+5, y, z) 
                    outputChatBox("Your " .. getVehicleName(carModel) .. " (#" .. carModel .. ") was spawned with and ID of " .. vehicles.id, player, 0, 255, 0) 
                    vehicles.id = vehicles.id+1 
                end 
            end 
        end 
        addCommandHandler("v", createVehicleCommand) 

Edited by Guest

Ingame nick: Cadu12

Posted

Your slightly late, already revised it and it works both ways.

Also, you forgot a tag there buddy!

function createVehicleCommand ( thePlayer, commandName, carName ) 
    local currVehicle = getPedOccupiedVehicle(thePlayer) 
    if currVehicle then 
        outputChatBox("You already are in a vehicle! Use /cv to change your vehicle!", thePlayer, 255, 0, 0) 
        return 
    end 
    if commandName == "v" then 
        if not carName then 
            outputChatBox("Syntax: /" .. commandName .. " [vehicle id/model]", thePlayer, 255, 0, 0) 
            return 
        end 
        local x, y, z = getElementPosition ( thePlayer ) 
        local carModel = tonumber ( carName ) 
        if (type(carModel) == "number") then 
            if (carModel < 400 or carModel > 611) then 
                outputChatBox("Invalid vehicle ID!", thePlayer, 255, 0, 0) 
                return 
            else 
                createVehicle(carModel, x+5, y, z+2) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
        else 
            local carModel = getVehicleModelFromName(carName) 
            if carName == "random" then 
                carModel = math.random(400,611) 
                createVehicle(carModel, x+5, y, z+2) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
            if (not carModel) then 
                outputChatBox("Invalid vehicle name!", thePlayer, 255, 0, 0) 
                return 
            else 
                createVehicle(carModel, x+5, y, z+2) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
        end 
    elseif commandName == "vx" then 
        if not carName then 
            outputChatBox("Syntax: /" .. commandName .. " [vehicle id/model]", thePlayer, 255, 0, 0) 
            return 
        end 
        local x, y, z = getElementPosition ( thePlayer ) 
        local carModel = tonumber ( carName ) 
        local theVeh 
        if (type(carModel) == "number") then 
            if (carModel < 400 or carModel > 611) then 
                outputChatBox("Invalid vehicle ID!", thePlayer, 255, 0, 0) 
                return 
            else 
                theVeh = createVehicle(carModel, x, y, z+2) 
                warpPedIntoVehicle(thePlayer, theVeh) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
        else 
            local carModel = getVehicleModelFromName(carName) 
            if carName == "random" then 
                carModel = math.random(400,611) 
                theVeh = createVehicle(carModel, x, y, z+2) 
                warpPedIntoVehicle(thePlayer, theVeh) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
            if (not carModel) then 
                outputChatBox("Invalid vehicle name!", thePlayer, 255, 0, 0) 
                return 
            else 
                theVeh = createVehicle(carModel, x, y, z+2) 
                warpPedIntoVehicle(thePlayer, theVeh) 
                outputChatBox("Your " .. getVehicleNameFromModel(carModel) .. " (Model: " .. carModel .. ") (ID: " .. vehicles.id .. ") was spawned!", thePlayer, 0, 255, 0) 
                vehicles.id = (vehicles.id + 1) 
                return 
            end 
        end 
    end 
end 
addCommandHandler("v", createVehicleCommand) 
addCommandHandler("vx", createVehicleCommand) 

All kinds of feedback are welcome on all of my 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 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...