Jump to content

Osidog

Members
  • Posts

    10
  • Joined

  • Last visited

Osidog's Achievements

Member

Member (5/54)

0

Reputation

  1. This is the script I was practising on. I'd say it's complete now. I was testing it and found a few problems but I think they're all solved now. It's given me an understanding how the scripts are made, and it has been a good starting point for me to start learning LUA. I'd like to thank you all for the support given. It's been very helpful and i doubt i would have been able to do it without the support and ofcourse the wiki. I'm going to keep reading the wiki and try and make some more scripts. I feel as if i'm getting the hang of it, but still got a long way to go. The script isn't a big one but I've literally spent hours and hours working on it, mainly experimenting, trying different things and lots of testing but it seems to be working ok now. Here's the script, if you'd like to have it or just want to look. Thanks All. function personalMessage(sender, cmd, sendTo, ... ) -- Find the player to send the message too and also get names of both players. recipient = getPlayerFromName(sendTo); recipientName = getPlayerName(recipient); senderName = getPlayerName(sender); -- Pack all words of message into a table tbl_Message = {...} -- Join all extra arguments into a string to form message theMessage = table.concat( tbl_Message, " " ); -- Check whether the recipient has been found and senders message exist. if recipient ~= false and #tbl_Message > 0 then -- No errors are found so send message to recipient and a confirmation to sender outputChatBox("PM from " .. senderName .. ": " .. theMessage, recipient, 255, 50, 0); outputChatBox("PM successfully sent to " .. recipientName, sender, 255, 50, 0); else -- There was a problem with the message. Send a notice to the sender. outputChatBox("PM not sent. Check format /pm full_name message", sender, 255, 50, 0) end end addCommandHandler("pm", personalMessage); -- command handler...
  2. Ok i will do. edit. Sorry subenji99 I didn't see your post at first. I wasn't ignoring you. I'm starting to understand it now. It's very hard for me to get my head around but i'm getting there now. you explained the source very well too. Thanks for your post.
  3. Alexander that's a great example. Thanks. eAi I've read those links. It's a lot to take in. I think i'm ok with source. Going to try it in a command to test it out myself. The 'getRootElement i'm still a bit confused after reading the two links. I'm going to read them again see if i can understsand it a bit more. I've been trying to work on that PM script and have been running into a few problems. I'll post the script in here, although I've got a few more things i'll like to try with it before then. Thanks.
  4. OK, i'm a bit confused still but it is getting late here in England. I get that the argument names aren't significant although the order of them is. I understand that now. Now With command handlers, the first argument is always the player name who entered the command, the second is the argument that is required for mta to call the function & the rest are whatever you want them to be, although the arguments are only needed if you need to grab extra data from whoever entered them? For example the recipients name and the message. So let's say i make the function function GoogleSearch ( ) outputChatBox("Google.com search engine") end addCommandHandler("google", GoogleSearch) I haven't included any arguments, and it's worked. I was really confused as to what arguments I include and in which order, although i think i'm starting to understand more. Although there's still a few things i've come across that i don't understand, such as when and why i may sometimes need to add getRootElement to the addEventHandler or the source in the [/b]outputChatBox[/b] - see this example. https://wiki.multitheftauto.com/index.ph ... PlayerJoin It'd be nice if someone could also explain that, although I don't want to pester you all with questions as i'm sure to have lots and if I be honest I've not searched as much as i should as it's getting late. I'm going to get some shuteye and will carry on with this tomorrow. Also If i'm wrong with the above please correct me. Thanks everyone for all your help.
  5. Uhm, there is a mistake here: The variable sender is a player element, and you can not put it into a string. And the variable sendto is also wrong, cuz there need to be cmd. A better example of the code above: -- wiki says: player playerSource, string commandName, [string arg1, string arg2, ...] -- After commandName you can put the arguments of the command. In this case the name you want to sent to and a message function personalMessage(sender, cmd, sendTo, message) -- You see that there are in total 4 arguments needed in other to make the command work. -- Now we get the recpient recipient = getPlayerFromName(sendTo); -- Now we get the player name of the sender senderName = getPlayerName(sender); -- Now we are going to output the message into the chatbox outputChatBox("pm from " .. senderName .. ": " .. message, recipient); -- Now this command is working. end -- Add the command handler, i guess you know how that works. addCommandHandler('pm', personalMessage); A full working pm command. Thanks Alexander. I'll go and test it again now after making the adjustments. One more thing though. I don't quite understand why "cmd" has to be included, or what it does. Is it the same as using "command"? Could you explain that to me please. Thanks. edit/ Alexander you're right. That's working! Just need to try and understand the code a bit more, but i'm getting there, slowly but surely. Thanks.
  6. Ok. Not quite there just yet. I've logged into admin and opened up the debug window. I've tried sending a PM to myself. (that should be possible?) Although nothing shows up in the chat box or the debug window. I entered "/pm osidog test123" I've also added the resource to start with the server & have tied restarting it. function PersonalMessage(sender, sendto, message) -- sends a private message to one person recipient = getPlayerFromName(sendto) if recipientthen outputChatBox("PM from" .. sender ":" .. tostring(message), recipient ) end end addCommandHandler("pm", PersonalMessage)
  7. Ok. I think I understand. i will go test this out.
  8. Thanks 50p. I'm slowly getting the hang of it. I keep making lots of mistakes and there's still a lot I don't understand. but all will come to me eventually if I keep trying. Your help is invaluable to me whilst i learn. I appreciate it. If i'm right them, adding the visibleTo will allow me to send to just one player. function PersonalMessage(sender, sendto, message) -- sends a private message to one person recipient = getPlayerFromName(sendto) outputChatBox("PM from" .. sender ":" .. tostring(message), element visibleTo=recipient ) end addCommandHandler("pm", PersonalMessage) I'm going to test this out. Hoping it will work for me. I'd like to add some error checking which searches for the recipients name to ensure someone's in the server with that name, and if there isn't it will send a message to the senders telling them so.
  9. Thank you Ryder. One more question. How does one send a message to one player. I know using outputChatBox sends the message to everyone. Is there a function/element which allows me to send a message to just one person? I've been searching around for it but can't find it.
  10. Hi. I'm learning the basics. I have reading through the pages at http://robhol.net/guide/basics/ https://wiki.multitheftauto.com/index.ph ... putChatBox I was able to start basic commands and all was going well. I then scrapped my lua script and tried making some of my own. Although none of them would work. So i tried even the very basic commands and they wouldn't work. This is one of the commands that's not working. function SayHello(player, command) outputChatBox("Hello Everyone") end addEventHandler("hi", SayHello) I'd expect this code to add the text "Hello Everyone" to the chatbox when I type /hi nothing happends. have i made a mistake somewhere?
×
×
  • Create New...