cokacola Posted April 1, 2009 Share Posted April 1, 2009 Hello, i have been trying to make a mail system for my server, i have a few things.. okay, first, here is my script so far(it renderes without errors and creates the DB) --Player mail system function createSQLOnStart () -- create our table, if it doesn't already exist executeSQLCreateTable ( "playermail", "playerto TEXT, mailmessage TEXT, mailsubject TEXT, mailread TEXT, mailfrom TEXT" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) function sendMail (playerTo, title, message, from) res = executeSQLInsert ( "playermail", "'" .. playerTo .. ",'" .. message .. "','" .. title .. "', '0', '" .. from .. "'" ) if ( res ) then outputChatBox ("Mail Sent", source) else outputChatBox ("Failed to send mail", source) end end addCommandHandler("sendmail", sendMail) function checkmail () sourcename = getClientName ( source ) result = executeSQLSelect ( "playermail", "playerto", "mailmessage", "mailtitle", "mailread", "mailfrom", "playerto = '" .. sourcename .. "', mailread = '1'" ) if ( result == false ) then outputChatBox ( "No new mail found", source ) else outputChatBox ( "New Mail Found, Subject: " .. result[1][3] ) outputChatBox ( "Message: " .. result[1][2] ) outputChatBox ( "From: " .. result[1][5] ) executeSqlUpdate ( "playermail", "mailread = '1'", "playerto = '" .. sourcename .. "', mailsubject = '" .. result[1][3] .. "', mailmessage = '" .. result[1][2] .. "'" ) end addCommandHandler("checkmail", checkmail) end Okay, so in-game "/sendmail" and "/checkmail" do nothing(not actually shore on sendmail because it has no output) so i dunno why i does nothing. Secondly, is there a way i can make it so only admins can send mail, and if this is possible, make it so the server can auto send mail(because cops can give out tickets, so i am also trying to work out how to make a ticket script force you to pay after 2 game days or jails you, i need help on where to start, i already have a jail script i can use) so yea, got a few things i need help with, but mainly, i need it to work thanks! EDIT: may i ask what this means? when i try to use sendmail, this happons in server console: "Error: *pathtoscript*:266 attempting to concatenate global 'playerto' " I am passing all required parameters (tried typing bizzycola and for my id '0' still getting nothing, also checkmail won't even say "no new mail" it also does nothing, but returns no errors Edit2: forgot 1 more thing, is there a way to tell if someone is putting out a fire?(for job script i am also making) oh and also, anyone who solves my problems / answers my questions gets in the credits..(i am going to make a /credits or something) and no, i am not asking you to write my scripts for me Edit3: if anyone knows how, i think the script would work better usig a text file,, but i don't know how to use text files with my script yet, oh and 1 other thing, when the script works, feel free to use it...credit would be nice, but not required... Link to comment
Extremo Posted April 1, 2009 Share Posted April 1, 2009 I just noticed this: res = executeSQLInsert ( "playermail", "'" .. playerTo .. ",'" .. message .. "','" .. title .. "', '0', '" .. from .. "'" ) Basically you are missing a ' before the comma at playerTo, so i am guessing that thats the reason why it doesnt work. So, this is how it should be like: res = executeSQLInsert ( "playermail", "'" .. playerTo .. "','" .. message .. "','" .. title .. "', '0', '" .. from .. "'" ) I don't see a problem at your checkmail though , i am not playing mta that long but i've been working before with sql, dunno why it wont work Link to comment
Thehookerkiller01 Posted April 1, 2009 Share Posted April 1, 2009 (edited) And why should you make it? Edited June 30, 2010 by Guest Link to comment
cokacola Posted April 1, 2009 Author Share Posted April 1, 2009 if you mean why should i make the script, its because i cannot find any mail scripts or cop ticket scripts and i don't know why checkmail won't work eather... it wont even say "no mail found" or display the mail...it needs a killing Link to comment
50p Posted April 1, 2009 Share Posted April 1, 2009 First of all, I'd recommend you to check out GUI section on the wiki or my GUI classes and make send email form. Secondly, "Error: *pathtoscript*:266 attempting to concatenate global 'playerTo' " it means that your 'playerTo' variable is nil and you can't concatenate (join) it with string.Thirdly, I am passing all required parametersHow do you know? Make sure all required parameters are passed and that they are the types of data that is required, that is, where string shoulr be string make sure it's string not something else. That means, debug the script.Fourthly, visit wiki and see what parameters are passed to function called by commands (addCommandHandler). Last but not latest. What is source in function checkmail? source is not player! It's variable passed to function triggered by events! Also, the MOST important thing, DO NOT USE source AS AN ARGUMENT IN FUNCTIONS! Link to comment
cokacola Posted April 2, 2009 Author Share Posted April 2, 2009 so source......... that would make a hell of a lot of sense and i know i am passing parameters because i am using other scripts i made and i am pretty shore i am so what is a player function.. because i thought i saw the wiki using source for players ^.^ Edit: this is what i have so far: --Player mail system function createSQLOnStart () -- create our table, if it doesn't already exist executeSQLCreateTable ( "playermail", "playerto TEXT, mailmessage TEXT, mailsubject TEXT, mailread TEXT, mailfrom TEXT" ) end addEventHandler ( "onResourceStart", getResourceRootElement(getThisResource()),createSQLOnStart ) function sendMail (sourcePlayer, command, plrToName, title, message ) playerTo = getPlayerFromNick( plrToName ) plrTo = playerTo plrTitle = title plrMessage = message res = executeSQLInsert ( "playermail", "'" .. playerTo .. ",'" .. plrMessage .. "','" .. plrTitle .. "', '0'" ) if ( res ) then outputChatBox ("Mail Sent", source) else outputChatBox ("Failed to send mail", source) end end addCommandHandler("sendmail", sendMail) function checkmail (sourcePlayer) sourcename = getPlayerFromNick( sourcePlayer ) result = executeSQLSelect ( "playermail", "playerto", "mailmessage", "mailtitle", "mailread", "playerto = '" .. sourceName .. "', mailread = '1'" ) if ( result == false ) then outputChatBox ( "No new mail found", playerTo ) else outputChatBox ( "New Mail Found, Subject: " .. result[1][3], thePlayer ) outputChatBox ( "Message: " .. result[1][2], thePlayer ) outputChatBox ( "From: " .. result[1][5], thePlayer ) executeSqlUpdate ( "playermail", "mailread = '1'", "playerto = '" .. thePlayer .. "', mailsubject = '" .. result[1][3] .. "', mailmessage = '" .. result[1][2] .. "'" ) end addCommandHandler("checkmail", checkmail) end /checkmail does nothing, and /sendmail [playername] [title] [message] gives an error: attempt to concatenate global 'playerTo' Link to comment
cokacola Posted April 4, 2009 Author Share Posted April 4, 2009 *bump* anyone got a clue what's wrong with this yet? as far as i can remember its returning no errors...i didn't try doing it in XML because its too confusing.. but i cannot make it work and i think its SQL related Link to comment
Lordy Posted April 4, 2009 Share Posted April 4, 2009 It's not sql related. A hint this time would sound like this: You can only join(concatenate) strings and you can only store strings in SQL. Moreover, getPlayerFromNick returns a player element. Since this is not the first time this mistake for you (string - element confuzzlement) you should read wiki about the entity/element system and lua wiki about userdata. ALWAYS if you have an error, try to debug it yourself. If you just keep coming back here with obvious mistakes, you will start getting less and less help. Also you can join #mta.scripting at gtanet irc if you have already tried to solve a bug but failed numerous times. /me thinks of writing a debugging tutorial (better than the wiki one, since noone follows that one anyway, just come here) Ah also, please take a look at debugging tutorial at wiki. Link to comment
cokacola Posted April 4, 2009 Author Share Posted April 4, 2009 okay thanks i think i figured out how to debug the other night.. /debugscript 3 but it only shows me what i see in the console Link to comment
Thehookerkiller01 Posted April 5, 2009 Share Posted April 5, 2009 okay thanks i think i figured out how to debug the other night.. /debugscript 3 but it only shows me what i see in the console Debugscript 3 means in client that you see errors in the console also ingame. Debugscript 2 means in client that you see only other errors. Type '/debugscript help' in client Link to comment
Lordy Posted April 5, 2009 Share Posted April 5, 2009 IIRC server only outputs errors. Debugscript outputs also warnings and info. MTA features a built-in debug console that shows debug messages output from MTA functions or from scripts. You can open it by typing debugscript x in console, while x is the debug level: * 1: only errors * 2: errors and warnings * 3: errors, warnings and info messages Thus, by typing debugscript 3 all messages are visible, that or level 2 are recommended for most occasions. You should have debugscript enabled most of the time you are testing your scripts, this will help you detect typos or other simple issues and solve them easily. While info messages can be omitted, warnings also mean that some part of your code is not working. Link to comment
robhol Posted April 5, 2009 Share Posted April 5, 2009 No, server log also outputs warnings and info, but only server-side ones. That's why debugscript is indispensable when making client-side scripts: you'd be flying blind otherwise. Link to comment
JohnDoe91286 Posted April 26, 2009 Share Posted April 26, 2009 Well Admin resource has a message system for Administrators. Exept I dont understand how to compose messagses. Link to comment
robhol Posted April 26, 2009 Share Posted April 26, 2009 That's the report system. You/players can use it with /report. Link to comment
Luke_Ferrara Posted November 20, 2009 Share Posted November 20, 2009 BUMP I know this is old haha but I would like to know if anyone found a solution Link to comment
cokacola Posted November 21, 2009 Author Share Posted November 21, 2009 yes, actually, i remade it using mysql and a GUI. i never managed to get the default sql functions to work for me though ^.^ Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now