Jump to content

Recommended Posts

Всем привет

как переделать скрипт, чтобы отправлять сообщения можно было не только по id, но и по никнейму.

пример: /pm id|nick text

function sendMessage(thePlayer, commandname, id, ...) 
        if ids[tonumber(id)] ~= nil then 
                local message = "" 
                for i,v in ipairs(arg) do 
                        message = message.." "..v 
                end 
                outputChatBox("*PM Sent!",thePlayer,0,255,0) 
                outputChatBox("*PM from "..getPlayerName(thePlayer)..":"..message,ids[tonumber(id)],255,255,0) 
        else 
                outputChatBox("*Wrong id!",thePlayer,255,0,0) 
        end 
end 

Link to comment
function findPlayer( namepart ) 
    local player = getPlayerFromName( namepart ) 
    if player then 
        return player 
    end 
    for _,player in pairs( getElementsByType 'player' ) do 
        if string.find( string.gsub( getPlayerName( player ):lower( ),"#%x%x%x%x%x%x", "" ), namepart:lower( ), 1, true ) then 
            return player 
        end 
    end 
    return false 
end 
  
function sendMessage( thePlayer, _, id_nick, ... ) 
    local find = ids[ tonumber( id_nick ) ] or findPlayer( id_nick ) 
    if find then 
        outputChatBox( "*PM Sent!",thePlayer,0,255,0 ) 
        outputChatBox( "*PM from "..getPlayerName( thePlayer )..":"..table.concat( { ... },' ' ),find,255,255,0 ) 
    else 
        outputChatBox( "*Wrong id/name!",thePlayer,255,0,0 ) 
    end 
end 
addCommandHandler( 'private_message',sendMessage ) 

/private_message [ ид/ник ][ сообщение ]

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