[Req] DarksWeb php reset code

davideguadagno

New Member
Joined
Dec 11, 2014
Messages
17
Reaction score
1
PHP:
<?php

	function do_reset_character()
	{
		global $option;
		$acc = $_SESSION['dt_username'];
		$char = $_POST['character'];

		$show_msg=array(
			'error'=>array()
		);
		
		if(empty($char))
		{
			$show_msg['error'][] = 'Please select a character!';
		}
		elseif(preg_match('/[^a-zA-Z0-9\_\-]/', $char))
		{
			$show_msg['error'][] = 'Invalid symbols!';
		}
		elseif(strlen($char) < 3 || strlen($char) > 10)
		{
			$show_msg['error'][] = 'Invalid Character Name!';
		}
		else
		{
			$is_acc_char = mssql_num_rows(
				mssql_query("SELECT Name FROM Character WHERE AccountID='". $acc ."' AND Name='". $char ."'")
			);
			
			$is_online=is_online($char, 1);
			$character=char_info($char);
			
			$new_res=($character['Resets'] + 1);
				if ( $Resets == 0 ) { $new_res = '1'; $exp = '35774999'; $clevel = '150'; }
				if ( $Resets == 1 ) { $new_res = '2'; $exp = '35774999'; $clevel = '150'; }
				if ( $Resets == 2 ) { $new_res = '3'; $exp = '83599999'; $clevel = '200'; }
				if ( $Resets == 3 ) { $new_res = '4'; $exp = '83599999'; $clevel = '200'; }
				if ( $Resets == 4 ) { $new_res = '6'; $exp = '161874999'; $clevel = '250'; }
				if ( $Resets == 5 ) { $new_res = '7'; $exp = '161874999'; $clevel = '250'; }
				if ( $Resets == 7 ) { $new_res = '8'; $exp = '2802876999'; $clevel = '300'; }
				if ( $Resets == 8 ) { $new_res = '8'; $exp = '2802876999'; $clevel = '300'; }
			
			if($option['rc_zen_type'] === 1)
			{
				$option['rc_zen'] = ($option['rc_zen'] * $new_res);
			}
			
			$new_money=($character['Money'] - $option['rc_zen']);
			if($option['rc_bonus_points'] == 1)
			{
				switch($character['Class'])
				{
					case 0:
					case 1:
					case 2:
						$option['rc_stats_per_reset'] = $option['rc_stats_for_sm'];
						break;
					case 16:
					case 17:
					case 18:
						$option['rc_stats_per_reset'] = $option['rc_stats_for_bk'];
						break;
					case 32:
					case 33:
					case 34:
						$option['rc_stats_per_reset'] = $option['rc_stats_for_me'];
						break;
					case 48:
					case 49:
						$option['rc_stats_per_reset'] = $option['rc_stats_for_mg'];
						break;
					case 64:
					case 65:
						$option['rc_stats_per_reset'] = $option['rc_stats_for_dl'];
						break;
				}
			}
			$level_up_points = $option['rc_stats_per_reset'];
			if($option['rc_stats_type'] === 1)
			{
				 $level_up_points = $level_up_points * $new_res;
			}
			if($option['rc_gr_bonus'] === 1)
			{
				 $level_up_points += ($option['gr_reward'] * $character['GrandResets']);
			}
		
			if($is_acc_char == 0)
			{
				$show_msg['error'][] = 'This character is not yours!';
			}
			elseif($is_online === 1)
			{
				$show_msg['error'][] = 'You need to leave the game!';
			}
			elseif($character['cLevel'] < $option['rc_level'])
			{
				$show_msg['error'][] = 'You need '.($option['rc_level'] - $character['cLevel']).' more levels!';
			}
			elseif($new_money < 0)
			{
				$show_msg['error'][] = 'You don't have enough money(zen)!';
			}
			elseif($new_res > $option['rc_max_resets'])
			{
				$show_msg['error'][] = 'You have reach the maximum resets!';
			}
			else
			{
				$sql='UPDATE Character SET ';
				if($option['rc_clear_stats'] === 1)
				{
					$sql .='Strength = 25, Dexterity = 25, Vitality = 25, Energy = 25, ';
				}
				$sql .="Resets = ".$new_res.", Money = ".$new_money.", LevelUpPoint = ".$level_up_points.", cLevel = $clevel, Experience = $exp WHERE Name='".$character['Name']."' AND AccountID='".$acc."'";
				mssql_query($sql);
				$show_msg['success'][0] = $char .' have successfully reset for '.$new_res.' time.';
			}
		}
		return $show_msg;
	}

I'm using this code for resetting at every stage as u can see but i'm having some problems, the scripts works but when i reset character it does 1 reset starts from 150 and finish there, any solution?
 
PHP:
<?php
function do_reset_character()
{
    global $option;
    $acc = $_SESSION['dt_username'];
    $char = $_POST['character'];

    $show_msg=array(
        'error'=>array()
    );
   
    if(empty($char))
    {
        $show_msg['error'][] = 'Please select a character!';
    }
    elseif(preg_match('/[^a-zA-Z0-9\_\-]/', $char))
    {
        $show_msg['error'][] = 'Invalid symbols!';
    }
    elseif(strlen($char) < 3 || strlen($char) > 10)
    {
        $show_msg['error'][] = 'Invalid Character Name!';
    }
    else
    {
        $is_acc_char = mssql_num_rows(
            mssql_query("SELECT Name FROM Character WHERE AccountID='". $acc ."' AND Name='". $char ."'")
        );
       
        $is_online=is_online($char, 1);
        $character=char_info($char);
       
        $new_res=($character['Resets'] + 1);

        $exp = 0;
        $clevel = 0;

        if ($new_res == 1) { $exp = 35774999; $clevel = 150; }
        elseif ($new_res == 2) { $exp = 83599999; $clevel = 200; }
        elseif ($new_res == 3) { $exp = 83599999; $clevel = 200; }
        elseif ($new_res == 4) { $exp = 161874999; $clevel = 250; }
        elseif ($new_res == 5) { $exp = 161874999; $clevel = 250; }
        elseif ($new_res == 7) { $exp = 2802876999; $clevel = 300; }
        elseif ($new_res == 8) { $exp = 2802876999; $clevel = 300; }
       
        if($option['rc_zen_type'] === 1)
        {
            $option['rc_zen'] = ($option['rc_zen'] * $new_res);
        }
       
        $new_money=($character['Money'] - $option['rc_zen']);
        if($option['rc_bonus_points'] == 1)
        {
            switch($character['Class'])
            {
                case 0:
                case 1:
                case 2:
                    $option['rc_stats_per_reset'] = $option['rc_stats_for_sm'];
                    break;
                case 16:
                case 17:
                case 18:
                    $option['rc_stats_per_reset'] = $option['rc_stats_for_bk'];
                    break;
                case 32:
                case 33:
                case 34:
                    $option['rc_stats_per_reset'] = $option['rc_stats_for_me'];
                    break;
                case 48:
                case 49:
                    $option['rc_stats_per_reset'] = $option['rc_stats_for_mg'];
                    break;
                case 64:
                case 65:
                    $option['rc_stats_per_reset'] = $option['rc_stats_for_dl'];
                    break;
            }
        }
        $level_up_points = $option['rc_stats_per_reset'];
        if($option['rc_stats_type'] === 1)
        {
             $level_up_points = $level_up_points * $new_res;
        }
        if($option['rc_gr_bonus'] === 1)
        {
             $level_up_points += ($option['gr_reward'] * $character['GrandResets']);
        }
   
        if($is_acc_char == 0)
        {
            $show_msg['error'][] = 'This character is not yours!';
        }
        elseif($is_online === 1)
        {
            $show_msg['error'][] = 'You need to leave the game!';
        }
        elseif($character['cLevel'] < $option['rc_level'])
        {
            $show_msg['error'][] = 'You need '.($option['rc_level'] - $character['cLevel']).' more levels!';
        }
        elseif($new_money < 0)
        {
            $show_msg['error'][] = 'You don\'t have enough money(zen)!';
        }
        elseif($new_res > $option['rc_max_resets'])
        {
            $show_msg['error'][] = 'You have reach the maximum resets!';
        }
        else
        {
            $sql='UPDATE Character SET ';
            if($option['rc_clear_stats'] === 1)
            {
                $sql .='Strength = 25, Dexterity = 25, Vitality = 25, Energy = 25, ';
            }
            $sql .="Resets = ".$new_res.", Money = ".$new_money.", LevelUpPoint = ".$level_up_points.", cLevel = $clevel, Experience = $exp WHERE Name='".$character['Name']."' AND AccountID='".$acc."'";
            mssql_query($sql);
            $show_msg['success'][0] = $char .' have successfully reset for '.$new_res.' time.';
        }
    }
    return $show_msg;
}
?>
 
Can you please test
PHP:
<?php
function do_reset_character(){$show_msg=array('error'=>array());
	if(isset($_POST['character'])&&preg_match('/^[a-zA-Z0-9_-]{3,10}$/',$_POST['character'])){global $option;
		$acc=$_SESSION['dt_username'];$char=$_POST['character'];
		$is_acc_char=mssql_num_rows(mssql_query("SELECT Name FROM Character WHERE AccountID='".$acc."' AND Name='".$char."'"));
		$is_online=is_online($char,1);
		$character=char_info($char);
		$new_res=($character['Resets']+1);
		switch($new_res){default:$exp=0;$clevel=0;break;
			case 1:$exp=35774999;$clevel=150;break;
			case 2:case 3:$exp=83599999;$clevel=200;break;
			case 4:case 5:$exp=161874999;$clevel=250;break;
			case 7:case 8:$exp=2802876999;$clevel=300;break;
		}

		if($option['rc_zen_type']===1){$new_money=($character['Money']-($option['rc_zen']*$new_res));}
		if($option['rc_bonus_points']==1){
			switch($character['Class']){
				case 0:case 1:case 2:$level_up_points=$option['rc_stats_for_sm'];break;
				case 16:case 17:case 18:$level_up_points=$option['rc_stats_for_bk'];break;
				case 32:case 33:case 34:$level_up_points=$option['rc_stats_for_me'];break;
				case 48:case 49:$level_up_points=$option['rc_stats_for_mg'];break;
				case 64:case 65:$level_up_points=$option['rc_stats_for_dl'];break;
			}
		}
		if($option['rc_stats_type']===1){$level_up_points=$level_up_points*$new_res;}
		if($option['rc_gr_bonus']===1){$level_up_points+=($option['gr_reward']*$character['GrandResets']);}
		if($is_acc_char==0){$show_msg['error'][]='This character is not yours!';
		}elseif($is_online===1){$show_msg['error'][]='You need to leave the game!';
		}elseif($character['cLevel']<$option['rc_level']){$show_msg['error'][]='You need '.($option['rc_level']-$character['cLevel']).' more levels!';
		}elseif($new_money<0){$show_msg['error'][]='You don\'t have enough money(zen)!';
		}elseif($new_res>$option['rc_max_resets']){$show_msg['error'][]='You have reach the maximum resets!';
		}else{
			if($option['rc_clear_stats']===1){$qustats='Strength=25,Dexterity=25,Vitality=25,Energy=25,';}else{$qustats='';}
			mssql_query("UPDATE Character SET $qustats Resets=$new_res,Money=$new_money,LevelUpPoint=$level_up_points,cLevel=$clevel,Experience=$exp WHERE Name='".$character['Name']."' AND AccountID='".$acc."'");
			$show_msg['success'][0]=$char.' have successfully reset for '.$new_res.' time.';
		}
	}else{
		$show_msg['error'][]='Invalid character!';
	}return $show_msg;
}
?>

It's DarkMaster's function, but cleaner.
 
Last edited:
  • Like
Reactions: Damian
Can you please test
PHP:
<?php
function do_reset_character(){$show_msg=array('error'=>array());
	if(isset($_POST['character'])&&preg_match('/^[a-zA-Z0-9_-]{3,10}$/',$_POST['character'])){global $option;
		$acc=$_SESSION['dt_username'];$char=$_POST['character'];
		$is_acc_char=mssql_num_rows(mssql_query("SELECT Name FROM Character WHERE AccountID='".$acc."' AND Name='".$char."'"));
		$is_online=is_online($char,1);
		$character=char_info($char);
		$new_res=($character['Resets']+1);
		switch($new_res){default:$exp=0;$clevel=0;break;
			case 1:$exp=35774999;$clevel=150;break;
			case 2:case 3:$exp=83599999;$clevel=200;break;
			case 4:case 5:$exp=161874999;$clevel=250;break;
			case 7:case 8:$exp=2802876999;$clevel=300;break;
		}

		if($option['rc_zen_type']===1){$new_money=($character['Money']-($option['rc_zen']*$new_res));}
		if($option['rc_bonus_points']==1){
			switch($character['Class']){
				case 0:case 1:case 2:$level_up_points=$option['rc_stats_for_sm'];break;
				case 16:case 17:case 18:$level_up_points=$option['rc_stats_for_bk'];break;
				case 32:case 33:case 34:$level_up_points=$option['rc_stats_for_me'];break;
				case 48:case 49:$level_up_points=$option['rc_stats_for_mg'];break;
				case 64:case 65:$level_up_points=$option['rc_stats_for_dl'];break;
			}
		}
		if($option['rc_stats_type']===1){$level_up_points=$level_up_points*$new_res;}
		if($option['rc_gr_bonus']===1){$level_up_points+=($option['gr_reward']*$character['GrandResets']);}
		if($is_acc_char==0){$show_msg['error'][]='This character is not yours!';
		}elseif($is_online===1){$show_msg['error'][]='You need to leave the game!';
		}elseif($character['cLevel']<$option['rc_level']){$show_msg['error'][]='You need '.($option['rc_level']-$character['cLevel']).' more levels!';
		}elseif($new_money<0){$show_msg['error'][]='You don\'t have enough money(zen)!';
		}elseif($new_res>$option['rc_max_resets']){$show_msg['error'][]='You have reach the maximum resets!';
		}else{
			if($option['rc_clear_stats']===1){$qustats='Strength=25,Dexterity=25,Vitality=25,Energy=25,';}else{$qustats='';}
			mssql_query("UPDATE Character SET $qustats Resets=$new_res,Money=$new_money,LevelUpPoint=$level_up_points,cLevel=$clevel,Experience=$exp WHERE Name='".$character['Name']."' AND AccountID='".$acc."'");
			$show_msg['success'][0]=$char.' have successfully reset for '.$new_res.' time.';
		}
	}else{
		$show_msg['error'][]='Invalid character!';
	}return $show_msg;
}
?>

It's DarkMaster's function, but cleaner.

I don't think that your code is cleaner because you have removed the alignment. Furthermore I think that "default" option on first place is right but weird.
 
I don't think that your code is cleaner because you have removed the alignment. Furthermore I think that "default" option on first place is right but weird.

It doesn't really matter where the default is located inside the switch block. I like to use it on switch(){ line to have clean view on the cases instead end with it, but if you want move it after them.
What do you mean by "you have removed the alignment"?
 
It doesn't really matter where the default is located inside the switch block. I like to use it on switch(){ line to have clean view on the cases instead end with it, but if you want move it after them.
What do you mean by "you have removed the alignment"?

Please read this guide for reference.
 
It doesn't really matter where the default is located inside the switch block. I like to use it on switch(){ line to have clean view on the cases instead end with it, but if you want move it after them.
What do you mean by "you have removed the alignment"?

Even if you do not follow the rulez that Damian is suggesting, you should have a common sence of styling to prepare well organized, easy for reading and uderstanding code.

Your phrase "to have clean view" doesn't make any sence to me in terms your code is completelly unreadable and hard for maintaning from someone else.
 
Some people like to write code that is dish with grapes!