[Ayuda] Con Vehiculos...
#1

Buenas a Todos, cree vehiculos con AddStaticVehicleEx y los defini con variables con sus array correspondiente, y coloke en un stock un for para chekear los array y lo coloke en un if en OnPlayerEnterVehicle para ke chekee si es el vehiculo correspondiente y si el player tiene la variable correspondiente para subirse si no lo sacara del vehiculo, pero no se ke estoy haciendo mal ke no me funciona :S

pawn Код:
public OnFilterScriptInit()
{
    variablevehiculo[0] = AddStaticVehicleEx(...);
    variablevehiculo[1] = AddStaticVehicleEx(...);
    variablevehiculo[2] = AddStaticVehicleEx(...);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(verificarvehiculo(vehicleid))
    {
        if(variable[playerid] != true)
        {
            SendClientMessage(playerid, -1, "no puedes subir al vehiculo");
            RemovePlayerFromVehicle(playerid);
        }
        return 0;
    }
    return 1;
}

stock verificarvehiculo(vehicleid)
{
    for(new index=0; index<3; index++)
    {
        if(vehicleid == variablevehiculo[index]) return 1;
    }
    return 1;
}
desde ya muchas Gracias .
Reply
#2

pawn Код:
stock verificarvehiculo(vehicleid)
{
    for(new index; index<3; index++)
    {
        if(vehicleid == variablevehiculo[index]) return 1;
    }
    return 1;
}
?
Reply
#3

Quote:
Originally Posted by Lunnatiicz
Посмотреть сообщение
pawn Код:
stock verificarvehiculo(vehicleid)
{
    for(new index; index<3; index++)
    {
        if(vehicleid == variablevehiculo[index]) return 1;
    }
    return 1;
}
?
ke ?

hay esta haciendo esto, ke tampoco anda, va si anda pero para todosl os vehiculos y no para los vehiculos ke esta definido con la variable :S

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger)
    {
        if(vehicleid == variablevehiculo[0] || variablevehiculo[1] || variablevehiculo[2] && variable[playerid] != true)
        {
            SendClientMessage(playerid, -1, "no puedes subir al vehiculo");
            RemovePlayerFromVehicle(playerid);
            return 0;
        }
    }
    return 1;
}
Reply
#4

No me doy la idea de porquй seteaste a 0 la variable en el loop.

pawn Код:
for(new index=0; index<3; index++)
Reply
#5

Quote:
Originally Posted by Lunnatiicz
Посмотреть сообщение
No me doy la idea de porquй seteaste a 0 la variable en el loop.

pawn Код:
for(new index=0; index<3; index++)
new variablevehiculo[3]; //se le suma un array y keda 3

variablevehiculo[0] = AddStaticVehicleEx(...); //0
variablevehiculo[1] = AddStaticVehicleEx(...); //1
variablevehiculo[2] = AddStaticVehicleEx(...); //2

for(new index=0; index<3; index++)

pero el codigo esta bien, son los operadores ke no me responden , me responden arrevez o_O
Reply
#6

Ah vale, porquй dices que te responden al contrario?
Reply
#7

Quote:
Originally Posted by Lunnatiicz
Посмотреть сообщение
Ah vale, porquй dices que te responden al contrario?
if(vehicleid == variablevehiculo[0] || variablevehiculo[1] || variablevehiculo[2] && variable[playerid] != true)

if(idel del vehiculo == al AddStaticVehicleEx o al AddStaticVehicleEx o al AddStaticVehicleEx con la variable

hay no me deja entrar al vehiculo si no tengo la variable y si le doy la variable al player me deja, pero es para todos los vehiculos y deberia ser solo para los ke estan definidos con las variables ke estan en el if nada mas .

ah y si intento con una sola variable en if si me funciona perfectamente, osea e problema es en los operadores ||
y intente con && como ya me habia pasado en otro post pero nada sigue igual :S :
Reply
#8

En Onplayerstatecheange
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_PASSENGER)
    {
          if( GetPlayerVehicleID(playerid) == variablevehiculo[0] || GetPlayerVehicleID(playerid) == variablevehiculo[1] || GetPlayerVehicleID(playerid) == variablevehiculo[2] || GetPlayerVehicleID(playerid) == variablevehiculo[3])
{
funciones
}
}
Reply
#9

Quote:
Originally Posted by adri1
Посмотреть сообщение
En Onplayerstatecheange
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_PASSENGER)
    {
          if( GetPlayerVehicleID(playerid) == variablevehiculo[0] || GetPlayerVehicleID(playerid) == variablevehiculo[1] || GetPlayerVehicleID(playerid) == variablevehiculo[2] || GetPlayerVehicleID(playerid) == variablevehiculo[3])
{
funciones
}
}
ha hay me di cuenta esta incompleto el if xD
Gracias .

EDIT:

Sigue Igual , el problema esta cuando coloco mas variables con el operador || , cuando lo coloco pasa la funcion a todosl os vehiculos :S
Reply
#10

Esto no tiene mucha ciencia, pero confunde, te haces un lнo con todas las IDs y demбs.
Antes que nada veo que usas una array para almacenar las IDs de los vehнculos. Hagamos una funciуn que diga si estбs en uno de esos vehнculos almacenados en la array.
pawn Код:
stock VerificarVehiculo(playerid, vehicleid) {
    if (!IsPlayerInAnyVehicle(playerid)) return 0;
    for (new x = 0; x <= 3; x++) { //<= 3 -> tenemos 4 vehнculos. new array[4]; (array[0], array[1], array[2], array[3])
        if (GetPlayerVehicleID(playerid) == variablevehiculo[x]) {
            break;
            return 1; //Devolvemos verdadero si la ID conincide con alguna de las IDs que contiene la array.
        }
    }
    return 0;
}
Ya que tenemos eso. Siguiendo tu script serнa asн:
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(!ispassenger)
    {
        if(VerificarVehiculo(playerid, vehicleid)) //Uso de la funciуn.
        {
            if (variable[playerid] != true) {
                SendClientMessage(playerid, -1, "No puedes subir al vehнculo!");
                RemovePlayerFromVehicle(playerid);
            }
        }
    }
    return 1;
}
Pero hay un problema, en OnPlayerEnterVehicle devuelvas lo que devuelvas, no tendrб ningъn efecto. Y el RemovePlayerFromVehicle aquн no funcionarб. Esta callback se llama cuando el jugador EMPIEZA a subir al vehнculo, cuando inicia la animaciуn. O sea que si estбs a 5 metros del coche y das F este script se llamarб mientras el jugador se acerca al vehнculo especifico.

Tendrбs que usar este script en OnPlayerStateChange.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)