[Tutorial] Post to your vBulletin forum using an in-game function
#1

This takes quite a bit of setting up, but could be useful nonetheless.
I for one have /report post details on my forum so I can keep track of what's happening when not in-game.

First you need a webhost with a vBulletin forum (I haven't had chance to figure out for SMF/phpBB yet, sorry!). Create a .php file called 'post_from_ingame.php' containing what's below and place it in your forum root directory (usually something like /forum/)

PHP Code:
<?php
    date_default_timezone_set 
("Europe/Amsterdam"); // Server time
    
require './global.php';
    require 
'./includes/class_dm.php';
    require 
'./includes/class_dm_threadpost.php';
    require 
'./includes/functions_databuild.php';
    
$threaddm = new vB_DataManager_Thread_FirstPost($vbulletinERRTYPE_STANDARD);
    
$post_userid 0// Guest
    
$userid 0// No user
    
$user_name $_POST['name'] . ' (SA-MP)';
    
$allow_smilie '1';
    
$visible '1';
    
    
$forum_id = !!!!!CHANGE_ME!!!!!; // Set the board id here. For example, my 'report discussions' board is ID 28, so I'd put 28. forum/forumdisplay.php?28-Report-discussion (28 is the ID)
    
    //Thread post formatting
    
$post_text = (string)strip_tags('In-game name:[indent]    ' $_POST['name'] .'[/indent]    
    Server time:[indent]    ' 
strftime("%l:%M:%S %p") . '    [/indent]    
    Explanation:[indent]' 
. (string)strip_tags($_POST['posttext']) . '[/indent]');
    
//$_POST['posttext'] - posttext is what is sent in-game
    //format(string, sizeof(string), "name=%s&posttext=%s", name, params);
    
    //Thread title formatting
    //$title = 'New post from in-game';
    
$title '[' strftime("%H:%M:%S") . '] Report from ' $_POST['name'];
    
$threaddm->do_set('forumid'$forum_id);
    
$threaddm->do_set('postuserid'$post_userid);
    
$threaddm->do_set('userid'$userid);
    
$threaddm->do_set('username'$user_name);
    
$threaddm->do_set('pagetext'$post_text);
    
$threaddm->do_set('title'$title);
    
$threaddm->do_set('allowsmilie'$allow_smilie);
    
$threaddm->do_set('visible'$visible);
    
$threaddm->save();
    
build_forum_counters($forum_id);
    
    die(
"Report posted!");
?>
pawn Code:
#include a_http
Add this to your script under any function you wish to use; I used dcmd:
pawn Code:
new string[128];
new name[32];
GetPlayerName(playerid, name, 32);
format(string, sizeof(string), "name=%s&posttext=%s", name, params);
HTTP(playerid, HTTP_POST, "link-to-post_from_ingame.php-file", string, "MyHTMLError");
If you want to change what is sent to the forum, you can change format(string, sizeof(string), "name=%s&posttext=%s", name, params);. For example:
pawn Code:
if(Kills[playerid] == 500) format(string, sizeof(string), "name=%s&kills=%d", name, Kills[playerid]);
If you do customise it, be sure to edit the post_from_ingame.php file:
PHP Code:
$post_text = (string)strip_tags('$_POST['name'] . ' just got 500 kills! 
Well done to him!'
); // Thread post
$title '[' strftime("%H:%M:%S") . '] - ' $_POST['name'] . ' just got 500 kills!'// Thread title 
Be sure to change the link-to-post_from_ingame.php-file part!
(My example would be domain.com/forum/post_from_ingame.php - you don't need the preceding http://)

And the MyHTMLError function:

pawn Code:
forward MyHTMLError(index, response_code, data[]);
public MyHTMLError(index, response_code, data[])
{
    new
        buffer[ 128 ];
    if(response_code == 200) //Did the request succeed?
    {
        //Yes!
        format(buffer, sizeof(buffer), "%s", data);
        SendClientMessage(index, 0xFFFFFFFF, buffer);
    }
}
die("Report posted!"); in the PHP file will send "Report posted!" to the game server, which will then be formatted as 'buffer' and sent to index (the player).

Edit config.php in /forum_root/includes and add this to the bottom:
PHP Code:
define('SKIP_REFERRER_CHECK'true); 
And now simply execute your function and voila!

Preview of my script:
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)