Dropping Money
#1

How to do a script if a player has $3000 on hand and he/she get killed his/her money will be dropped and can be get by another player by : pass by and he/she will get it.. i will give +rep
Reply
#2

Check the money OnPlayerDeath and if its == 3000 you can create a pickup, give it an ID and reward the player who picks up the pickup.
Reply
#3

On top of your script:
Код:
new cash_pickup;
On your OnPlayerDeath:
Код:
if(GetPlayerMoney(playerid) > 3000) { // Player that died has more than 3000$ 
GivePlayerMoney(playerid, -3000); // Take 3000 from their money.
new Float:x, Float:y, Float:z; // A place to store the place to create the pickup
GetPlayerPos(playerid, x,y,z); // Get their x,y and z to create the pickup on
cash_pickup = CreatePickup(1212, 5, x,y,z, -1); // Creates a pickup on the location where the player died. this 
pickup will disappear after some time
On your OnPlayerPickUpPickup:
Код:
if(pickupid == cash_pickup) {
GivePlayerMoney(playerid, 3000); // note: all players can pickup this pickup. Other players can take your cash reward.
}
Not tested.
Reply
#4

Quote:
Originally Posted by EpicDutchie
Посмотреть сообщение
On top of your script:
Код:
new cash_pickup;
On your OnPlayerDeath:
Код:
if(GetPlayerMoney(playerid) > 3000) { // Player that died has more than 3000$ 
GivePlayerMoney(playerid, -3000); // Take 3000 from their money.
new Float:x, Float:y, Float:z; // A place to store the place to create the pickup
GetPlayerPos(playerid, x,y,z); // Get their x,y and z to create the pickup on
cash_pickup = CreatePickup(1212, 5, x,y,z, -1); // Creates a pickup on the location where the player died. this 
pickup will disappear after some time
On your OnPlayerPickUpPickup:
Код:
if(pickupid == cash_pickup) {
GivePlayerMoney(playerid, 3000); // note: all players can pickup this pickup. Other players can take your cash reward.
}
Not tested.
How if he/she has 3000++ money like 1million then only 3000 will be dropped ? i want if he has 3000+ then all of his money will be dropped
Reply
#5

I've made EpicDutchie's code abit more clear and changed it abit with my own input. He explained most things already so I've left out the comments. This should work, but I highly advise you to store all the dropped money values in to an array because doing it the way I did it will basically create a pickup with the last player's dropped money. You could also make an array of pickupids and use a loop to count through the existing pickupids so you can prevent overwriting them.

Anywho, this is the code (sorry for it not being entirely efficient, but it should give you a good idea on how to do it):

pawn Код:
new cash_pickup;
new pickupcash;

new pmoney[MAX_PLAYERS];

public OnPlayerSpawn(playerid)
{
    // We put pmoney to zero because OnPlayerSpawn gets called after OnPlayerDeath
    // This is just to prevent abuse but you may not even need this.

    pmoney[playerid] = 0;

    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    new Float:x, Float:y, Float:z;

    if(GetPlayerMoney(playerid) > 3000)
    {
        pickupcash = pmoney[playerid];

        pmoney[playerid] = GetPlayerMoney(playerid);
        GetPlayerPos(playerid, x,y,z);
   
        cash_pickup = CreatePickup(1212, 5, x,y,z, -1);
        GivePlayerMoney(playerid, -pmoney[playerid]);
    }
   
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == cash_pickup)
    {
        GivePlayerMoney(playerid, pickupcash);
    }

    return 1;
}
Reply
#6

This script has a problem - if two players die at nearly the same time, the pickup created for the player who died FIRST will get abandoned and the player picking it up will not get any cash. So you need an array.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)