• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

[PHP] Simple function easy to create new players

biel-kun

New Member
Joined
Sep 4, 2007
Messages
31
Reaction score
0
Please moderators, look this: May cannot be a correct section, please move this topic.

Only works with the Forgotten 0.2.6 release.

I will post a function on PHP made by me, to create new players(ps.: have another functions to assistant with MySQL connections, errors, and querys):
PHP:
<?
session_start();
error_reporting(0);
$_error_ = "";

function noteErr($err) {
	global $_error_;
	$_error_ .= '<span class="err">'.$err.'</span><BR>';
	return 0;
}

function showErr() {
	global $_error_;
	return $_error_;
}
function cn($db = 'otserv') {
	global $_error_;
	$cn = mysql_connect("localhost", "root", "secret") or noteErr("Falha ao conectar na DB");
	mysql_select_db($db, $cn) or noteErr("Falha ao selecionar DataBase");
	return $cn;
}

function query($txt, $ha) {
	$ret =& mysql_query($txt, $ha) or noteErr("Falha na query: ".mysql_error());
	return $ret;
}
function g_player($pElement) {
	if(is_numeric($pElement)) {
		$type = 'id';
	} else {
		$type = 'name';
	}	
	$player_q = query("SELECT * FROM players WHERE ".$type." = '".$pElement."'", cn());
	return mysql_fetch_object($player_q);
}
function createCharacter($namein, $acc_logged, $startlvl, $voc, $hp, $startexp, $maglvl, $mana, $town_id, $pos_x, $pos_y, $pos_z, $cap, $lk_body, $lk_feet, $lk_head, $lk_legs, $lk_type, $lk_addons, $soul, $sexin) {

	//query("INSERT INTO players(name, account_id, level, vocation, health, healthmax, experience, maglevel, mana, manamax, town_id, posx, posy, posz, conditions, cap, lookbody, lookfeet, lookhead, looklegs, looktype, lookaddons, soul, sex) values('$namein', '$acc_logged', '$startlvl', '$voc', '" .$hp. "', '" .$hp. "', '$startexp', '" .$maglvl. "', '" .$mana. "', '" .$mana. "', '" .$town_id. "', '".$pos_x."', '".$pos_y."', '".$pos_z."', '0', '" .$cap. "', '" .$lk_body. "', '" .$lk_feet. "', '" .$lk_head. "', '" .$lk_legs. "', '" .$lk_type. "', '" .$lk_addons. "', '" .$soul. "', '".$sexin."')", cn());
	// Query atualizada para Forgotten -> 0.2.6
	query("INSERT INTO `players` ( `id` , `name` , `group_id` , `account_id` , `level` , `vocation` , `health` , `healthmax` , `experience` , `lookbody` , `lookfeet` , `lookhead` , `looklegs` , `looktype` , `lookaddons` , `maglevel` , `mana` , `manamax` , `manaspent` , `soul` , `town_id` , `posx` , `posy` , `posz` , `conditions` , `cap` , `sex` , `lastlogin` , `lastip` , `save` , `redskull` , `redskulltime` , `rank_id` , `guildnick` , `lastlogout` , `blessings` , `direction` , `loss_experience` , `loss_mana` , `loss_skills` , `premend` )
VALUES ( NULL , '".$namein."', '0', '".$acc_logged."', '".$startlvl."', '".$voc."', '".$hp."', '".$hp."', '".$startexp."', '".$lk_body."', '".$lk_feet."', '".$lk_head."', '".$lk_legs."', '".$lk_type."', '".$lk_addons."', '".$maglvl."', '".$mana."', '".$mana."', '0', '".$soul."', '".$town_id."', '".$pos_x."', '".$pos_y."', '".$pos_z."', '', '".$cap."', '".$sexin."', '0', '0', '1', '0', '0', '0', '', '0', '0', '0', '10', '10', '10', '0')", cn());
	$playerid = g_player($namein)->id;
	
	//Creating Player Skills...
	$skills1 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','0','10','0')";
	$skills2 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','1','10','0')";
	$skills3 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','2','10','0')";
	$skills4 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','3','10','0')";
	$skills5 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','4','10','0')";
	$skills6 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','5','10','0')";
	$skills7 = "INSERT INTO player_skills(player_id, skillid, value, count) values('$playerid','6','10','0')";	
	query($skills1, cn());
	query($skills2, cn());
	query($skills3, cn());
	query($skills4, cn());
	query($skills5, cn());
	query($skills6, cn());
	query($skills7, cn());
	
	//Adding items into DataBase....              player_id, pid, sid, itemtype, count, attributes, writer, date
	$item1 = "INSERT INTO `player_items` VALUES (".$playerid.", 10, 108, 2120, 1, '')";
	$item2 = "INSERT INTO `player_items` VALUES (".$playerid.", 8, 107, 2643, 1, '')";
	$item3 = "INSERT INTO `player_items` VALUES (".$playerid.", 7, 106, 2478, 1, '')";
	$item4 = "INSERT INTO `player_items` VALUES (".$playerid.", 6, 105, 2412, 1, '')";
	$item5 = "INSERT INTO `player_items` VALUES (".$playerid.", 5, 104, 2530, 1, '')";
	$item6 = "INSERT INTO `player_items` VALUES (".$playerid.", 3, 102, 1988, 1, '')";
	$item7 = "INSERT INTO `player_items` VALUES (".$playerid.", 4, 103, 2483, 1, '')";
	$item8 = "INSERT INTO `player_items` VALUES (".$playerid.", 1, 101, 2457, 1, '')";
	$item9 = "INSERT INTO `player_items` VALUES (".$playerid.", 102, 109, 2580, 1, '')";
	$item10 = "INSERT INTO `player_items` VALUES (".$playerid.", 102, 110, 2152, 5, '')";	
	query($item1, cn());
	query($item2, cn());
	query($item3, cn());
	query($item4, cn());
	query($item5, cn());
	query($item6, cn());
	query($item7, cn());
	query($item8, cn());
	query($item9, cn());
	query($item10, cn());
}
?>

A example of use:
PHP:
<?
require 'functions.php'; // substitutes this for the file that you placed the functions above
//Getting the form fields...
$acc = $_POST['acc'];
$nome = $_POST['nome'];
$voc = $_POST['voc'];
$sex = $_POST['sex'];
$city = $_POST['city'];
//Listing all cityes and ur positions
$citys = array(
'1' => array('x' => '85', 'y' => '111', 'z' => '7'),
'2' => array('x' => '180', 'y' => '387', 'z' => '7'),
'3' => array('x' => '234', 'y' => '419', 'z' => '12'),
'4' => array('x' => '485', 'y' => '162', 'z' => '7'),
'5' => array('x' => '232', 'y' => '557', 'z' => '7')
);
if(isset($_GET['acc']) && isset($_GET['nome']) && isset($_GET['voc']) && isset($_GET['sex']) && is_numeric($city)) {
	createCharacter($nome, $acc, "8", $voc, "185", "4200", "0", "35", $city, $citys[$city]['x'], $citys[$city]['y'], $citys[$city]['z'], "340", "68", "76", "78", "39", "128", "3", "100", $sex);
    echo 'Character created... cya!<BR>If have errors you can see below:<BR>';
    showErr();
}
?>

It's not the best perform and security, but I hope it will help you.

Bugs? Fixs? please post there.
 
Last edited:
Not modular -.-
This create player with default skills and items ;]
POT is really better.
 
Back
Top