Be a Supporter!
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
AS: Scoreboard Aug. 26th, 2005 @ 05:24 PM Reply

AS: Main

This is a basic tutoarial using the following:

PHP
MySQL
Flash ActionScript

This is mainly an ActionScript tutorial, the PHP and MySQL part is minimized to "copy and paste"

Stages

1)Getting a server
2)Setting the files and writing them
3)Setting the actionscript

WARNING: This scoreboard tutorial will produce a working but hackable scoreboard, you'll need to protect it better if you want it practically used , I might write a follow up tutorial or I might get Denvish to :P

Getting a server
The first thing you need to do is get a server that supports both PHP and MySQL there are plenty of free servers providing these services and you shouldn't care about ADs since you aren't using the pages themselves (you're loading them directly to flash), if you want to get something professional you should get a payed server, 3qhost are fair and trustworthy (I used them twice) and apthosting are pretty good too.

Setting the script

This script will include 1 php file and 1 sql table, let's start with the tricky sql part, your host should have some form of SQL access (preferable CPanel with PhpMyAdmin which is best to use). connect to your SQL (as provided) and create a new scores table:

CREATE TABLE `scores` ( `name` VARCHAR( 30 ) NOT NULL , `score` INT NOT NULL , `id` INT NOT NULL AUTO_INCREMENT , PRIMARY KEY ( `id` ) );

basically I created a table with a place for names and a place for scores, names are limited to 30 chars but you can use more if you'd like

now make sure you have the sql connection script ready, it's

mysql_connect(<server>,<username><userpass
>);
select_db(<database name>);

create a new php file, name it highscores.php or something similar, and put the following script in it, costumizable parts have <>'s


<?
$action=$_POST['action'];
echo "returned=1";
echo $_POST['lolk'];
function spitScores($n){
$result=mysql_query("SELECT * FROM `scores` WHERE 1 ORDER BY `score` DESC");
for($i=0;$i<10;$i++){
$row = mysql_fetch_array($result, MYSQL_BOTH);
echo "&row" . $i . "=" . $row['name'] . "&score" . $i . "=" . $row['score'];
}
}
function insertScore($name,$value){
if($value<100000){
mysql_query("INSERT INTO `scores` ( `name` , `score` , `id` ) VALUES ('$name', '$value', '');");
}
}
function clearDB(){
mysql_query("DELETE * FROM 'scores'");
}
if($action!=null){

mysql_connect(<server>,<username><userpass
>);
mysql_select_db(<database name>);

}else{
die ("I cannot find the action");
}
if($action=="view"){
spitScores(10);
}else if($action=="insert"){
$name=$_POST['name'];
$score=$_POST['score'];
$domain=$_POST['domain'];
//if(($domain=="http://www.gamesofgondor.c
om") || ($domain=="http://uploads.ungrounded.net")
){
insertScore($name,$score);
// }else{
// echo "Stop trying to cheat the system";
// }
}else if($action=="clear"){
$pass=$_POST['password'];
if($pass=="<myclearpasshere(give it to noone)>"){
clearDB();
}

}else{
"Please don't hack this, if scoring high REALLY means that much to you just email us and we'll give you a highscore, just don't be such a godamn lamer and ruin someone's hard work" ;
}
?>

once you have this code you're pretty much set, all you have to do is fetch the scores from flash...

you'll notice you have a domain check with a remark bound before it at a point, you can unremark it and alter it as you need

The Actionscript

You have 3 actions in this scoreboard script, view insert and clear, you only need to mess with view and insert, for example to insert a score you can do

action="insert";
name="Inglor"
score=2000;
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");

to view the scores you need to do
action="view";
loadVariablesNum("www.site.suffix/path/hig
hscores.php",1,"POST");

Again, this script is not secure, only use it for education and learning how highscores work, the view action loads the variables into _level1, toy with it to check the format, it loads 10 scores (configurable)

enjoy!

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:27 PM Reply

Cool. I've not used PHP much, but I wrote a tut for a Flash/ASP scoreboard (with sample files) here. I will come back and offer some tips for preventing hacking at a later date.


- - Flash - Music - Images - -

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:27 PM Reply

google it, it's free

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:28 PM Reply

Great work! Too bad so many people are desperate for highscores though >:-(


BBS Signature
Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:30 PM Reply

Oh, and also check out AS: Load External Data/Cross-Domain for information about using cross-domain scoreboards. If you're planning on using a scoreboard in a Flash submitted to NG, it WON'T WORK unless you sort out the crossdomain.xml on the database domain.


- - Flash - Music - Images - -

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:33 PM Reply

At 8/26/05 05:27 PM, Denvish wrote: Cool. I've not used PHP much, but I wrote a tut for a Flash/ASP scoreboard

that's cute but ASP is dead :P

GeoKureli
GeoKureli
  • Member since: Apr. 1, 2003
  • Offline.
Forum Stats
Supporter
Level 19
Game Developer
Response to AS: Scoreboard Aug. 26th, 2005 @ 05:38 PM Reply

too bad i cant put php on freewebs. cuz i reeeeeaaly want to learn xml server crap with flash.

Zielak
Zielak
  • Member since: Sep. 21, 2005
  • Offline.
Forum Stats
Member
Level 17
Game Developer
Response to AS: Scoreboard Mar. 31st, 2006 @ 12:57 PM Reply

At 8/26/05 05:38 PM, ImpotentBoy2 wrote: too bad i cant put php on freewebs. cuz i reeeeeaaly want to learn xml server crap with flash.

go on [=Arroways!=] ^^

caseyo
caseyo
  • Member since: May. 14, 2005
  • Offline.
Forum Stats
Member
Level 23
Blank Slate
Response to AS: Scoreboard Mar. 31st, 2006 @ 01:03 PM Reply

At 3/31/06 12:57 PM, Zielak wrote: go on [=Arroways!=] ^^

I bet he found a solution, that was like 7 monthes ago. :p

CabritoGoat
CabritoGoat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Scoreboard Apr. 30th, 2006 @ 10:36 AM Reply

Doesn’t work.

Database remains empty after i press the button with the code, even in its original form.

CabritoGoat
CabritoGoat
  • Member since: Jun. 5, 2004
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Scoreboard Apr. 30th, 2006 @ 01:24 PM Reply

I used the php code from some other tutorial and used Inglor’s AS. It now submits the score but the username is: _level0.post or undefined. So how do I fix this?

I have tried many methods and this is the last one:

on (release){
action= "insert";
userName = _parent.post_game.player_name;
myScore = _root.total_score;
loadVariablesNum("addScore.php",1,"POST");
}

“player_name” is the instance name of the player name input. “post_game” is the MC where the input box and the “send score” button resides.

Any suggestions?

EclipseNine
EclipseNine
  • Member since: Feb. 20, 2003
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Scoreboard May. 30th, 2006 @ 09:35 PM Reply

alright, lets say that i have 20 dynamic text boxes, 10 named "name0" through "name9" the other ten "score0" though "score9" how do i take the data from the php file, and make the scores and names display in their desired text boxes?

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Scoreboard Jan. 15th, 2007 @ 03:12 AM Reply

http://www.armorbot.com

you all get redeemed for free

Bezman
Bezman
  • Member since: Aug. 16, 2001
  • Offline.
Forum Stats
Member
Level 29
Melancholy
Response to AS: Scoreboard Jan. 15th, 2007 @ 07:38 AM Reply

At 1/15/07 03:12 AM, Inglor wrote: http://www.armorbot.com

you all get redeemed for free

Only those using MX+ :(

ShooterMG
ShooterMG
  • Member since: Nov. 10, 2006
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to AS: Scoreboard Jun. 27th, 2007 @ 02:50 AM Reply

At 5/30/06 09:35 PM, EclipseNine wrote: alright, lets say that i have 20 dynamic text boxes, 10 named "name0" through "name9" the other ten "score0" though "score9" how do i take the data from the php file, and make the scores and names display in their desired text boxes?

Why the heck did this never get answered?