qaisjp Posted November 24, 2011 Share Posted November 24, 2011 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) 1 Link to comment
MetaGamer Posted November 24, 2011 Share Posted November 24, 2011 very nice! Keep it up. Link to comment
12p Posted November 24, 2011 Share Posted November 24, 2011 Wrong section. Can a moderator move this to Scripting, plz? Ty beforehand. Link to comment
MetaGamer Posted November 25, 2011 Share Posted November 25, 2011 Wrong section. Can a moderator move this to Scripting, plz? Ty beforehand. If there is no section for tutorial then Other section is used. Don't you know that? Link to comment
qaisjp Posted November 25, 2011 Author Share Posted November 25, 2011 very nice! Keep it up. Thanks Link to comment
World Championship Posted December 6, 2011 Share Posted December 6, 2011 How do you make this command work with part of the names? Typing the whole name is a bit hard and since MTA doesn't have IDs... Link to comment
Xeno Posted December 8, 2011 Share Posted December 8, 2011 And how would I make it so it gets the text from say, a guiMemo and sends the text inside of the memo? Im guessing I would change around this: local text = table.concat({...}," ") Link to comment
Castillo Posted December 8, 2011 Share Posted December 8, 2011 local text = guiGetText(myGUIElement) Link to comment
ViRuZGamiing Posted February 10, 2013 Share Posted February 10, 2013 I think you also could add: else outputChatBox ("This Player doesn't exist") end Link to comment
qaisjp Posted September 7, 2013 Author Share Posted September 7, 2013 This tutorial has been updated and revamped at https://wiki.multitheftauto.com/wiki/Tu ... /PM_System Make sure to visit https://wiki.multitheftauto.com/wiki/Tutorials too! Please update the main topic to prepend the link in a large text directing users to the wikipage for the updated tutorial! Link to comment
Chris!i! Posted February 18, 2016 Share Posted February 18, 2016 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
qaisjp Posted February 19, 2016 Author Share Posted February 19, 2016 you typed personToRecieve at first output. Sorry? Don't quite get what you mean. Link to comment
Chris!i! Posted March 3, 2016 Share Posted March 3, 2016 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
qaisjp Posted March 5, 2016 Author Share Posted March 5, 2016 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
Recommended Posts