SA-MP Forums Archive
Pickups after Death! - 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: Pickups after Death! (/showthread.php?tid=318783)



Pickups after Death! - Twisted_Insane - 16.02.2012

Hi all!

So, I had the idea instead of givin' the player killing an enemy just money, giving him pickups! That means:
Player "X" killed player "Y", so when "Y" is dead, there should be a pickup near him (money), which the killer can pick up then! I don't know what to do, because there is a position needed! Do I have to do it like that?

PHP код:
OnGameModeInit() {
new 
Float:xFloat:yFloat:zFloat:angle;
    
GetPlayerPos(playeridxyz);
mypickup CreatePickup(12391xyz, -1); 
Also, I want that when a player picks that money up, he should get an random amount between 100 and 1000 dollar!


Re: Pickups after Death! - System64 - 16.02.2012

OnGameModeInit? U Mad?

pawn Код:
new DeathPickup;
public OnPlayerDeath(playerid, killerid, reason)
{
    new Float: Pos[3];
    GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
    DeathPickup = CreatePickup(1239, 1, Pos[0], Pos[1], Pos[2], -1);
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == DeathPickup)
    {
        //GiveMoney etc...
    }
    return 1;
}



Re: Pickups after Death! - Nonameman - 16.02.2012

EDIT: Improved the code that was here, see my next post in this topic.


Re: Pickups after Death! - Twisted_Insane - 16.02.2012

Sorry, was a little confused!
Okay, now I want that random-money, but this what I did is probably wrong, created an array, which gives me errors:

PHP код:
public OnPlayerPickUpPickup(playeridpickupid)
    {
        if(
pickupid == DeathPickup)
        {
               new 
RandomCash[][] =
            {
                
"100",
                
"200",
               
"300",
                
"400",
                
"500",
                
"600",
                
"700",
                
"800",
                
"900",
                
"1000"
               
}
                   
GivePlayerMoney(playeridRandomCash);
           }
        return 
1;
    } 



Re: Pickups after Death! - Nonameman - 16.02.2012

Try this, I didn't test it, but should work.

pawn Код:
#define MAX_DEATH_PICKUPS   10 // you can set here the amount of pickups that can exist at the same time
new DeathPickup[MAX_PLAYERS][MAX_DEATH_PICKUPS]; // tracking dropped pickups for killers
pawn Код:
public OnPlayerDeath(playerid, killerid, reason)
{
    new stck = -1;
    for (new p = 0; p < MAX_DEATH_PICKUPS; p++) {
        if (DeathPickup[killerid][p] != 0) continue; // only own death pickups can be picked up
        else {
            stck = p;
            break;
        }
    }
    if (stck != -1) { // if one or more stocks are free
        new Float:pPos[3];
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        DeathPickup[killerid][stck] = CreatePickup(1274, 1, pPos[0]+random(5), pPos[1]+random(5), pPos[2]);
    }
    return 1;
}
pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    for (new p = 0; p < MAX_DEATH_PICKUPS; p++) {
        if (pickupid != DeathPickup[playerid][p]) continue;
        DestroyPickup(pickupid);
        DeathPickup[playerid][p] = 0;
        GivePlayerMoney(playerid, random(900) + 100);
    }
    return 1;
}



Re: Pickups after Death! - Twisted_Insane - 16.02.2012

pawn Код:
new stck = -1;    for (new p = 0; p < MAX_DEATH_PICKUPS; p++) {        if (DeathPickup[killerid][p] != 0) continue; // only own death pickups can be picked up        else {            stck = p;            break;
Eh? I meant that whoever sees that pickup from the money can pick it up, not only myself!


Re: Pickups after Death! - Nonameman - 16.02.2012

Then:

pawn Код:
#define MAX_DEATH_PICKUPS   100

new DeathPickups[MAX_DEATH_PICKUPS] = 0;

public OnPlayerDeath(playerid, killerid, reason)
{
    new stck = -1;
    for (new p = 0; p < MAX_DEATH_PICKUPS; p++) {
        if (DeathPickups[p] != 0) continue;
        else {
            stck = p;
            break;
        }
    }
    if (stck != -1) {
        new Float:pPos[3];
        GetPlayerPos(playerid, pPos[0], pPos[1], pPos[2]);
        DeathPickups[stck] = CreatePickup(1274, 1, pPos[0]+random(5), pPos[1]+random(5), pPos[2]);
    }
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    for (new p = 0; p < MAX_DEATH_PICKUPS; p++) {
        if (pickupid != DeathPickups[p]) continue;
        DestroyPickup(pickupid);
        DeathPickups[p] = 0;
        GivePlayerMoney(playerid, random(900) + 100);
    }
    return 1;
}
I thought you want the pickups to be private.


Re: Pickups after Death! - Twisted_Insane - 16.02.2012

Dude, I think you're a bit confused! xD
First of all, why 0?
PHP код:
new DeathPickups[MAX_DEATH_PICKUPS] = 0
Secondly, why random positions?
PHP код:
DeathPickups[stck] = CreatePickup(12741pPos[0]+random(5), pPos[1]+random(5), pPos[2]); 



Re: Pickups after Death! - Nonameman - 16.02.2012

Quote:
Originally Posted by Twisted_Insane
Посмотреть сообщение
Dude, I think you're a bit confused! xD
First of all, why 0?
PHP код:
new DeathPickups[MAX_DEATH_PICKUPS] = 0
Secondly, why random positions?
PHP код:
DeathPickups[stck] = CreatePickup(12741pPos[0]+random(5), pPos[1]+random(5), pPos[2]); 
I'm not confused, it's 0, because the array stocks contain no death pickups when gamemode starts. And as you see, in the loop, script checks the for free slots to place a new one. So then more pickups can be exist at the same time and it will track all of them.

Secondly, the random values are because in normal GTA San Andreas money pickups appear around the place where npcs die and I wanted to make something like that.

+ You said:

Quote:
Originally Posted by Twisted_Insane
Посмотреть сообщение
there should be a pickup near him



Re: Pickups after Death! - Twisted_Insane - 16.02.2012

That there are different pickups around him is cool!

Lol, but there is a problem! I kill myself in the game (/kill), and when I go back to the position where I died at, there is a bottle! lol... I also get no money when I step into it! XD
Look at the pic! Wrong PickupID, or what?