help by a function

  • hi @ all



    I have a problem with the function.
    admin: send text message ("" ..pName .. "your hunger & thirst was quenched by" ..aName);


    The message does not reach pName but at aName


    Where is the error?


    I would like to:
    admin sended text message to player ...


    Not !!!


    admin sended text message to admin
    can you help me?



    [lua]elseif cmd[1] == "/hunger" then
    -- Checking if admin :
    if not event.player:isAdmin() then return msgAccessDenied(event.player) end
    -- Checking if there's an argument
    if not cmd[2] then return msgInvalidUsage(event.player) end
    -- Checking if targeted player exist
    if not server:findPlayerByID(cmd[2]) then return msgBadID(event.player) end
    local target = server:findPlayerByID(cmd[2]);
    hunger(event.player, target)[/lua]



    [lua]function hunger(admin, player)
    local aName = admin:getPlayerName();
    local pName = player:getPlayerName();
    admin:sendTextMessage(" "..pName.." dein Hunger&Durst wurden gestillt von "..aName);
    player:setPlayerHunger(100)
    player:setPlayerThirst(100)
    end[/lua]

  • Lua-Quellcode



    elseif cmd[1] == "/hunger" then
    local target;
    -- Checking if admin :
    if not event.player:isAdmin() then return msgAccessDenied(event.player) end
    -- Checking if there's an argument
    if not cmd[2] then return msgInvalidUsage(event.player) end
    -- Checking if targeted player exist
    if not server:findPlayerByID(cmd[2]) then return msgBadID(event.player) end
    local target = server:findPlayerByID(cmd[2]);
    hunger(event.player, target)

  • here's the error in a line:


    [lua]admin:sendtextmessage(" "..pName .. "your hunger & thirst was quenched by" ..aName);[/lua]



    [lua]function hunger(admin, player)
    local aName = admin:getPlayerName();
    local pName = player:getPlayerName();
    admin:sendTextMessage(" "..pName.." dein Hunger&Durst wurden gestillt von "..aName);
    player:setPlayerHunger(100)
    player:setPlayerThirst(100)
    end[/lua]

  • There is a misunderstanding of the 'sendTextMessage()' function: When calling this function on a player, a text message (i.e. a chat message) will be send to this player. So when you call player:sendTextMessage(...), you send a chatmessage to this particular player.
    So in your case don't call this function on the admin, but call it on the target player ;)

Participate now!

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