[Question] input cmd

  • Hi all,


    i dont know there my mistake is, maybe some can help me
    ----------------------------------------------
    -- Create Portpoint only Admins
    elseif cmd[1] == "/ptnew" then
    local target;
    -- Checking if Admin :
    if not event.player:isAdmin() then return msgAccessDenied(event.player) end
    local name = cmd[2]
    local pos = event.player:getPlayerPosition()
    ptnew(event.player, pos, name)
    -------------------------------------------------
    function ptnew (admin, pos, name)
    local targetPos = admin:getPlayerPosition();
    local posx = targetPos.x;
    local posy = targetPos.y;
    local posz = targetPos.z;

    admin:sendTextMessage(posx);
    admin:sendTextMessage(posy);
    admin:sendTextMessage(posz);
    admin:sendTextMessage(name);

    database:queryupdate("INSERT INTO `port` (`name`, `posx`, `posy`, `posz`) VALUES ('".. name .."', '".. posx .."', ".. posy ..", '".. posz .."')")
    end
    ------------------------------------------------


    when i do /ptnew test 1


    it will not take the 1, so when i have a space the rest after the space will not in the name


    thx for you help


    Vossi

  • If I get you right you want to store "test 1" into the variable "name" instead of just "test"?
    You need to keep in mind that "cmd" is an array of the splitted command (so each index contains one word/parameter). You find the full command in the event.command variable. If you want to remove the "/ptnew" at the beginning, you can do this:
    [lua]local name = string.sub(event.command, string.len(cmd[1]) + 2);[/lua]
    When entering "/ptnew test 1" you will get "test 1" for name, when entering "/ptnew test 1 2 3 4" you will get "test 1 2 3 4" etc.

Participate now!

Don’t have an account yet? Create a new account now and be part of our community!