Jump to content

[TUT] How to make a PM SYSTEM


qaisjp

Recommended Posts

Please visit the updated tutorial instead!


In the modification on the server, there are multiple resources to make a server. There are many resources already shipped with MTA, however you may wish to edit or create some.

Basic components of resources

  • meta.xml file - States what needs to be loaded and other metadata
  • scripts - What is the use of this resource, without scripts? Scripts do the action

In this tutorial we will make a PM system. Let's think what we need to do, we need to make a command and attach that to the function. We need to manipulate who we are sending to and the text we are sending.

First we need to make our resource folder, generally the resources folder is in

Quote
C:/Program Files/MTA San Andreas 1.1/server/mods/deathmatch/resources/

in MTA 1.1, they support multiple sub-dir's so let's make a subfolder called "[TUT]". It can be anything you want, but this just makes the resources folder organised. Make sure it has '[' and ']'.

Inside [TUT] make a folder called 'pm-system' - this will be our working directory and our main resource folder.

Inside our folder, we create a file named 'meta.xml' and we need to type a few lines to make sure our resource is loaded correctly. Inside the meta file we will type this:

  
<meta> 
    <script src="script.lua" type="server"/> 
</meta> 
  
 

The first and third line is MANDATORY, meaning it must be there. The second line tells MTA to load our script (which we will soon make ahead of this tutorial)

'

'type="server"' - What side the script will operate on, can be server or client

Making the script

First we need to create a command handler and a function for it too

 

function pmHandler() -- create function 
  
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 
  
 

When we do /pm nothing should happen, we need to add the target person and the text and also the output

 

function pmHandler(player, _, to, text) -- create function.  
      
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 
  
 

player - the person who wrote the command

to - the person we want to send the pm to

text - the text

 

function pmHandler(player, _, to, text) -- create function.  
     local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        -- We send the messages! 
     end 
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 
  
 

In the above code we are using getPlayerFromName to match the player by his name and we are checking if there is a player.

 

function pmHandler(player, _, to, text) -- create function.  
     local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        outputChatBox("PM --> #FFFFFF "..getPlayerName(personToReceive)..": ".. text, player, 255,0,0,true) 
        outputChatBox("[PM] "..getPlayerName(player).."#FFFFFF: ".. text, personToReceive, 255,0,0,true) 
     end 
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 
  
 

In the fourth line we tell the sender (John) we have sent it, we would get some sort of message when we type /pm qais hi

PM --> Qais: hi

and the receiver (Qais)gets

[PM] John: hi

If we type '/pm qais hi Qais this is doesnt work' we wont get the spaces, let's implement that.

 

function pmHandler(player, _, to, ...) -- create function.  
     local text = table.concat({...}," ") 
     local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        outputChatBox("PM --> #FFFFFF "..getPlayerName(personToReceive)..": ".. text, player, 255,0,0,true) 
        outputChatBox("[PM] "..getPlayerName(player).."#FFFFFF: ".. text, personToReceive, 255,0,0,true) 
     end 
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 
  
 

(is it an abrupt ending)

  • Like 1
Link to comment
  • 2 weeks later...
  • 1 year later...
  • 6 months later...
  • 2 years later...
  • 1 month later...
function pmHandler(player, _, to, ...) -- create function. 
     local text = table.concat({...}," ") 
     local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        outputChatBox("PM --> #FFFFFF "..getPlayerName(personToReceive)..": ".. text, player, 255,0,0,true) 
        outputChatBox("[PM] "..getPlayerName(player).."#FFFFFF: ".. text, personToReceive, 255,0,0,true) 
     end 
end 
  
addCommandHandler ( "pm", pmHandler ) -- attach handler to function 

you typed personToRecieve at first output.

Link to comment
  • 2 weeks later...
  local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        outputChatBox("PM --> #FFFFFF "..getPlayerName(personToRecieve)..": ".. text, player, 255,0,0,true) 

local personToReceive = getPlayerFromName(to)

and u typed in the outputChatBox getPlayerName(personToRecieve) it must be

getPlayerName(personToReceive)

Link to comment
  local personToReceive = getPlayerFromName(to) -- We get the player from the name 
     if personToReceive then-- if the person in the above line exists, then continue 
        outputChatBox("PM --> #FFFFFF "..getPlayerName(personToRecieve)..": ".. text, player, 255,0,0,true) 

local personToReceive = getPlayerFromName(to)

and u typed in the outputChatBox getPlayerName(personToRecieve) it must be

getPlayerName(personToReceive)

Oh, you mean receive vs recieve. Thanks!

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...