Jump to content

help


golanu21

Recommended Posts

function creatvehicles( yoy, source, modelid, tablename, key, ...) 
if model and tablename and key then 
local modelid = tonumber(modelid) 
 tablename = table.concat({...}, " ") 
 key = tonumber(yoy) 
 x, y, z = getElementPosition(source) 
  
    veh = createVehicle(modelid, x, y +1, z, 0 ,0 , 0, tablename) 
 xv, yv, zv = getElementPosition( veh ) 
        setVehicleLocked(veh, true) 
    marker = createMarker(xv, yv +1, zv, "cylinder", 1, 255, 0, 0, 100) 
else 
outputChatBox("[invalidSyntax]:/makeveh [model], [tablename], [key]", thePlayer, 255, 0, 0) 
end 
end 
addCommandHandler("makeveh", creatvehicles) 

when i use the command like this... /makeveh 543 koi 213 is give me the sintax...

Link to comment

For what are you using the table?

btw, you are checking if you got the model, instead of modelid.

function creatvehicles( yoy, source, modelid, tablename, key, ...) 
    if ( ( modelid ) and ( tablename ) and ( key ) ) then 
        local modelid = tonumber( modelid ); 
        tablename = table.concat( {...}, " " ); 
        key = tonumber( key ); 
        x, y, z = getElementPosition( source ); 
        veh = createVehicle( modelid, x, y +1, z, 0 ,0 , 0, tablename ); 
        xv, yv, zv = getElementPosition( veh ); 
        setVehicleLocked( veh, true ); 
        marker = createMarker( xv, yv +1, zv, "cylinder", 1, 255, 0, 0, 100 ); 
    else 
        outputChatBox("[invalidSyntax]:/makeveh [model], [tablename], [key]", thePlayer, 255, 0, 0) 
    end 
end 

Link to comment

Updated it with 3 examples on how you could check if each parameter consists of numbers or letters. It's up to you to add more foolproof checks if you want it :)

Server Side:

function onPlayerCreateVehicle_Handler(source, cmd, ...) 
local message = table.concat({...}, " ") 
local messageParameters = split(message, " ") 
    if(string.match(messageParameters[1], "[0-9]")) then -- Check if first parameter are numbers, if so, continue checking. 
        if(not string.match(messageParameters[2], "[0-9]")) then -- Check if second parameter consist only of letters. If so, continue checking. 
                if(string.match(messageParameters[3], "[0-9]")) then -- Check if third parameter are numbers, if so, create vehicle. 
                    local playerX, playerY, playerZ = getElementPosition(source) 
                    local newVehicle = createVehicle(tonumber(messageParameters[1]), playerX, playerY-5, playerZ, 0, 0, 0, messageParameters[2]) 
                    local vehMarker = createMarker(playerX, playerY-5, playerZ-2, "cylinder", 5, 255, 0, 0, 100) 
                        setVehicleLocked(newVehicle, true) 
                else 
                    outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, invalid Key ID! Must consist of numbers!", getRootElement(), 145, 145, 145, true) 
                end 
        else 
            outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, invalid License Plate Text! No numbers allowed!", getRootElement(), 145, 145, 145, true) 
        end 
    else 
        outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, incorrect Car ID!", getRootElement(), 145, 145, 145, true) 
    end 
end 
addCommandHandler("makeveh", onPlayerCreateVehicle_Handler, false) 

Link to comment
Updated it with 3 examples on how you could check if each parameter consists of numbers or letters. It's up to you to add more foolproof checks if you want it :)

Server Side:

function onPlayerCreateVehicle_Handler(source, cmd, ...) 
local message = table.concat({...}, " ") 
local messageParameters = split(message, " ") 
    if(string.match(messageParameters[1], "[0-9]")) then -- Check if first parameter are numbers, if so, continue checking. 
        if(not string.match(messageParameters[2], "[0-9]")) then -- Check if second parameter consist only of letters. If so, continue checking. 
                if(string.match(messageParameters[3], "[0-9]")) then -- Check if third parameter are numbers, if so, create vehicle. 
                    local playerX, playerY, playerZ = getElementPosition(source) 
                    local newVehicle = createVehicle(tonumber(messageParameters[1]), playerX, playerY-5, playerZ, 0, 0, 0, messageParameters[2]) 
                    local vehMarker = createMarker(playerX, playerY-5, playerZ-2, "cylinder", 5, 255, 0, 0, 100) 
                        setVehicleLocked(newVehicle, true) 
                else 
                    outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, invalid Key ID! Must consist of numbers!", getRootElement(), 145, 145, 145, true) 
                end 
        else 
            outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, invalid License Plate Text! No numbers allowed!", getRootElement(), 145, 145, 145, true) 
        end 
    else 
        outputChatBox("[server]: #FF0000/makeveh(Syntax Error!)#919191, incorrect Car ID!", getRootElement(), 145, 145, 145, true) 
    end 
end 
addCommandHandler("makeveh", onPlayerCreateVehicle_Handler, false) 

ERROR: ss\server.lua:4: bad argument #1 to 'match' (string expected, got nil)

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