Author Topic: Send automated PM?  (Read 8321 times)

Offline Ecko

Send automated PM?
« on: October 13, 2006, 06:28:06 am »
I am a complete neeb when it comes to coding. Can someone help me make an item that somewhat fits this description:

First you buy the item, then you use it. When you use it, I want it to randomly select from a list of phrases or words that have already been defined. Example:

+1 Attack
+1 Defense
+1 HP
-1 Attack
-1 Defense
-1 HP

So when you use this item, it selects one of those and then it tells them You've just gained/lost _____.

Then, as soon as they use it, it sends an automated PM to the Administration saying the exact same thing it says to the user.

Offline Basil Beard

Re: Send automated PM?
« Reply #1 on: October 13, 2006, 10:53:14 am »
Use the mt_rand() function with a switch statement to figgure out which case to use. Either that, or put it into an array and use the shuffle function. Then use the sendpm() function to send the PMs. Look on php helpsites and this site to figgure out just how to do that if you arn't sure =)
Arrrrr!

Offline Ecko

Re: Send automated PM?
« Reply #2 on: October 13, 2006, 10:56:25 am »
Check out my other post in your item creation guide.

I keep getting that error, and so far I've got it so that it it will randomly select a selection of words from a .txt file and tell it, but I also want it to PM that to an Admin and the User.

Offline Daniel15

Re: Send automated PM?
« Reply #3 on: October 13, 2006, 07:11:26 pm »
For sending PM's, my code is similar to:

$result 
db_query("SELECT money, memberName, realName
	
	
	
	
	
FROM 
{$db_prefix}members
	
	
	
	
	
WHERE ID_MEMBER = 
{$ID_MEMBER}
	
	
	
	
	
LIMIT 1"
__FILE____LINE__);

$row mysql_fetch_array($resultMYSQL_ASSOC);
$membersUserName $row['memberName'];
$membersName $row['realName'];

$pmfrom = array(
	
'id' => $ID_MEMBER,
	
'name' => $membersName,
	
'username' => $membersUserName
);
	
	

$pmto = array(
	
'to' => array(1),
	
'bcc' => array()
);
	
	

$subject "Subject of the message"
$message "Actual message goes here!";
sendpm($pmto$subject$message0$pmfrom);


This sends a message 'from' the user running the script, to the admin (ID = 1). Just change the '1' in array(1) to send the IM to a different user.

Offline Ecko

Re: Send automated PM?
« Reply #4 on: October 14, 2006, 04:43:01 am »
So if I had an item that displays a random quote or something and have it return( after the item has been used, I can also make it send that same message to myself and the person who used the item?

Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2005 DanSoft Australia           |
|      http://www.dansoftaustralia.com/        |
\**********************************************/

//File: FireScroll.php
//      Test Item (requires NO input)

//VERSION: 1.0 (Build 1)
//DATE: 12h October 2006
// $Id: FireScroll.php 3 2006-10-12 10:01:21Z eckostylez $

//your class should always be called item_filename, eg. if your file is 
//myCoolItem.php then the class should be called 'item_myCoolItem'. This 
//class should always extend itemTemplate.
class item_FireScroll extends itemTemplate {
    
    
//when this function is called, you should set all the item's
    //variables (see inside this example)
    
function getItemDetails() {

        
//VALUES CHANGABLE FROM WITHIN ADMIN PANEL:
          //the name of the item
          
$this->name "Firebending Scroll";
          
//the item's description
          
$this->desc "Learn a new attack! Or an old one...!";
          
//the item's price
          
$this->price 500;
          
        
//UNCHANGABLE VALUES:
          //whether the item requires input or not. In this case, we don't need
          //any input
          
$this->require_input false;
          
//set this to 'false' if the item is unusable. This is good for display
          //items.
          
$this->can_use_item true;
    }

    
//since this item requires no input, we don't need to have a getUseInput function
    //here (see the testitem2.php file if you want to make an item that needs input.


    //the is where all the fun begins. This function is called when 
    //the user actually uses the item. Return stuff, DON'T ECHO!
    
function onUse() {
         
$quotes = array('You learned Fire Kick - 3 DMG''You learned Flaming Punch - 2 DMG''You learned Lightning Strike - 5 DMG');
         return (
$quotes[rand(0count($quotes) -1)]);
 
    }
}


?>


After the function onUse() part is the array that holds the random "quotes" and then it returns it to them in the next box.

What would I add to make it send a PM to me and the person who used the item with the same message from the array?

Offline chougard

Re: Send automated PM?
« Reply #5 on: November 12, 2006, 12:24:32 am »
For sending PM's, my code is similar to:

$result 
db_query("SELECT money, memberName, realName
	
	
	
	
	
FROM 
{$db_prefix}members
	
	
	
	
	
WHERE ID_MEMBER = 
{$ID_MEMBER}
	
	
	
	
	
LIMIT 1"
__FILE____LINE__);

$row mysql_fetch_array($resultMYSQL_ASSOC);
$membersUserName $row['memberName'];
$membersName $row['realName'];

$pmfrom = array(
	
'id' => $ID_MEMBER,
	
'name' => $membersName,
	
'username' => $membersUserName
);
	
	

$pmto = array(
	
'to' => array(1),
	
'bcc' => array()
);
	
	

$subject "Subject of the message"
$message "Actual message goes here!";
sendpm($pmto$subject$message0$pmfrom);


This sends a message 'from' the user running the script, to the admin (ID = 1). Just change the '1' in array(1) to send the IM to a different user.
Could someone tell me how to make a item out of that code? When I copied an item code into a new file and replaced the codes with this, I was given an error.

Offline chinatown

Re: Send automated PM?
« Reply #6 on: November 17, 2006, 08:43:14 am »
For sending PM's, my code is similar to:

$result 
db_query("SELECT money, memberName, realName
	
	
	
	
	
FROM 
{$db_prefix}members
	
	
	
	
	
WHERE ID_MEMBER = 
{$ID_MEMBER}
	
	
	
	
	
LIMIT 1"
__FILE____LINE__);

$row mysql_fetch_array($resultMYSQL_ASSOC);
$membersUserName $row['memberName'];
$membersName $row['realName'];

$pmfrom = array(
	
'id' => $ID_MEMBER,
	
'name' => $membersName,
	
'username' => $membersUserName
);
	
	

$pmto = array(
	
'to' => array(1),
	
'bcc' => array()
);
	
	

$subject "Subject of the message"
$message "Actual message goes here!";
sendpm($pmto$subject$message0$pmfrom);


This sends a message 'from' the user running the script, to the admin (ID = 1). Just change the '1' in array(1) to send the IM to a different user.

whenever i try to use this code in my items. i get Parse error: syntax error, unexpected T_VARIABLE

anything i went wrong?

Offline feeble

Re: Send automated PM?
« Reply #7 on: November 17, 2006, 05:47:41 pm »
a small note for anyone wishing to use this. Let say the person installing this item write their own message from within the interface, or similar.

$subject = "Hi [name],[nl]You must be new here.[nl]Your password is [pass].";
$vreplacekeys = array('[name]', '[pass]', '[nl]');
$vreplaceto = array($username, $userpass, '
');

$subject  = str_replace($vreplacekeys , $vreplaceto , $subject);

$subject will now contain echo something like
Hi john,
You must be new here.
Your password is doe.

Offline Daniel15

Re: Send automated PM?
« Reply #8 on: November 17, 2006, 07:49:54 pm »
Quote
whenever i try to use this code in my items. i get Parse error: syntax error, unexpected T_VARIABLE

anything i went wrong?

There's a slight mistake in my code!
Find:

$subject 
"Subject of the message"

And add a semicolon to the end:

$subject 
"Subject of the message";


Quote
a small note for anyone wishing to use this. Let say the person installing this item write their own message from within the interface, or similar.

$subject = "Hi [name],[nl]You must be new here.[nl]Your password is [pass].";
$vreplacekeys = array('[name]', '[pass]', '[nl]');
$vreplaceto = array($username, $userpass, '
');

$subject  = str_replace($vreplacekeys , $vreplaceto , $subject);

$subject will now contain echo something like
Hi john,
You must be new here.
Your password is doe.
No need to do it like that ;)

$subject 
"Hi ".$username."\nYou must be new here.\nYour password is ".$userpass.".";


;)

Offline chougard

Re: Send automated PM?
« Reply #9 on: November 21, 2006, 10:21:27 am »
Here is the code I used to make the item.
Code: [Select]
<?php
/**********************************************\
| SMFSHOP (Shop MOD for Simple Machines Forum) |
|         (c) 2006 DanSoft Australia           |
|      http://www.dansoftaustralia.net/        |
\**********************************************/

//File: sendpm.php
//      Email the admin item

// VERSION: 2.3 (Build 11)
// $Date: 2006-10-21 13:34:18 +1000 (Sat, 21 Oct 2006) $
// $Id: EmailAdmin.php 24 2006-10-21 03:34:18Z daniel15 $

class item_sendpm extends itemTemplate {

    function 
getItemDetails() {
$this->authorName "Daniel15";
$this->authorWeb "http://www.dansoftaustralia.net/";
$this->authorEmail "dansoft@dansoftaustralia.net";

        
$this->name "Send PM to Admin v2";
        
$this->desc "Send off an PM to the admin. A good use for this (for a web host) is an 'Add 100MB of Webspace to your hosting account'";
        
$this->price 10;
    }
$result db_query("SELECT money, memberName, realName











FROM 
{$db_prefix}members











WHERE ID_MEMBER = 
{$ID_MEMBER}











LIMIT 1"
__FILE____LINE__);

$row mysql_fetch_array($resultMYSQL_ASSOC);
$membersUserName $row['memberName'];
$membersName $row['realName'];

$pmfrom = array(



'id' => $ID_MEMBER,



'name' => $membersName,



'username' => $membersUserName
);






$pmto = array(



'to' => array(1),



'bcc' => array()
);






$subject "Subject of the message";
$message "Actual message goes here!";
sendpm($pmto$subject$message0$pmfrom);
?>
It gives me
Parse error: syntax error, unexpected T_VARIABLE, expecting T_FUNCTION in /home/chougard/public_html/smf/Sources/shop/items/sendpm.php on line 26

Thanks for any help!

Offline chinatown

Re: Send automated PM?
« Reply #10 on: November 21, 2006, 11:32:10 am »
Quote
whenever i try to use this code in my items. i get Parse error: syntax error, unexpected T_VARIABLE

anything i went wrong?

There's a slight mistake in my code!
Find:

$subject 
"Subject of the message"

And add a semicolon to the end:

$subject 
"Subject of the message";


its working fine for me.. thanks..

Offline Daniel15

Re: Send automated PM?
« Reply #11 on: November 21, 2006, 09:22:26 pm »
chougard, all of your code needs to be in an onUse() function. Please see the example items (and the email an admin item) for more details.
(sorry I can't post more, It's 12:21AM here. I'll see if I can fix it tommorow)