Jump to content

Best way to "announce" a text


Eth

Recommended Posts

So hello everyone, My name is Eth and I have recently moved from SAMP to MTA [let's face it, MTA Is way better than SAMP]

So when I joined MTA I started to script my own gamemode right away as I have Large experience in programming in different languages and everything works great! but I have a little problem here, I am trying to do an announce command for admins that will announce a text for 5 seconds then disappears again, I have searched in MTA wiki but I didn't find the best way to do it.

here is my announce command:

function Announce( sourcePlayer, commandname, ...) 
  
  local message = table.concat({...}, " ") 
  
  if(message ~= nil and message ~= "") then 
  
  if(tonumber(getElementData(sourcePlayer,"Admin")) < 2) then 
  
  outputChatBox("ERROR: you Can't use This CMD.",sourcePlayer) 
  
  outputDebugString("WARNING: Player " .. getPlayerName(sourcePlayer) .. " has attempt to use An ADMIN command. [/"..commandname.."]") 
  
  return 
  
end 
-- I want my code to be here to announce message 
  
else 
  outputChatBox("Error Right Syntax: /announce [text] ",sourcePlayer) 
  
   end 
end   
  

so how can I do that? thank you.

Link to comment

I would also recommend DX functions, have a look at this maybe which already does most of the job for you: https://github.com/GTWCode/GTW-RPG/tree/master/resources/GTWtopbar, by including that a simple announce command based on your code would look like this:

function Announce( sourcePlayer, commandname, ...) 
    local message = table.concat({...}, " ") 
    if(message ~= nil and message ~= "") then 
        if(tonumber(getElementData(sourcePlayer,"Admin")) < 2) then 
            outputChatBox("ERROR: you Can't use This CMD.",sourcePlayer) 
            outputDebugString("WARNING: Player " .. getPlayerName(sourcePlayer) .. " has attempt to use An ADMIN command. [/"..commandname.."]") 
            return 
        end 
        export.GTWtopbar("Note: "..message, root, 255, 255, 255) 
    else 
        outputChatBox("Error Right Syntax: /announce [text] ",sourcePlayer) 
    end 
end 
addCommandHandler("announce", Announce) 

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