Ayuda armas al subirse en un auto
#1

Hola, me he dado cuenta de que tengo un pequeсo problema, que algunos jugadores tambien se podrian aprovechar de aquello, explico: Si un jugador tiene alguna metralletadora e ingresa a un vehiculo como conductor este podria disparar desde dentro del vehiculo, y si un jugador tiene una desert, o una recortada, o una M4 y se sube como PASAJERO tambien puede disparar, sobre todo si se sube con la desert, ya que con la desert al estar como pasajero y apretar la letra "H" para disparar como co-piloto la desert dispara muy muy rapido. Entonces me gustaria saber si es que hay alguna posibilidad de esquivar eso. Estoy pensando en crear unas variables almacenadoras de armas, que el jugador al subir al auto se le guarden las armas y municiones que posea en una variable y al bajar del auto tenga las mismas armas y con las mismas cantidades de municion que poseai al igual que cuando entro.

No se si es posible hacer aquello, pero estoy viendo unos codigos para saber como hacerlo y la verdad no tengo idea de las variables con arrays y ese estilo de cosas D:

Saludos y gracias xd
Reply
#2

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        if(GetPlayerWeapon(playerid) == 24) // 24 = ID de la desert...
        {
            SetPlayerArmedWeapon(playerid, 0);
        }
    }
    return 1;
}
Reply
#3

D:, muchisimas gracias me sirvio :P
Reply
#4

https://sampforum.blast.hk/showthread.php?tid=335149
Reply
#5

Quote:
Originally Posted by bytytus
Посмотреть сообщение
eso te daria un terrible lag es mejor la opcion de BullShot saludos
Reply
#6

Quote:
Originally Posted by Shiny_David
Посмотреть сообщение
eso te daria un terrible lag es mejor la opcion de BullShot saludos
El cуdigo anteriormente posteado pertenece a Jovanny.
Reply
#7

Quote:
Originally Posted by Shiny_David
Посмотреть сообщение
eso te daria un terrible lag es mejor la opcion de BullShot saludos
De hecho eso no daria tanto lag, aun que esta lejos de ser el mejor codigo.

Aca un buen ejemplo:
pawn Код:
new bool:Driving[MAX_PLAYERS], Weapons[MAX_PLAYERS][13][2];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        for(new i; i<13; i++)
        {
            GetPlayerWeaponData(playerid, i, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        Driving[playerid] = true;
    }
    else if(Driving && (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER))
    {
        for(new i; i<13; i++)
        {
            GivePlayerWeapon(playerid, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        Driving[playerid] = false;
    }
    return 1;
}
Reply
#8

Quote:
Originally Posted by the_chaoz
Посмотреть сообщение
De hecho eso no daria tanto lag, aun que esta lejos de ser el mejor codigo.

Aca un buen ejemplo:
pawn Код:
new bool:Driving[MAX_PLAYERS], Weapons[MAX_PLAYERS][13][2];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        for(new i; i<13; i++)
        {
            GetPlayerWeaponData(playerid, i, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        Driving[playerid] = true;
    }
    else if(Driving && (newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER))
    {
        for(new i; i<13; i++)
        {
            GivePlayerWeapon(playerid, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        Driving[playerid] = false;
    }
    return 1;
}
Eso no funcionara, simplemente por que no le remueves las armas y por que la segunda condicion JAMAS se cumplira, ademas no se necesita quitarle las armas, solo con cambiar el arma equipada basta

EJ un poco mas avanzado
pawn Код:
new ForbiddenWeapons[] =
{
    24, // Desert Eagle
    26, // Recortadas o Sawnoff Shotgun
    31 // M4
};

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new WeaponID = GetPlayerWeapon(playerid);
        for(new i; i < sizeof(ForbiddenWeapons); i++) if(WeaponID == ForbiddenWeapons[i])
        {
            SetPlayerArmedWeapon(playerid, 0);
            break;
        }
    }
    return 1;
}
Reply
#9

Quote:
Originally Posted by Jovanny
Посмотреть сообщение
Eso no funcionara, simplemente por que no le remueves las armas y por que la segunda condicion JAMAS se cumplira, ademas no se necesita quitarle las armas, solo con cambiar el arma equipada basta

EJ un poco mas avanzado
pawn Код:
new ForbiddenWeapons[] =
{
    24, // Desert Eagle
    26, // Recortadas o Sawnoff Shotgun
    31 // M4
};

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        new WeaponID = GetPlayerWeapon(playerid);
        for(new i; i < sizeof(ForbiddenWeapons); i++) if(WeaponID == ForbiddenWeapons[i])
        {
            SetPlayerArmedWeapon(playerid, 0);
            break;
        }
    }
    return 1;
}
Si el jugador tiene una tec9 y puсo entra al coche con la tec9 seleccionada le va a cambiar al puсo, pero si entra con el puсo seleccionado le va a cambiar el arma a la tec9.
Y si una ves dentro del auto pone /tec9 y le da una tec9.
Si no es verdad, explнcame el cуdigo por hay no lo entendн bien
Reply
#10

Quote:
Originally Posted by Jovanny
Посмотреть сообщение
Eso no funcionara, simplemente por que no le remueves las armas y por que la segunda condicion JAMAS se cumplira, ademas no se necesita quitarle las armas, solo con cambiar el arma equipada basta
Se nota q estaba algo cansado cuando lo scriptie y debido a que OnPlayerStateChange admite un bug en el cual uno podria cambiar el arma luego de que este callback sea llamado (creditos por el bug al lag), podria ser que tu codigo falle, por eso lo mejor es remover y volver a dar las armas al jugador.

Codigo arreglado:
pawn Код:
new bool:Driving[MAX_PLAYERS], Weapons[MAX_PLAYERS][13][2];

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER)
    {
        for(new i; i<13; i++)
        {
            GetPlayerWeaponData(playerid, i, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        ResetPlayerWeapons(playerid);
        Driving[playerid] = true;
    }
    else if(Driving[playerid] && (newstate == PLAYER_STATE_ONFOOT))
    {
        for(new i; i<13; i++)
        {
            GivePlayerWeapon(playerid, Weapons[playerid][i][0], Weapons[playerid][i][1]);
        }
        Driving[playerid] = false;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)