[HELP] Pickup mixing with each other!
#1

Hello!

I am doing missions for APB with item pickups, but I have one problem!
So, basicaly, when player pickups "mpickup" (stands for "mission pickup"), it sets random delivery point! When player dies, new item pickup called "dropickup" (stands for "dropped pickup") creates on player death position! BUT, when I want to pickup dropped item, it "mixes" with mission pickup (created on start of a mission) and again it randomly generates new delivery point and deleting old one! Here is the code:

pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == mpickup)
    {
        PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
        HasItem[playerid] = 1;
        SendClientMessage(playerid,GCOLOR_YELLOW,"MISSION: Item picked up! Now deliver it! (HELP: Delivery place is marked with checkpoint)");
        DestroyPickup(mpickup);
        MCP[playerid] = 1;
        new rand = random(sizeof(RandomMissionEndPos));
        SetPlayerCheckpoint(playerid, RandomMissionEndPos[rand][0], RandomMissionEndPos[rand][1], RandomMissionEndPos[rand][2],5);
        RemovePlayerMapIcon(playerid,0);
        return 1;
    }
    if(pickupid == dropickup)
    {
        PlayerPlaySound(playerid, 1056, 0.0, 0.0, 10.0);
        HasItem[playerid] = 1;
        SendClientMessage(playerid,GCOLOR_YELLOW,"MISSION: Item picked up!");
        DestroyPickup(dropickup);
        RemovePlayerMapIcon(playerid,0);
        return 1;
    }
    return 1;
}
pawn Код:
if(inMission[playerid] == 1)
    {
        if(HasItem[playerid] == 1)
        {
            RemovePlayerMapIcon(playerid,0);
            new Float:X;
            new Float:Y;
            new Float:Z;
            GetPlayerPos(playerid,X,Y,Z);
            dropickup = CreatePickup(1210,19,X,Y,Z,0);
            SetPlayerMapIcon(playerid,0,X,Y,Z,52,-1,MAPICON_GLOBAL);
            HasItem[playerid] = 0;
            SendClientMessage(playerid,GCOLOR_YELLOW,"MISSION: Item dropped!");
            return 1;
        }
    }
I dont know if this is script bug or SAMP bug!
Reply
#2

anyone??
Reply
#3

mpickup and dropickup are variables which hold numbers, the ids of the pickups
As said before they only hold these numbers and are not connected to the pickup itself
means that it could happen that the id which got hold in one of these variables will be created again

Just an easy example
pawn Код:
new
    pickup1 = CreatePickup(); // lets say this is pickupid 1
DestroyPickup(pickup1); // destroy pickup1, pickupid 1 is now unused
new
    pickup2 = CreatePickup(); // this would again create a pickup with the id 1
// now lets check for the pickups
if(pickup1 == 1) {
    // this code will get executed
    return 1;
}
if(pickup2 == 1) {
    // this not
    return 1;
}
What you could do now

1. Just set the variable under DestroyPickup to something invalid
pawn Код:
new
    pickup1 = CreatePickup();
DestroyPickup(pickup1);
pickup1 = -1; // sets the variable to something invalid
new
    pickup2 = CreatePickup();
if(pickup1 == 1) {
    return 1;
}
if(pickup2 == 1) {
    //  this code will get executed
    return 1;
}
2. Or you just write a constum function which does it for you
pawn Код:
// this code needs to be over the first usage of DestroyPickup! (important)
stock DestroyPickupFully(&pickupid) {
    if(DestroyPickup(pickupid)) {
        pickupid = -1;
        return true;
    }
    return false;
}
#define DestroyPickup DestroyPickupFully
pawn Код:
new
    pickup1 = CreatePickup();
DestroyPickup(pickup1); // destroy pickup1, additionally sets pickup1 to -1 within the function
new
    pickup2 = CreatePickup();
if(pickup1 == 1) {
    return 1;
}
if(pickup2 == 1) {
    //  this code will get executed
    return 1;
}
Reply
#4

Thanks man!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)