Jump to content
MakeWebGames

Crime items help needed


orsino

Recommended Posts

hello all 

im working on my crime page 

chivalryisdeadgame source (mccodes) 

i would like to ad crimes where the user steals a random item 

i already managed to do that  but its not printing the item name when the crime is done 

          

 if ($_GET['c'] == 3)   //// cartheft
                {
                    $item = array(1,2,3,4,5);
                        $api->UserGiveItem($userid, $item[mt_rand(0,4)], 1);
                        $api->SystemLogsAdd($userid, 'crime', "Successfully stole {$item} .");
                    }
                $text = str_ireplace(array("{money}","{secondary}","{item}"), array(number_format($prim_currency),number_format($sec_currency),$api->SystemItemIDtoName($r['crimeITEMSUC'])), $r['crimeSTEXT']);
                $title = "Success!";
                $type = 'success';

when i have a normal crime with 1 item , i can add {items} in the text 

but i need it to work for random items aswell 

Link to comment
Share on other sites

<?php
$macropage = ('criminal.php');
require('globals.php');
include('class/class_evalmath.php');
$m = new EvalMath;
echo "<h3><i class='game-icon game-icon-robber'></i> Criminal Center</h3>";
if ($api->UserStatus($ir['userid'], 'infirmary') || $api->UserStatus($ir['userid'], 'dungeon')) {
    alert('danger', "Uh Oh!", "You cannot commit crimes while in the hospital or jail.");
    die($h->endpage());
}
if ($api->UserInfoGet($userid, 'will', true) > 100)
{
	alert('danger', "Uh Oh!", "You cannot commit crimes while your will is over 100%!");
    die($h->endpage());
}
if (!isset($_GET['action'])) {
    $_GET['action'] = '';
}
switch ($_GET['action']) {
    case 'crime':
        crime();
        break;
    default:
        home();
        break;
}
function home()
{
    global $db, $h, $ir, $m, $userid, $api;
    $crimes = array();
    $q2 = $db->query("/*qc=on*/SELECT `crimeGROUP`, `crimeNAME`, `crimeBRAVE`, `crimeID`, `crimePERCFORM` FROM `crimes` ORDER BY `crimeBRAVE` ASC");
    while ($r2 = $db->fetch_row($q2)) {
        $crimes[] = $r2;
    }
    $db->free_result($q2);
    $q = $db->query("/*qc=on*/SELECT `cgID`, `cgNAME` FROM `crimegroups` ORDER BY `cgORDER` ASC");
	echo "<div class='card'>
        <div class='card-body'><div class='row'>
			<div class='col'>
				<h5>Crime</h5>
			</div>
			<div class='col'>
				<h5>Success Chance</h5>
			</div>
		</div>
		<hr />";
    while ($r = $db->fetch_row($q)) {
        echo "<div class='row'>
				<div class='col'>
					<h3>{$r['cgNAME']} Crimes</h3> 
				</div>
			</div>
			<hr />";
        foreach ($crimes as $v) {
            if ($v['crimeGROUP'] == $r['cgID']) {
				//Fix from Kyle Massacre. Thanks!
				//https://github.com/KyleMassacre
				$ec = str_ireplace(array("LEVEL", "EXP", "WILL", "IQ"), array($ir['level'], $ir['xp'], $ir['will'], $ir['iq']), $v['crimePERCFORM']) . ";";
				$tokens = token_get_all("<?php {$ec}");
				$expr = '';
				foreach($tokens as $token)
				{
					if(is_string($token))
					{
						if(in_array($token, array('(', ')', '+', '-', '/', '*'), true))
							$expr .= $token;
						continue;
					}
					list($id, $text) = $token;
					if(in_array($id, array(T_DNUMBER, T_LNUMBER)))
						$expr .= $text;
				}
				$v['sucrate']=$m->evaluate($expr);
				try 
				{
					$v['sucrate']=$m->evaluate($expr); 
				}
				catch (\Error $e)
				{
					alert('danger',"Uh Oh!","There's an issue with this crime. Please contact the game administration.",true,'criminal.php');
					die($h->endpage());
				}
				$specialnumber=((getSkillLevel($userid,17)*20)/100);
				$v['sucrate']=$v['sucrate']+($v['sucrate']*$specialnumber);
				if (hasNecklaceEquipped($userid,284))
				{
					$v['sucrate']=$v['sucrate']+($v['sucrate']*0.1);
				}
				if ($v['sucrate'] > 100)
					$v['sucrate']=100;
				$v['sucrate']=round($v['sucrate']);
				echo "<div class='row'>
			<div class='col'>
				<a href='?action=crime&c={$v['crimeID']}'>{$v['crimeNAME']}</a><br />
				Needed Brave: {$v['crimeBRAVE']}
			</div>
			<div class='col'>
				<div class='progress' style='height: 1rem;'>
					<div class='progress-bar bg-primary' role='progressbar' aria-valuenow='{$v['sucrate']}' style='width:{$v['sucrate']}%' aria-valuemin='0' aria-valuemax='100'>
						<span>
							{$v['sucrate']}%
						</span>
					</div>
				</div>
			</div>
			</div>
			<hr />";
            }
        }
    }
    echo "</div>
			</div>";
    $db->free_result($q);
    $h->endpage();
}

function crime()
{
    global $db, $userid, $ir, $h, $api, $m;
    if (!isset($_GET['c'])) {
        $_GET['c'] = 0;
    }
    $_GET['c'] = abs($_GET['c']);
    if ($_GET['c'] <= 0) {
        alert('danger', "Invalid Crime!", "You have chosen to commit and invalid crime.", true, 'criminal.php');
    } else {
        $q = $db->query("/*qc=on*/SELECT * FROM `crimes` WHERE `crimeID` = {$_GET['c']} LIMIT 1");
        if ($db->num_rows($q) == 0) {
            alert('danger', "Invalid Crime!", "You are trying to commit a non-existent crime.", true, 'criminal.php');
            die($h->endpage());
        }
        $r = $db->fetch_row($q);
        $db->free_result($q);
        if ($ir['brave'] < $r['crimeBRAVE']) {
            alert('danger', "Uh Oh!", "You do not have enough Bravery to commit this crime. You only have {$ir['brave']} Brave.", true, 'criminal.php');
            die($h->endpage());
        } else {
            //Fix from Kyle Massacre. Thanks!
            //https://github.com/KyleMassacre
            $ec = str_ireplace(array("LEVEL", "EXP", "WILL", "IQ"), array($ir['level'], $ir['xp'], $ir['will'], $ir['iq']), $r['crimePERCFORM']) . ";";
            $tokens = token_get_all("<?php {$ec}");
            $expr = '';
            foreach($tokens as $token)
            {
                if(is_string($token))
                {
                    if(in_array($token, array('(', ')', '+', '-', '/', '*'), true))
                        $expr .= $token;
                    continue;
                }
                list($id, $text) = $token;
                if(in_array($id, array(T_DNUMBER, T_LNUMBER)))
                    $expr .= $text;
            }
            $sucrate=$m->evaluate($expr);
            try 
            {
                $sucrate=$m->evaluate($expr); 
            }
            catch (\Error $e)
            {
                alert('danger',"Uh Oh!","There's an issue with this crime. Please contact the game administration.",true,'criminal.php');
                die($h->endpage());
            }
            if (!$sucrate)
            {
                alert('danger',"Uh Oh!","There's an issue with this crime. Please contact the game administration.",true,'criminal.php');
                die($h->endpage());
            }
			$specialnumber=((getSkillLevel($userid,17)*20)/100);
			$sucrate=$sucrate+($sucrate*$specialnumber);
			if (hasNecklaceEquipped($userid,284))
					$sucrate=$sucrate+($sucrate*0.1);
            $ir['brave'] -= $r['crimeBRAVE'];
            $api->UserInfoSet($userid, "brave", "-{$r['crimeBRAVE']}");
            if (Random(1, 100) <= $sucrate) {
                if (!empty($r['crimePRICURMIN'])) {
                    $prim_currency = Random($r['crimePRICURMIN'], $r['crimePRICURMAX']);
                    $api->UserGiveCurrency($userid, 'primary', $prim_currency);
					crime_log($_GET['c'],true,'copper',$prim_currency);
					addToEconomyLog('Criminal Activities', 'copper', $prim_currency);
                }
                if (!empty($r['crimeSECCURMIN'])) {
                    $sec_currency = Random($r['crimeSECCURMIN'], $r['crimeSECURMAX']);
                    $api->UserGiveCurrency($userid, 'secondary', $sec_currency);
					crime_log($_GET['c'],true,'token',$sec_currency);
					addToEconomyLog('Criminal Activities', 'token', $sec_currency);
                }
                if (!empty($r['crimeITEMSUC'])) {
                    item_add($userid, $r['crimeITEMSUC'], 1);
					crime_log($_GET['c'],true,'item',1);
                }
                if (empty($prim_currency)) {
                    $prim_currency = 0;
                }
                if (empty($sec_currency)) {
                    $sec_currency = 0;
                }
                if (empty($r['crimeITEMSUC'])) {
                    $r['crimeITEMSUC'] = 0;
                }
				if ($_GET['c'] == 3)   //// cartheft
				{
			                    $item = array(1,2,3,4,5);
                        $api->UserGiveItem($userid, $item[mt_rand(0,4)], 1);
                        $api->SystemLogsAdd($userid, 'crime', "Successfully stole {$item} .");
					}
                $text = str_ireplace(array("{money}","{secondary}","{item}"), array(number_format($prim_currency),number_format($sec_currency),$api->SystemItemIDtoName($r['crimeITEMSUC'])), $r['crimeSTEXT']);
                $title = "Success!";
                $type = 'success';
                $api->UserInfoSetStatic($userid, "xp", $ir['xp'] + $r['crimeXP']);
                $api->SystemLogsAdd($userid, 'crime', "Successfully committed the {$r['crimeNAME']} crime.");
            } else {
                $title = "Uh Oh!";
                $type = 'danger';
                $dtime = Random($r['crimeDUNGMIN'], $r['crimeDUNGMAX']);
                $text = str_replace("{time}", number_format($dtime), $r['crimeFTEXT']);
                $api->UserStatusSet($userid, 'dungeon', $dtime, $r['crimeDUNGREAS']);
                $api->SystemLogsAdd($userid, 'crime', "Failed to commit the {$r['crimeNAME']} crime.");
				crime_log($_GET['c'],false,0,0);
            }
			$api->SystemLogsAdd($userid, 'xp_gain', "+" . number_format($r['crimeXP']) . "XP");
            alert("{$type}", "{$title}", "{$r['crimeITEXT']} {$text}", true, "?action=crime&c={$_GET['c']}", "Attempt Again");
            die($h->endpage());
        }
    }
}
function crime_log($crimeid,$won,$wontype,$wonqty)
{
	global $db,$userid,$api;
	$q=$db->query("/*qc=on*/SELECT * FROM `crime_logs` WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
	if ($db->num_rows($q) == 0)
	{
		$db->query("INSERT INTO `crime_logs` 
					(`userid`, `crimeid`, `crimetotal`, `crimesuccess`,
					`crimecopper`, `crimetoken`, `crimeitem`) 
					VALUES 
					('{$userid}', '{$crimeid}', '0', '0', '0', '0', '0')");
	}
	$db->free_result($q);
	$q=$db->query("/*qc=on*/SELECT * FROM `crime_logs` WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
	$r=$db->fetch_row($q);
	$db->query("UPDATE `crime_logs` SET `crimetotal` = `crimetotal` + 1 WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
	if ($won)
	{
		if ($wontype == 'copper')
		{
			$db->query("UPDATE `crime_logs` SET `crimecopper` = `crimecopper` + {$wonqty} WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
		}
		if ($wontype == 'token')
		{
			$db->query("UPDATE `crime_logs` SET `crimetoken` = `crimetoken` + {$wonqty} WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
		}
		if ($wontype == 'item')
		{
			$db->query("UPDATE `crime_logs` SET `crimeitem` = `crimeitem` + 1 WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
		}
		$db->query("UPDATE `crime_logs` SET `crimesuccess` = `crimesuccess` + 1 WHERE `userid` = {$userid} AND `crimeid` = {$crimeid}");
	}
}

the item is given thats not the problem 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...