[AYUDA] Comando con mysql
#1

Comando :
pawn Код:
cmd(comprarveh,playerid,params[])//Trenico
{
    if(GetPVarInt(playerid,"Logueado"))
    {
        new color1,color2;
        new vehicleid;
        new query[400];
        if (VerDinero(playerid) >= CostoCoche(GetPVarInt(playerid,"CocheConcesionario")))
        {
            if (GetPVarInt(playerid,"ComprandoCoche"))
            {
                MostrarSombra(playerid);
                DestroyVehicle(GetPVarInt(playerid,"CocheConcesionario"));
                vehicleid = AddStaticVehicleEx(ModelosCoches[GetPVarInt(playerid,"BuscandoCoche")], -1640.9456,1216.0890,7.0391, 0, -1, -1, 60000);
                TogglePlayerControllable(playerid, true);
                SetPVarInt(playerid,"ComprandoCoche",0);
                SetPVarInt(playerid,"BuscandoCoche",0);
                SetPlayerVirtualWorld(playerid, 0);
                SetVehicleVirtualWorld(vehicleid, 0);
                SetCameraBehindPlayer(playerid);
                VerColorCoche(vehicleid,color1,color2);

                if (InfoJugador[playerid][jLlave1] == 2000) { }
                else if (InfoJugador[playerid][jLlave2] == 2000) { }
                else if (InfoJugador[playerid][jLlave3] == 2000) { }
                else
                {
                    SendClientMessage(playerid, color_rojo, "Tienes todas las llaves ocupadas!");
                    DestroyVehicle(GetPVarInt(playerid,"CocheConcesionario"));
                    TogglePlayerControllable(playerid, true);
                    SetPVarInt(playerid,"ComprandoCoche",0);
                    SetPVarInt(playerid,"BuscandoCoche",0);
                    SetPlayerVirtualWorld(playerid, 0);
                    SetVehicleVirtualWorld(vehicleid, 0);
                    SetCameraBehindPlayer(playerid);
                    SetPlayerPos(playerid, -1657.5057,1210.6478,7.2500);
                    TextDrawHideForPlayer(playerid,TextoConce[playerid]);
                    TextDrawHideForPlayer(playerid,CajaTextConce[playerid]);
                    return 1;
                }
                new SQLId[12];
                mysql_fetch_row(SQLId);// lo que no entiendo
                InfoCoche[vehicleid][cSQLID] = strval(SQLId);// lo que no entiendo
                InfoCoche[vehicleid][cModelo] = GetVehicleModel(vehicleid);
                InfoCoche[vehicleid][cX] = -1640.9456;
                InfoCoche[vehicleid][cY] = 1216.0890;
                InfoCoche[vehicleid][cZ] = 7.0391;
                InfoCoche[vehicleid][cA] = 270;
                InfoCoche[vehicleid][cColor1] = color1;
                InfoCoche[vehicleid][cColor2] = color2;
                InfoCoche[vehicleid][cComprable] = 1;
                InfoCoche[vehicleid][cBloqueado] = 0;
                strmid(InfoCoche[vehicleid][cProp], VerNombreEx(playerid), 0, strlen(VerNombreEx(playerid)), 30);
                strmid(InfoCoche[vehicleid][cNombre], NombreCoche(GetPVarInt(playerid,"CocheConcesionario")), 0, strlen(NombreCoche(GetPVarInt(playerid,"CocheConcesionario"))), 40);
                InfoCoche[vehicleid][cFaccion] = 0;
                InfoCoche[vehicleid][cTrabajo] = 0;
                InfoCoche[vehicleid][cMulta] = 0;
                strmid(InfoCoche[vehicleid][cMultaRazon], "Ninguna", 0, 20, 30);
                strmid(InfoCoche[vehicleid][cMultaPor], "Nadie", 0, 30, 30);
                InfoCoche[vehicleid][cArma1] = 0;
                InfoCoche[vehicleid][cArma2] = 0;
                InfoCoche[vehicleid][cMun1] = 0;
                InfoCoche[vehicleid][cMun2] = 0;
                InfoCoche[vehicleid][cDrogas] = 0;
                InfoCoche[vehicleid][cEspacio] = 0;
                InfoCoche[vehicleid][cAlarma] = 0;
                InfoCoche[vehicleid][cGas] = 100;
                InfoCoche[vehicleid][cPaintJob] = 0;
                InfoCoche[vehicleid][cExpira] = 230;
                InfoCoche[vehicleid][cLegal] = 1;
                new plate[126];
                new randplate = random(999);
                format(plate, sizeof(plate), "LS%d", randplate);
                strmid(InfoCoche[vehicleid][cPlaca], plate, 0, 126, 128);
                SetPlayerPos(playerid, -1640.9456,1216.0890,7.0391);
                DarLlave(playerid,InfoCoche[vehicleid][cSQLID]);
                SetVehicleNumberPlate(vehicleid,InfoCoche[vehicleid][cPlaca]);
                SetVehicleToRespawn(vehicleid);
                PutPlayerInVehicle(playerid, vehicleid, 0);
                DarDinero(playerid, -CostoCoche(GetPVarInt(playerid,"CocheConcesionario")));
                TextDrawHideForPlayer(playerid,TextoConce[playerid]);
                TextDrawHideForPlayer(playerid,CajaTextConce[playerid]);
                GameTextForPlayer(playerid,"~w~Felicitaciones por tu compra~n~recuerda usar ~r~/v parquear~w~para parquear tu coche",5000,3);
                SendClientMessage(playerid,color_admin,"Felicitaciones ahora puedes prender tu coche");
                format(query,sizeof(query),"INSERT INTO coches (Id,Modelo,X,Y,Z,A,Color1,Color2,Comprable,Bloqueado,Propietario,Nombre,Faccion,Trabajo,Multa,MultaRazon,MultaPor,Arma1,Arma2,Mun1,Mun2,Drogas,Espacio,Alarma,Placa,Gas,PaintJob,Expira,Legal) VALUES (%d,%d,%f,%f,%f,%f,%d,%d,%d,%d,'%s','%s',%d,%d,%d,'%s','%s',%d,%d,%d,%d,%d,%d,%d,'%s',%d,%d,%d,%d)",
                InfoCoche[vehicleid][cSQLID],InfoCoche[vehicleid][cModelo], InfoCoche[vehicleid][cX], InfoCoche[vehicleid][cY], InfoCoche[vehicleid][cZ], InfoCoche[vehicleid][cA], color1, color2, InfoCoche[vehicleid][cComprable], InfoCoche[vehicleid][cBloqueado], InfoCoche[vehicleid][cProp], InfoCoche[vehicleid][cNombre], InfoCoche[vehicleid][cFaccion],
                InfoCoche[vehicleid][cTrabajo],InfoCoche[vehicleid][cMulta], InfoCoche[vehicleid][cMultaRazon], InfoCoche[vehicleid][cMultaPor], InfoCoche[vehicleid][cArma1], InfoCoche[vehicleid][cArma2], InfoCoche[vehicleid][cMun1], InfoCoche[vehicleid][cMun2], InfoCoche[vehicleid][cDrogas],
                InfoCoche[vehicleid][cEspacio], InfoCoche[vehicleid][cAlarma], InfoCoche[vehicleid][cPlaca], InfoCoche[vehicleid][cEspacio], InfoCoche[vehicleid][cAlarma], InfoCoche[vehicleid][cPlaca], InfoCoche[vehicleid][cGas], InfoCoche[vehicleid][cPaintJob], InfoCoche[vehicleid][cExpira], InfoCoche[vehicleid][cLegal]);
                mysql_query(query);
                mysql_query("SELECT MAX(Id) FROM coches");
                mysql_store_result();
                GuardarCoche(vehicleid);
                return strval(SQLId);
            }
            else SendClientMessage(playerid,color_rojo, "No estas comprando un coche!");
        }
        else
        {
            new mens[64];
            format(mens, sizeof mens, "Este coche cuesta $%d y tu solo tienes $%d!", CostoCoche(GetPVarInt(playerid,"CocheConcesionario")), VerDinero(playerid));
            SendClientMessage(playerid,color_rojo, mens);
        }
    }
    return 1;
}
Yo no escribi este codigo y me cuesta entender una parte que esta causando un problema. Lo que no entiendo es basicamente el sistema de id del auto. Que id le pone? Porque esa id? Creo que esta en esta parte.
pawn Код:
new SQLId[12];
                mysql_fetch_row(SQLId);
                InfoCoche[vehicleid][cSQLID] = strval(SQLId);
Y el problema es que cuando compras el auto le pone una id sin sentido. (Solo tenia 36 autos, entonces supuestamente tendria que tener la id 37 el proximo auto) pero no, compre dos autos y al primero le asigno la id 51, y la segunda vez que compre un auto, remplazo la linea en la base de datos ya que a este tambien le asigno la id 51.

A todo esto no entiendo porque la 51, ya que no entiendo esa parte del codigo jeje.
Reply
#2

InfoCoche[vehicleid][cSQLID] = strval(SQLId);// lo que no entiendo

Esto le dice al scrip que debe asignarle el id que esta en la variable SQLID.

mysql_fetch_row(SQLId);

Esto si no me equivoco es para que devuelva todo el contenido de la fila y lo almacene en SQLID

sobre tu problema trata de revisar en la base de datos estoy seguro que el problema esta en la tabla.

Perdon si no te puedo ayudar mucho tengo mucho tiempo retirado del pawn
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)