Jump to content

[help]server mail system


cokacola

Recommended Posts

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

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 :x, i am not playing mta that long but i've been working before with sql, dunno why it wont work :x

Link to comment

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 parameters
How 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

so source.........

that would make a hell of a lot of sense :P

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

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

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
  • 3 weeks later...
  • 6 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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