[DUDA] Eliminar objeto adherido a vehнculo
#1

Buenas, tengo unos objetos que se adhieren a un vehнculo por medio de presionar la tecla bloq. mayъs. pero lo que necesito saber es como eliminar el objeto cuando se presione de nuevo la tecla mencionada.

pawn Код:
/// otras key mas arriba
if (newkeys & KEY_SUBMISSION)
    {
        if (IsPlayerInVehicle(playerid, sunrise1) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
             AttachObjectToVehicle(myobject, sunrise1, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
        }
        if (IsPlayerInVehicle(playerid, sunrise2) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
             AttachObjectToVehicle(myobject, sunrise2, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
        }
        if (IsPlayerInVehicle(playerid, sunrise3) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //DestroyObject(myobject);
        {
             AttachObjectToVehicle(myobject, sunrise3, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
        }
    }
// otras key mбs abajo
Creo recordar que leн algo de if (pressed) o algo asн. Y de esa forma poder eliminar el objeto.
Reply
#2

pawn Код:
new TieneObjeto[MAX_PLAYERS];//arriba de tu gm

if (newkeys & KEY_SUBMISSION)//en la callback
{
    if (IsPlayerInVehicle(playerid, sunrise1) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(TieneObjeto[playerid] == false)
        {
            AttachObjectToVehicle(myobject, sunrise1, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
            TieneObjeto[playerid] = true;
        }
        if(TieneObjeto[playerid] == true)
        {
            DestroyObject(myobject);
            TieneObjeto[playerid] = false;
        }
    }
    if (IsPlayerInVehicle(playerid, sunrise2) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
    {
        if(TieneObjeto[playerid] == false)
        {
            AttachObjectToVehicle(myobject, sunrise2, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
            TieneObjeto[playerid] = true;
        }
        if(TieneObjeto[playerid] == true)
        {
            DestroyObject(myobject);
            TieneObjeto[playerid] = false;
        }
    }
    if (IsPlayerInVehicle(playerid, sunrise3) && gTeam[playerid] == TEAM_FBI && GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //DestroyObject(myobject);
    {
        if(TieneObjeto[playerid] == false)
        {
            AttachObjectToVehicle(myobject, sunrise3, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
            TieneObjeto[playerid] = true;
        }
        if(TieneObjeto[playerid] == true)
        {
            DestroyObject(myobject);
            TieneObjeto[playerid] = false;
        }
    }
}
Con una variable booleana se puede hacer, arriba te lo deje echo (:
Reply
#3

Me da estas advertencias:

Код:
pwn(7520) : warning 213: tag mismatch
pwn(7525) : warning 213: tag mismatch
pwn(7533) : warning 213: tag mismatch
pwn(7538) : warning 213: tag mismatch
pwn(7546) : warning 213: tag mismatch
pwn(7551) : warning 213: tag mismatch
En todas estas lнneas:

pawn Код:
if(TieneObjeto[playerid] == false)
Reply
#4

Sorry olvide poner el tag a la variable, reemplaza
pawn Код:
new TieneObjeto[MAX_PLAYERS];
por
pawn Код:
new bool:TieneObjeto[MAX_PLAYERS];
Reply
#5

la respuesta mas simple a tu pregunta era... simplemente DestroyObject
Reply
#6

Quote:
Originally Posted by bytytus
Посмотреть сообщение
la respuesta mas simple a tu pregunta era... simplemente DestroyObject
ya se soluciono la duda y/o problema, no era ese el objetivo? xd
Reply
#7

Quote:
Originally Posted by NeuZz
Посмотреть сообщение
ya se soluciono la duda y/o problema, no era ese el objetivo? xd
te parece ke fue correcta la solucion?

Respuesta correcta:

pawn Код:
#include <a_samp>

new bool:TieneObjeto[MAX_VEHICLES]=false;
new ObjetoVeh[1];

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
    switch(newkeys) {
        case KEY_SUBMISSION: {
            new vehicleid = GetPlayerVehicleID(playerid);
            if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER) return true;
            switch(gTeam[playerid]) {
                case TEAM_FBI: {
                    switch(TieneObjeto[vehicleid]) {
                        case false: {
                            TieneObjeto[vehicleid = true;
                            AttachObjectToVehicle(ObjetoVeh[0], vehicleid, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
                        }
                        case true: {
                            TieneObjeto[vehicleid = false;
                            DestroyObject(ObjetoVeh[0]);
                        }
                    }
                }
            }
        }
    }
    return true;
}
sino te parece, dime por ke, porfavor?.
Reply
#8

La primera no funciono.

Y la que hizo bytytus me dio mas warnings y errores que nunca.
Reply
#9

Quote:
Originally Posted by Matthias134
Посмотреть сообщение
La primera no funciono.

Y la que hizo bytytus me dio mas warnings y errores que nunca.
te habra tirado warnings por ke habras copiado y pegado,

modificalo con tus variables , etc.

Saludos.
Reply
#10

: okay :

Ahora lo ordene y funciono el cуdigo, ahora probarй en juego, edito para ver si funciona.

EDIT: No funciona!

Ahora lo edite un poco y quedo asн

pawn Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys){
switch(newkeys) {
    case KEY_SUBMISSION: {
        if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER) return true;
        switch(gTeam[playerid]) {
            case TEAM_FBI: {
                switch(TieneObjeto[sunrise1]) {
                    case false: {
                        TieneObjeto[sunrise1] = true;
                        AttachObjectToVehicle(myobject, sunrise1, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
                    }
                    case true: {
                        TieneObjeto[sunrise1] = false;
                        DestroyObject(ObjetoVeh[0]);
                    }
                }
                switch(TieneObjeto[sunrise2]) {
                    case false: {
                        TieneObjeto[sunrise2] = true;
                        AttachObjectToVehicle(ObjetoVeh[0], sunrise2, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
                    }
                    case true: {
                        TieneObjeto[sunrise2] = false;
                        DestroyObject(ObjetoVeh[0]);
                    }
                }
                switch(TieneObjeto[sunrise3]) {
                    case false: {
                        TieneObjeto[sunrise3] = true;
                        AttachObjectToVehicle(ObjetoVeh[0], sunrise3, -0.599999,0.075000,0.750000,0.000000,0.000000,0.000000);
                    }
                    case true: {
                        TieneObjeto[sunrise1] = false;
                        DestroyObject(ObjetoVeh[0]);
                    }
                }
            }
        }
    }
}
if(newkeys == KEY_SECONDARY_ATTACK)
{
/// ================ ENTRAR A LA COMISARIA - ENTRADA PRINCIPAL //
if (PlayerToPoint(2.0, playerid,-1605.5000000,711.7000122,13.8999996) && GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
{
SetPlayerPos(playerid, 246.3000031,108.0999985,1003.0000000);
SetPlayerInterior(playerid, 10);
}

/// muchas cosas para allб, lol

Me podriбs explicar ademбs que es ObjetoVeh[0], intentй probar en una con 'myobject' pero tampoco funcionу.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)