Ich versuche gerade für den Vault Mod ein System zu erschaffen um einen automatischen Börsencrash zu verursachen. Dazu habe ich mir 2 Variablen erschaffen, welche die max., min. (Vergleichswert) und aktuellen Preise (Index) in ein Verhältnis setzen. D.h. wenn der Index größer gleich dem Vergleichswert ist, soll es crashen. Das funktioniert auch bestens. Nur leider explodieren die Preise förmlich anstelle zu fallen.
Was mache ich in folgendem Code falsch:
Code: Alles auswählen
for($i = 0; $i < count($exchange); $i++)
{
if ( $vault_general['stock_min_change'] > $vault_general['stock_max_change'] )
{
$vault_general['stock_min_change'] = $vault_general['stock_max_change'];
}
$variation = mt_rand($vault_general['stock_min_change'] , $vault_general['stock_max_change']);
$hazard = mt_rand(1,2);
if ( $hazard == '2' )
{
$variation = - $variation ;
}
$new_price = round((($exchange[$i]['stock_price'] + 1) * ( 1 + ( $variation / 100 ))), 2);
$old_price = $exchange[$i]['stock_price'];
$best_price = ( $new_price > $exchange[$i]['stock_best_price'] ) ? $new_price : $exchange[$i]['stock_best_price'];
$worst_price = ( $new_price < $exchange[$i]['stock_worst_price'] ) ? $new_price : $exchange[$i]['stock_worst_price'];
$sql = "UPDATE " . VAULT_EXCHANGE_TABLE ."
SET stock_price = $new_price ,
stock_previous_price = $old_price ,
stock_best_price = $best_price ,
stock_worst_price = $worst_price
WHERE stock_id = ".$exchange[$i]['stock_id'];
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Couldn't update stock exchange", "", __LINE__, __FILE__, $sql);
}
// --- Börsencrash - Start ---
if ( $stock_price_avg >= $stock_avg )
{
$variation = mt_rand($vault_general['stock_min_change'] , $vault_general['stock_max_change']);
$variation = - $variation ;
$new_price = round((($exchange[$i]['stock_price'] + 5) * ( 5 + ( $variation / 100 ))), 2);
$old_price = $exchange[$i]['stock_price'];
$best_price = ( $new_price > $exchange[$i]['stock_best_price'] ) ? $new_price : $exchange[$i]['stock_best_price'];
$worst_price = ( $new_price < $exchange[$i]['stock_worst_price'] ) ? $new_price : $exchange[$i]['stock_worst_price'];
$sql = "UPDATE " . VAULT_EXCHANGE_TABLE ."
SET stock_price = $new_price ,
stock_previous_price = $old_price ,
stock_best_price = $best_price ,
stock_worst_price = $worst_price
WHERE stock_id = ".$exchange[$i]['stock_id'];
$result = $db->sql_query($sql);
if( !$result )
{
message_die(GENERAL_ERROR, "Couldn't update stock exchange", "", __LINE__, __FILE__, $sql);
}
}
// --- Börsencrash - Ende ---
}
Code: Alles auswählen
$variation = - $variation ;
Bye