Hello everyone,
I am trying to send parameters to my php file but when I try it it generates the error: Undefined index: peticion
This is what I wrote in the GDevelop:
host: “https://example.com”
path: “/duelos/enviar_duelo.php”
body: “peticion= inicio”
methods: “POST”
content type: “text / javascript”
variable: arr_inicio
The php file have permissions: 755
The code that my php has:
<?php
header('Content-Type: text/javascript');
header('Access-Control-Allow-Origin: https://example.com');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');
$peticion = $_REQUEST['peticion'];
if ($peticion == 'inicio') {
$id_usuario = $_COOKIE['loggedin'];
$id_player = $id_usuario;
include('../libreria/obtener_conexion_members.php');
include('../libreria/obtener_ip_usuario.php');
include('../libreria/obtener_ip_x_id.php');
$ip_actual = get_client_ip();
$ip_guardado = $arr_session['ip'];
if ($ip_actual == $ip_guardado) {
// Se obtiene valores del temp
$valida_rival_temp = mysql_query("SELECT * FROM hm_rol_temp
WHERE ind_duelo = 'S' and id_player=".$id_usuario, $db_connection);
if (mysql_num_rows($valida_rival_temp) > 0)
{
$arr_temp = mysql_fetch_assoc($valida_rival_temp);
$id_rival = $arr_temp['id_rival'];
$id_lugar = $arr_temp['id_lugar'];
// datos del player
$valida_player=mysql_query("SELECT * FROM hm_rol_players WHERE id_usuario = ".$id_player, $db_connection);
if (mysql_num_rows($valida_player)<=0)
{
echo "Error al obtener datos del jugador al iniciar el duelo.";
}
$arr_player = mysql_fetch_assoc($valida_player);
$ataque_player = $arr_player['ataque'];
$defensa_player = $arr_player['defensa'];
$hambre_player = $arr_player['hambre'];
$cansancio_player = $arr_player['cansancio'];
$id_mano1_player = $arr_player['mano_1'];
$id_mano2_player = $arr_player['mano_2'];
$id_pecho_player = $arr_player['pecho'];
$id_cabeza_player = $arr_player['cabeza'];
$id_avatar_player = $arr_player['id_avatar'];
$hp_player = $defensa_player-($defensa_player*((20-$cansancio_player)/20));
$fp_player = $ataque_player-($ataque_player*((10-$hambre_player)/10));
// obtener nombres objetos
if ($id_mano1_player > 0) {
$id_objeto = $id_mano1_player;
include('../libreria/obtener_objeto.php');
$mano1_player = $arr_objeto['nombre'];
$fp_player = $fp_player + ($ataque_player*($arr_objeto['ataque']/100));
}
if ($id_mano2_player > 0) {
$id_objeto = $id_mano2_player;
include('../libreria/obtener_objeto.php');
$mano2_player = $arr_objeto['nombre'];
$fp_player = $fp_player + ($ataque_player*($arr_objeto['ataque']/100));
}
if ($id_pecho_player > 0) {
$id_objeto = $id_pecho_player;
include('../libreria/obtener_objeto.php');
$pecho_player = $arr_objeto['nombre'];
$hp_player = $hp_player + ($defensa_player*($arr_objeto['defensa']/100));
}
if ($id_cabeza_player > 0) {
$id_objeto = $id_cabeza_player;
include('../libreria/obtener_objeto.php');
$cabeza_player = $arr_objeto['nombre'];
$hp_player = $hp_player + ($defensa_player*($arr_objeto['defensa']/100));
}
// datos del rival
$id_usuario = $id_rival;
include('../libreria/obtener_usuario_x_id.php');
$nombre_rival = $arr_usuario_x_id['usuario'];
$nivel_rival = $arr_usuario_x_id['nivel'];
$monedas_rival = $arr_usuario_x_id['monedas_total'];
$valida_rival=mysql_query("SELECT * FROM hm_rol_players WHERE id_usuario = ".$id_rival, $db_connection);
if (mysql_num_rows($valida_rival)<=0)
{
echo "Error al obtener datos del rival al iniciar el duelo.";
}
$arr_rival = mysql_fetch_assoc($valida_rival);
$defensa_rival =$arr_rival['defensa'];
$ataque_rival = $arr_rival['ataque'];
$hambre_rival = $arr_rival['hambre'];
$cansancio_rival = $arr_rival['cansancio'];
$id_casco_rival = $arr_rival['cabeza'];
$id_pecho_rival = $arr_rival['pecho'];
$id_mano1_rival = $arr_rival['mano_1'];
$id_mano2_rival = $arr_rival['mano_2'];
$id_avatar_rival = $arr_rival['id_avatar'];
$hp_rival = $defensa_rival-($defensa_rival*((20-$cansancio_rival)/20));
$fp_rival = $ataque_rival-($ataque_rival*((10-$hambre_rival)/10));
if ($id_casco_rival > 0) {
$id_objeto = $id_casco_rival;
include('../libreria/obtener_objeto.php');
$desc_casco_rival = $arr_objeto['nombre'];
$hp_rival = $hp_rival + ($defensa_rival*($arr_objeto['defensa']/100));
}
if ($id_pecho_rival > 0) {
$id_objeto = $id_pecho_rival;
include('../libreria/obtener_objeto.php');
$desc_pecho_rival = $arr_objeto['nombre'];
$hp_rival = $hp_rival + ($defensa_rival*($arr_objeto['defensa']/100));
}
if ($id_mano2_rival > 0) {
$id_objeto = $id_mano2_rival;
include('../libreria/obtener_objeto.php');
$desc_mano2rival = $arr_objeto['nombre'];
$fp_rival = $fp_rival + ($ataque_rival*($arr_objeto['ataque']/100));
}
if ($id_mano1_rival > 0) {
$id_objeto = $id_mano1_rival;
include('../libreria/obtener_objeto.php');
$desc_mano1rival = $arr_objeto['nombre'];
$fp_rival = $fp_rival + ($ataque_rival*($arr_objeto['ataque']/100));
}
} else {
echo "Error al iniciar el duelo, vuelve a intentarlo.";
}
echo '{
"id_player":"'. $id_player.'",
"id_lugar":"'. $id_lugar.'",
"id_categoria":"1",
"id_avatar_player":"'. $id_avatar_player.'",
"id_mano1_player":"'. $id_mano1_player.'",
"id_mano2_player":"'. $id_mano2_player.'",
"id_cabeza_player":"'. $id_cabeza_player.'",
"id_pecho_player":"'. $id_pecho_player.'",
"hp_player":"'. $hp_player.'",
"fp_player":"'. $fp_player.'",
"id_rival":"'. $id_rival.'",
"nombre_rival":"'. $nombre_rival.'",
"id_avatar_rival":"'. $id_avatar_rival.'",
"id_mano1_rivalr":"'. $id_mano1_rival.'",
"id_mano2_rival":"'. $id_mano2_rival.'",
"id_cabeza_rival":"'. $id_casco_rival.'",
"id_pecho_rival":"'. $id_pecho_rival.'",
"hp_rival":"'. $hp_rival.'",
"fp_rival":"'. $fp_rival.'"
}';
mysql_close();
} else {
echo "Error, conflicto al iniciar sesion del duelo";
}
} /*elseif () {
}*/
?>
With this attempt, when starting the game, get all the player’s values
Please, help me with this?
Thank!