Raised This Month: $ Target: $400
 0% 

[L4D] PounceRecord 1.1


Post New Thread Reply   
 
Thread Tools Display Modes
Guinn
Junior Member
Join Date: Sep 2009
Old 09-09-2009 , 02:33   Re: [L4D] PounceRecord 1.1
Reply With Quote #71

hi. two questions.

can someone help me with the utf8 charset encoding? my sql dbase is set for utf8 and i added the below from n0limits post and i am still not collecting the data correctly.

Code:
if(hDb == INVALID_HANDLE)
            LogError("Unable to connect to the specified host for the database configuration named %s.",configName);
        else
            SQL_TQuery(hDb,SqlPounceCallback,"SET NAMES 'utf8'");
also


this may not be the place to ask, but i am anyways . i made it so that the Top 10 would show in-game for 8 seconds or a player could type /pounce for the Top 10 as seen below. is there anyway to format the output so that there is set min/max characters per field? therefore it would look more like:



you can see it in action at 8.9.9.62:27015

thank you!



Last edited by Guinn; 09-09-2009 at 06:16.
Guinn is offline
n0limit
Senior Member
Join Date: May 2009
Old 09-09-2009 , 13:01   Re: [L4D] PounceRecord 1.1
Reply With Quote #72

Quote:
Originally Posted by Guinn View Post
hi. two questions.

can someone help me with the utf8 charset encoding? my sql dbase is set for utf8 and i added the below from n0limits post and i am still not collecting the data correctly.
The plugin should try to set it to utf8 already, but I've seen it have problems depending on the db. Is it giving an error? Try running it in mysqladmin and check the result.

Quote:
Originally Posted by Guinn View Post
this may not be the place to ask, but i am anyways . i made it so that the Top 10 would show in-game for 8 seconds or a player could type /pounce for the Top 10 as seen below. is there anyway to format the output so that there is set min/max characters per field? therefore it would look more like:



you can see it in action at 8.9.9.62:27015

thank you!
Quite cool, I was hoping to one day write this but I've just been swamped. Are you planning on posting the code?

To answer your question, you need to figure out your largest field width, and then use the syntax
%#s, with # being the field width.
For an example, %32s, and it will pad the rest with spaces. You may have to use %-32s if it's justifying on the wrong side.
If you get stuck, http://wiki.alliedmods.net/Format_Cl...d_Scripting%29 is good reading.
n0limit is offline
Guinn
Junior Member
Join Date: Sep 2009
Old 09-09-2009 , 17:10   Re: [L4D] PounceRecord 1.1
Reply With Quote #73

I tried the formatting and couldn't get it to line up. It added spacing, but was still off. Maybe someone else can help. Below is what I added to mine. This was the first code I have ever tried so it probably looks bad. I just looked at other codes (specifically msleepers) and did trial and error to get to work.

Compile the below as a separate plugin. The stats show automatically after the player is in the server for 100 seconds. They can also type !pounce in chat.

Code:
#include <sourcemod>

#define PLUGIN_VERSION "1.0"
//globals

#define MAX_LINE_WIDTH 150

new Handle:hDb;

public Plugin:myinfo = 
{
    name = "Top10Pounces",
    author = "Guinn",
    description = "Shows Hunter Pounce Records. Works aside pouncerecord.",
    version = PLUGIN_VERSION,
    url = ""
}

public OnPluginStart()
{

    ConnectToDB("PounceDB");
    if(hDb == INVALID_HANDLE)
        return; //Don't setup the system if the DB is non responsive.
    
    RegConsoleCmd("sm_pounce", cmd_Top10Pounce);
}

public ConnectToDB(const String:configName[])
{
    new String:errorMsg[256];
    
    if(SQL_CheckConfig(configName))
    { //config section exists
        hDb = SQL_Connect(configName,true,errorMsg,sizeof(errorMsg));
        if(hDb == INVALID_HANDLE)
            LogError("Unable to connect to the specified host for the database configuration named %s.",configName);
        else
            SendSQLUpdate("SET NAMES 'utf8'");

    }
    else
        LogError("The database configuration name %s was not present in the databases.cfg file.",configName);
    
}

public SendSQLUpdate(String:query[])
{
    if (hDb == INVALID_HANDLE)
        return;

    SQL_TQuery(hDb, SQLErrorCheckCallback, query);
}

public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if (hDb == INVALID_HANDLE)
        return;

    if(!StrEqual("", error))
        LogError("SQL Error: %s", error);
}

public OnClientPutInServer(client)
{
    if (IsFakeClient(client))
    return;

    if (client)
    CreateTimer(100.0, JustJoined, client);
}

public Action:JustJoined(Handle:timer, any:client)
{
       if (IsFakeClient(client))
        return;

    if (client)
        FakeClientCommand(client, "sm_pounce");
}


// Generate the TOP 10 Pounce Records display panel.
public Action:cmd_Top10Pounce(client, args)
{
decl String:query[256];
Format(query, sizeof(query), "SELECT pouncer, damage, distance FROM pounces ORDER BY damage DESC LIMIT 10");
SQL_TQuery(hDb, Top10pounces, query, client);
    
return Plugin_Handled;
}

// Send the TOP 10 Pounce Records to the client's display.
public Top10pounces(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    new client = data;

    if (!client || hndl == INVALID_HANDLE)
        return;

    new String:pouncer[MAX_NAME_LENGTH];
    new damage,distance

        new Handle:Top10PouncePanel = CreatePanel();
        SetPanelTitle(Top10PouncePanel, "---------------------Top 10 Pounces---------------------");
        DrawPanelText(Top10PouncePanel, "          ");

        while (SQL_FetchRow(hndl))
        {
            SQL_FetchString(hndl, 0, pouncer, sizeof(pouncer));
            ReplaceString(pouncer, sizeof(pouncer), "&lt;", "<");
            ReplaceString(pouncer, sizeof(pouncer), "&gt;", ">");
            ReplaceString(pouncer, sizeof(pouncer), "%", "%");
            ReplaceString(pouncer, sizeof(pouncer), "=", "=");
            ReplaceString(pouncer, sizeof(pouncer), "*", "*");

            damage = SQL_FetchInt(hndl, 1);
            distance = SQL_FetchInt(hndl, 2);
 
           new String:Value[MAX_LINE_WIDTH];

       Format(Value, sizeof(Value), "%s %s %s %i %s %i %s", "-", pouncer, "gave", damage, "damage at", distance /16, "ft");
           DrawPanelText(Top10PouncePanel, Value);
        }
            
        SendPanelToClient(Top10PouncePanel, client, Top10PanelHandler, 5);
        CloseHandle(Top10PouncePanel);
}
    
    
// Handler for Top 10 Pounce panel.
public Top10PanelHandler(Handle:menu, MenuAction:action, param1, param2)
{
}

Last edited by Guinn; 09-21-2009 at 08:11.
Guinn is offline
eRazorzEDGE
Junior Member
Join Date: Jul 2009
Old 09-13-2009 , 22:12   Re: [L4D] PounceRecord 1.1
Reply With Quote #74

Quote:
Originally Posted by LosTZealoT View Post
I recent helped a friend who owns a server and use this plugin with a small thing in terms of the web interface. He wanted to have the website display ALL pounces, using pages much like a forum uses in displaying threads. I thought this would be cool too, so I wrote up some code and made it work. He was using crazydog's version of the web interface, with the search and all, so I did some tinkering with that. I'm not sure how much this feature is in demand, but I though it would be nice to share anyway.

There is quite a bit of code to be added to a few files to add this function, so it is somewhat impractical to give you the modifications. Most of the files here shouldn't be one's you've done too much customizing, except template.tpl. For that file, here is the most important custom code to modify:

Find:
PHP Code:
<?php include("./parse.php")?>
                </table>
                </div>
Add below it:
PHP Code:
<div align="right">
<?php 
$pagedoubledown 
$pagenumber-2;
$pagedown $pagenumber-1;
$pageup $pagenumber+1;
$pagedoubleup $pagenumber+2;

if (
$searchterm == "Player Name")
{
$searchtemp "";
}
else
{
$searchtemp $searchterm;
}

echo 
'<b><a href="index.php?pg=1&search=' $searchtemp '&type=' $searchtype '">&lt;&lt;</a> ';
if (
$pagedown>=1)
{
echo 
'<a href="index.php?pg=' $pagedown '&search=' $searchtemp '&type=' $searchtype '">&lt;</a> ';
}
else
{
echo 
'<a href="index.php?pg=1&search=' $searchtemp '&type=' $searchtype '">&lt;</a> ';
}

if (
$pagenumber>3)
{
echo 
'<a href="index.php?pg=1&search=' $searchtemp '&type=' $searchtype '">1</a> ... ';
}

if (
$pagedoubledown>=1)
{
echo 
'<a href="index.php?pg=' $pagedoubledown '&search=' $searchtemp '&type=' $searchtype '">' $pagedoubledown '</a> ';
}
if (
$pagedown>=1)
{
echo 
'<a href="index.php?pg=' $pagedown '&search=' $searchtemp '&type=' $searchtype '">' $pagedown '</a> ';
}

echo 
'<i>' $pagenumber '</i> ';

if (
$pageup<=$pagetotal)
{
echo 
'<a href="index.php?pg=' $pageup '&search=' $searchtemp '&type=' $searchtype '">' $pageup '</a> ';
}
if (
$pagedoubleup<=$pagetotal)
{
echo 
'<a href="index.php?pg=' $pagedoubleup '&search=' $searchtemp '&type=' $searchtype '">' $pagedoubleup '</a> ';
}

if (
$pagenumber<($pagetotal-2))
{
echo 
'... <a href="index.php?pg=' $pagetotal '&search=' $searchtemp '&type=' $searchtype '">' $pagetotal '</a> ';
}

if (
$pageup<=$pagetotal)
{
echo 
'<a href="index.php?pg=' $pageup '&search=' $searchtemp '&type=' $searchtype '">&gt;</a> ';
}
else
{
echo 
'<a href="index.php?pg=' $pagetotal '&search=' $searchtemp '&type=' $searchtype '">&gt;</a> ';
}
echo 
'<b><a href="index.php?pg=' $pagetotal '&search=' $searchtemp '&type=' $searchtype '">&gt;&gt;</a></b> ';

?>
</div>
<div align="center">
            <?php if($distanceformat == 1)
                    {
                    echo 
"Distance displayed in game units. \n";
                    }
            elseif(
$distanceformat == 2)
                   {
                    
$distance = ($distance 16);
                    echo 
"Distance displayed in feet. \n";
                    }
            elseif(
$distanceformat == 3)
                   {
                   
$distance = ($distance 0.0213);
                   echo 
"Distance displayed in meters. \n";
                   }
?>
                        
            </div>
            <br>
<div align="center">
Displaying <?=number_format($listings);?> pounces out of a total of <?=$playercount;?> pounces in the database for <?php if(!isset($searchtype)){echo'everyone';}else{echo'players matching term: '.$searchterm;}?>.
</div>
Remove from page:
PHP Code:
Displaying the top <?=number_format($displaynumber);?> pounces out of a total of <?=$playercount;?> pounces in the database.
That line, telling you how many pounces are being displayed and how many are in the database, is modified in my version and moved.

Modify(Find the line that creates the "Back to all pounce" link and add "index.php" to the href:
PHP Code:
<?php if(isset($searchtype)){echo'<a href="">Back to all pounces</a><br>';}?>

--to-->

<?php if(isset($searchtype)){echo'<a href="index.php">Back to all pounces</a><br>';}?>
If there seem to be any errors or problems, please tell me!

(In the zip file below are just the files that I modified, NOT all the files required for this plugin)
firstly, thank you for this. very useful.

secondly, a couple minor code errors in a couple files that i've corrected. i'm not a coder, but i know some of the basics, so forgive me if it's not perfect. here's what i did:

CONNECT.PHP

WAS:
PHP Code:
elseif($pagenumber == $pagetotal)
     
$displaynumber $listings $maxplayers


SHOULD BE:

PHP Code:
else
if(
$pagenumber == $pagetotal)
     
$displaynumber $listings $maxplayers
TEMPLATE.TPL

WAS:
PHP Code:
Displaying <?=number_format($listings);?>
SHOULD BE:
PHP Code:
Displaying <?=number_format($displaynumber);?>
the template.tpl error basically displayed number of all the pounces in the database instead of just that displayed on each page and i forget what the connect.php fix did :p
eRazorzEDGE is offline
Guinn
Junior Member
Join Date: Sep 2009
Old 09-19-2009 , 17:01   UTF-8 Help!
Reply With Quote #75

I have been working on UTF-8 again today. I finally got it working right. Just incase others have been fighting with it below is what I did. Now the names are showing up correctly through web and when I run my Top 10 pounce records within game.

I was having errors when creating the table with "ENGINE=MyISAM AUTO_INCREMENT=243 DEFAULT CHARSET=utf8;". I think it is just my web server. I was ecstatic when the below worked.
Code:
CREATE TABLE IF NOT EXISTS `pounces` (
  `ID` int(10) unsigned NOT NULL auto_increment,
  `datetime` datetime NOT NULL,
  `pouncer` varchar(255) character set utf8 collate utf8_general_ci not null,
  `pounced` varchar(255) character set utf8 collate utf8_general_ci not null,
  `distance` smallint(5) unsigned NOT NULL,
  `damage` float NOT NULL,
  `map` varchar(64) NOT NULL,
  `steamid` varchar(64) NOT NULL,
  PRIMARY KEY  (`ID`)
)
I added the below to pouncerecord
Code:
        
// AFTER
        if(hDb == INVALID_HANDLE)
            LogError("Unable to connect to the specified host for the database configuration named %s.",configName);

// I ADDED

            else
            SendSQLUpdate("SET NAMES 'utf8'");
Than I added

Code:
public SendSQLUpdate(String:query[])
{
    if (hDb == INVALID_HANDLE)
        return;

    SQL_TQuery(hDb, SQLErrorCheckCallback, query);
}

public SQLErrorCheckCallback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if (hDb == INVALID_HANDLE)
        return;

    if(!StrEqual("", error))
        LogError("SQL Error: %s", error);
}
Guinn is offline
LosTZealoT
New Member
Join Date: Aug 2009
Old 09-22-2009 , 22:52   Re: [L4D] PounceRecord 1.1
Reply With Quote #76

Thanks for the compliment, and I understand why one might think those lines are at fault. But neither are.

The first is not error. elseif is a valid php statement. However, I did make a math error. That line should be:
PHP Code:
elseif($pagenumber == $pagetotal && $listings%$maxplayers != 0)
     
$displaynumber $listings $maxplayers
(If the search or display is a perfect division of the displaynumber, the last page would not show. $listings % $maxplayers == 0!!}

The second is really a matter of preference. $displaynumber will be max that fix on a page, so if there are multiple pages, the total number of values will be a mystery because using $displaynumber will simply be number per page. Using $listings, it displays all that are being displayed on all pages in total. It really does not matter, just what I thought would be most useful.
LosTZealoT is offline
eRazorzEDGE
Junior Member
Join Date: Jul 2009
Old 09-25-2009 , 00:23   Re: [L4D] PounceRecord 1.1
Reply With Quote #77

ahh. well on the "elseif" i was just going off of what was in the other "elseif" statement in that file, right before this one. it was formatted like i've shown. i just thought that it being together wouldn't work properly.

yeah, when it was set to $listings, it would say "Displaying 140 pounces out of 140 pounces total in the database.", no matter how many pounces were on the current page. again, i thought that's what you trying to do, but obviously i suck at assumptions :p
eRazorzEDGE is offline
Dream
Junior Member
Join Date: Aug 2009
Old 09-25-2009 , 14:19   Re: [L4D] PounceRecord 1.1
Reply With Quote #78

My server provider is GameServers. I've uploaded the plugin to my server, and all of the PHP pack files to the website I have them with as well. I've read through the topic and made changes accordingly. However I still have not been able to get everything to work. I'm getting SQL errors on my main page here: http://www.terror.clanservers.com/pounces/index.php

Also, after installing the plugin and setting up the web pages, I had someone start a game. I monitored the server console and saw no errors, but no pounce records have been added to the database, so I am not sure what it is I didn't do correctly.

The only thing I could think of was that the plugin config file was pointing to the wrong database (which I have set to localhost). I figured this was correct since my server and website are both provided by GameServers. Nothing else has worked though (site url, host IP). Is there anyone who uses GameServers that can point me in the right direction?

Also, in regards to UTF-8 character encoding. MyPHPadmin says that MySQL charset is set to UTF-8 Unicode. I've also ran the CHARSET utf8 query in the SQL database. My question is, which document do I need to change in order for my PHP file to output in utf8 as well?

Any help is much appreciated.

EDIT: GameServers support has confirmed that my database hostname is localhost. I've created each database with a username and password. This still doesn't work. I've tried it while installing the MyBB forum on my website and it did not work either.
__________________

Last edited by Dream; 09-25-2009 at 15:24.
Dream is offline
LosTZealoT
New Member
Join Date: Aug 2009
Old 09-25-2009 , 15:45   Re: [L4D] PounceRecord 1.1
Reply With Quote #79

To Dream:
Well, if both MyBB and this plugin are having trouble writing to the database, it could be that you improperly entered the login information for the database or didn't set it up right. I haven't done much with GameServers, but it could be one of these:

In the given config files of MyBB and this plugin, the data for $dbname, $dbuser, and $dbpass were not entered correctly. $dbname. Make sure you know the full name of the database and full username; cPanel usually adds your cPanel username to the database name and username. For example, a database called mybb would become lostzealot_mybb if my username for the cPanel was lostzealot. Same for the username.

It could also be that you've not bond the user and the database. The user must be given read/write permissions to the database. If it isn't, the user can't enter data, thus causing the problem.

I am honestly not sure as I'm not familiar with GameServers, but these two are common mistakes for setting up PHP&MySQL sites. I sometimes make them, they can be easy to overlook.

To eRazor:
You're right in that if the config it set up right, it will merely display 140 out of 140. However, it is not always the case. Filters and searched change that number. Here's who I originally made the mod for, this site a working example of my mod:

http://fs-gaming.clanservers.com/
LosTZealoT is offline
d4ve
Junior Member
Join Date: Aug 2009
Old 09-27-2009 , 07:43   Re: [L4D] PounceRecord 1.1
Reply With Quote #80

DREAM
im using clanservers i to had the same problem getting mine to connect an display the data i found i needed to add a remote connection .

i achieved this by going to my cpanel an going into mysql database at the bottom there is your Access Hosts
you need to add %



i hope this helps
d4ve is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 02:39.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode