Create Gift Pickups OnPlayerDeath
#1

Hello,
im Having a Problem With Creating Gift Box's OnPlayerDeath.
ok im creating pickups onplayerdeath the first pickup works correect.

when i kill a guy a pickup appears on his location where he died. and i can pick it..

[PROBLEM]: when i kill a guy a Pickup Appears On His Location Where he Died. and im leaving his pickup im not picking it. and when i kill a guy again both pickups got bugged. both can't be picked

HERE IS MY CODE:

On Top
PHP код:
new GiftPickup[MAX_PLAYERS]; 
Under OnPlayerDeath( ... )
PHP код:
new Float:XFloat:YFloat:Z;
GetPlayerPos(playeridX,Y,Z);
GiftPickup[playerid] = CreatePickup(19054,8,X,Y,Z0); 
PHP код:
Under OnPlayerPickupPickup( ... )
if(
pickupid == GiftPickup[playerid])
{
//gifts
//merry xmas
DestroyPickup(GiftPickup);

Reply
#2

Hello,

Could you post the code?

Regards,
MD5
Reply
#3

i removed my code. b/c it dosent work can u give me a code?
Reply
#4

HERE IS MY CODE:

On Top
PHP код:
new GiftPickup[MAX_PLAYERS]; 
Under OnPlayerDeath( ... )
PHP код:
new Float:XFloat:YFloat:Z;
GetPlayerPos(playeridX,Y,Z);
GiftPickup[playerid] = CreatePickup(19054,8,X,Y,Z0); 
PHP код:
Under OnPlayerPickupPickup( ... )
if(
pickupid == GiftPickup[playerid])
{
//gifts
//merry xmas
DestroyPickup(GiftPickup);

Reply
#5

I can suggest. Adding a timer to OnplayerDeath Like
pawn Код:
SetTimerEx("RemoveGift", Time, false, "i", playerid);
And make a function like
pawn Код:
public RemoveGift
{
    DestroyPickup(GiftPickup);
    return 1;
}
And it should work.
Reply
#6

look how can i make pickups more than 1 in on variable GiftPickup.

b/c there willbe many players who die so pickups willbe bugged onevery player death there is
GiftPickup = CreatePickup( ... )

how can i make if players die new new pickups with new variables create
Reply
#7

Help?
Reply
#8

Since you're creating a pickup for every player that dies instead of using playerid here you should use a loop.

Код:
Under OnPlayerPickupPickup( ... ) 
if(pickupid == GiftPickup[playerid]) 
{ 
//gifts 
//merry xmas 
DestroyPickup(GiftPickup); 
}
Change that to

Код:
Under OnPlayerPickupPickup( ... )
for(new i = 0; i < MAX_PLAYERs; i++)
{
if(pickupid == GiftPickup[i]) 
{ 
//gifts 
//merry xmas 
DestroyPickup(GiftPickup); 
}
}
Reply
#9

pawn Код:
new GiftOwner[MAX_PICKUPS];
// OnGameModeInit
for(new i = 0; i < MAX_PICKUPS; i++)
{
    GiftOwner[i] = INVALID_PLAYER_ID;
}
// OnPlayerDeath
if(killerid != INVALID_PLAYER_ID)
{
    new pickupid = CreatePickup(19054,8,X,Y,Z, 0);
    GiftOwner[pickupid] = killerid;
}

// OnPlayerPickupPickup
if(GiftOwner[pickupid] != INVALID_PLAYERID && GiftOwner[pickupid] == playerid)
{
    // your code here
    GiftOwner[pickupid] = INVALID_PLAYER_ID;
    DestroyPickup(pickupid);
}
Reply
#10

Or alternatively, you could just make the pickup for each time a player is killed.

pawn Код:
new GiftPickup[MAX_PLAYERS];

public OnPlayerDeath(playerid, killerid, reason)
{
    if(killerid != INVALID_PLAYER_ID)
    {
        new Float:X, Float:Y, Float:Z;
        GetPlayerPos(playerid, X, Y, Z);
        if(GiftPickup[playerid] != -1)
        {
            DestroyPickup(GiftPickup[playerid]);
            GiftPickup[playerid] = -1;
        }
        GiftPickup[playerid] = CreatePickup(19054, 8, X, Y, Z, 0);
    }
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == GiftPickup[playerid]) return SendClientMessage(playerid, -1, "You cannot pickup the Gift that you dropped.");
    for(new i = 0; i < MAX_PLAYERS; i++) //Foreach is a better alternative.
    {
        if(!IsPlayerConnected(i) || i == playerid) continue; //Remove this line if using Foreach.
        if(pickupid != GiftPickup[i]) continue;
        //At this point, the player has picked up a Gift dropped by a player.
        SendClientMessage(playerid, -1, "You have picked up a Gift!");
        DestroyPickup(GiftPickup[i]);
        GiftPickup[i] = -1;
        break;
    }
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(GiftPickup[playerid] != -1)
    {
        DestroyPickup(GiftPickup[playerid]);
        GiftPickup[playerid] = -1;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)