SA-MP Forums Archive
Create Gift Pickups OnPlayerDeath - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Create Gift Pickups OnPlayerDeath (/showthread.php?tid=550777)



Create Gift Pickups OnPlayerDeath - danish007 - 14.12.2014

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);




Re: Create Gift Pickups OnPlayerDeath - MD5 - 14.12.2014

Hello,

Could you post the code?

Regards,
MD5


Re: Create Gift Pickups OnPlayerDeath - danish007 - 14.12.2014

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


Re: Create Gift Pickups OnPlayerDeath - danish007 - 14.12.2014

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);




Re: Create Gift Pickups OnPlayerDeath - mahdi499 - 14.12.2014

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.


Re: Create Gift Pickups OnPlayerDeath - danish007 - 14.12.2014

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


Re: Create Gift Pickups OnPlayerDeath - danish007 - 15.12.2014

Help?


Re: Create Gift Pickups OnPlayerDeath - Divergent - 15.12.2014

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); 
}
}



Re: Create Gift Pickups OnPlayerDeath - rickisme - 15.12.2014

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);
}



Re: Create Gift Pickups OnPlayerDeath - Threshold - 15.12.2014

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;
}