Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: 99% ajax crimes  (Read 1441 times)

catles

  • Basic Member
  • *
  • Reputation Power: 24
  • catles has no influence.
  • Offline Offline
  • Posts: 26
    • View Profile
    • WWW
    • Email
99% ajax crimes
« on: January 25, 2010, 03:43:49 PM »

ok this is my 1st mod so bare with me
i used the prototype eng for the Ajax (hance y I'm posting this free) not sure if i can link to there download page but just Google prototype to get it,

criminal.php
Code: [Select]
<?php
$macropage
="criminal.php";
$pagename="criminal";
include 
"globals.php";
if(
$ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
$q2=$db->query("SELECT * FROM crimes ORDER BY crimeBRAVE ASC");
while (
$r2=$db->fetch_row($q2))
{
$crimes[]=$r2;
}
$q=$db->query("SELECT * FROM crimegroups ORDER by cgORDER ASC");
print 
"
<div id='do'>
</div>
<div id='crimes'>
</div><br /><b>Criminal Centre</b><br />
<table width='75%' cellspacing=1 class='table'><tr><th>Crime</th><th>Cost</th><th>Do</th></tr>"
;
while(
$r=$db->fetch_row($q))
{
print 
"<tr><td colspan='3' class='h'>{$r['cgNAME']}</td></tr>";
foreach(
$crimes as $v)
{
if(
$v['crimeGROUP'] == $r['cgID'])
{
echo <<<<
CRIMES
 
<tr><td>{$v['crimeNAME']}</td><td>{$v['crimeBRAVE']} Brave</td><td><a href="#do" onclick="javascript:void load( 'docrime.php?c={$v['crimeID']}' )">Do</a></td></tr>
CRIMES;
}
}
}
print 
"</table>";
print <<<OUT
 <script type=text/javascript>
  function load( crime ) {
  new Ajax.Updater( 'crimes', crime, { method: 'get' } );
}
</script>
<script src="effects.js" type="text/javascript"></script>
OUT;
$h->endpage();
?>

docrime.php
Code: [Select]
<?php
$macropage
="docrime.php?c={$_GET['c']}";
include 
"globals_ajax.php";
if(
$ir['jail'] or $ir['hospital']) { die("This page cannot be accessed while in jail or hospital."); }
$_GET['c']=abs((int) $_GET['c']);
if(!
$_GET['c'])
{
print 
"Invalid crime";
}
else
{
$q=mysql_query("SELECT * FROM crimes WHERE crimeID={$_GET['c']}",$c);
$r=mysql_fetch_array($q);
if(
$ir['brave'] < $r['crimeBRAVE'])
{
print 
"You do not have enough Brave to perform this crime.";
}
else
{
$ec="\$sucrate=".str_replace(array("LEVEL","CRIMEXP","EXP","WILL","IQ"), array($ir['level'], $ir['crimexp'], $ir['exp'], $ir['will'], $ir['IQ']),$r['crimePERCFORM']).";";
eval(
$ec);
print 
$r['crimeITEXT'];
$ir['brave']-=$r['crimeBRAVE'];
mysql_query("UPDATE users SET brave={$ir['brave']} WHERE userid=$userid",$c);
$br1=(int) ($ir['brave']/$ir['maxbrave']*100);
echo 
'<input type="hidden" name="b1s" value="'.$br1.'" id="b1s" />';
if(
rand(1,100) <= $sucrate)
{
print 
str_replace("{money}",$r['crimeSUCCESSMUNY'],$r['crimeSTEXT']);
$ir['money']+=$r['crimeSUCCESSMUNY'];
$ir['crystals']+=$r['crimeSUCCESSCRYS'];
$ir['exp']+=(int) ($r['crimeSUCCESSMUNY']/8);
mysql_query("UPDATE users SET money={$ir['money']}, crystals={$ir['crystals']}, exp={$ir['exp']},crimexp=crimexp+{$r['crimeXP']} WHERE userid=$userid",$c);
if(
$r['crimeSUCCESSITEM'])
{
  
item_add($userid$r['crimeSUCCESSITEM'], 1);
}
}
else
{
if(
rand(12) == 1)
{
print 
$r['crimeFTEXT'];
}
else
{
  print 
$r['crimeJTEXT'];
  
$db->query("UPDATE `users` SET `jail` = '$r[crimeJAILTIME]', `jail_reason` = '$r[crimeJREASON]' WHERE `userid` = '$userid'");
}
}
echo <<<DOCRIME
 <script type=text/javascript>
  function load( crime ) {
  new Ajax.Updater( 'crimes', crime, { method: 'get' } );
}
</script>
<br /><a href="javascript:void load( 'docrime.php?c=
{$_GET['c']}' )">Try Again</a><br />
DOCRIME;
}
}


$h->endpage();
?>


globals_ajax.php cuz you cant use the main globals...
Code: [Select]
<?php

session_start
();
ob_start();
if (
get_magic_quotes_gpc()) {
foreach(
$_POST as $k => $v)
  {
    
$_POST[$k]=addslashes($v);
  }
  foreach(
$_GET as $k => $v)
  {
    
$_GET[$k]=addslashes($v);
  }

}


require 
"global_func.php";
$userid=$_SESSION['userid'];

include 
"config.php";
global 
$_CONFIG;
define("MONO_ON"1);
require 
"class/class_db_mysql.php";
$db=new database;
$db->configure($_CONFIG['hostname'],
 
$_CONFIG['username'],
 
$_CONFIG['password'],
 
$_CONFIG['database'],
 
$_CONFIG['persistent']);
$db->connect();
$c=$db->connection_id;
$set=array();
$settq=$db->query("SELECT * FROM settings");
while(
$r=$db->fetch_row($settq))
{
$set[$r['conf_name']]=$r['conf_value'];
}
$domain=$_SERVER['HTTP_HOST'];


$is=$db->query("SELECT u.*,us.*,c.*
FROM users u
LEFT JOIN userstats us
ON u.userid=us.userid
LEFT JOIN cities c
ON u.location=c.cityid
WHERE u.userid=$userid"
);
$ir=$db->fetch_row($is);


global 
$macropage;
if(
$macropage && !$ir['verified'] && $set['validate_on']==1)
{
header("Location: macro1.php?refer=$macropage");
exit;
}
?>
effects.js
Code: [Select]
Event.observe(window, 'load', function() {
  $$('a[href^=#]:not([href=#])').each(function(element) {
    element.observe('click', function(event) {
      new Effect.ScrollTo(this.hash.substr(1));
      Event.stop(event);
    }.bindAsEventListener(element))
  })
})
var b1s=document.getElementById('b1s').value;
document.getElementById("user1bra").style.width=""+s1s+"px";

And give your brave bar's IMG code
Code: [Select]
id='user1bra'
« Last Edit: January 27, 2011, 08:39:27 AM by catles »
Logged

vlad

  • Basic Member
  • *
  • Reputation Power: 3
  • vlad has no influence.
  • Offline Offline
  • Posts: 7
    • View Profile
    • WWW
    • Email
Re: 99% ajax crimes
« Reply #1 on: July 05, 2010, 10:25:59 AM »
thats the fancy ajax crimes ive been hearing about , havent tryd it but ok job could be a little differant , btw isnt that for sale in the sale part of the forum?
Logged

catles

  • Basic Member
  • *
  • Reputation Power: 24
  • catles has no influence.
  • Offline Offline
  • Posts: 26
    • View Profile
    • WWW
    • Email
Re: 99% ajax crimes
« Reply #2 on: July 10, 2010, 10:09:12 PM »
not this code i costem did it myself tho the one for dale is a really nice one
Logged

catles

  • Basic Member
  • *
  • Reputation Power: 24
  • catles has no influence.
  • Offline Offline
  • Posts: 26
    • View Profile
    • WWW
    • Email
Re: 99% ajax crimes
« Reply #3 on: January 27, 2011, 08:38:57 AM »
updated for all thoughs who asked im PMs over the last year ^^
Logged
 


This forum is now closed and has moved to a new location! Click here to find out why.