Author Topic: -Tutorial-PM System  (Read 29 times)

Offline Brian

  • Owner
  • Regular Poster
  • *****
  • Posts: 61
  • Location: Moscow,Russia
    • View Profile
-Tutorial-PM System
« on: June 22, 2012, 10:59:50 pm »
Hello players,today i will show you how to make PM system for your server.
First make your resourse folder
Computer/Local Disk:C/Program Files/MTA/Server/Mods/Deathmatch/Resourse

When we create folder,we must create file called "meta.xml" in our folder.

Code: [Select]
<meta>
    <script src="script.lua" type="server"/>
</meta>

The first and third line must be here.The second line tells MTA to load our script.
<script' - Tells mta it is a script
'src="script.lua"' - Tell's mta where the script file is
'type="server"' - What side the script will operate on, can be server or client

Now,we will start...First we will create function

Code: [Select]
function pmHandler() -- create function
 
end
 
addCommandHandler ( "pm", pmHandler ) -- attach handler to function

When we do /pm nothing happend , so we need to add target person.

Code: [Select]
function pmHandler(player, _, to, text) -- create function.
     
end
 
addCommandHandler ( "pm", pmHandler ) -- attach handler to function

player-the person who write command.
to-the person we want send pm.
text-the text.

f
Code: [Select]
unction 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.

Code: [Select]
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(personToRecieve)..": ".. 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 (Brian) we have sent it, we would get some sort of message when we type /pm zem hi
PM --> Zem: hi
and the receiver (Zem)gets
[PM] Brian: hi

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

Code: [Select]
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(personToRecieve)..": ".. 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


We finished,if you have questions ask . As you can see,it's not so hard.
Education is the most powerful weapon which you can use to change the world.

Share on Bluesky Share on Facebook