spawn random armor/health onplayerdeath
#1

Well I had this idea, if a player dies then spawn under his dead body a armor or health object and when you pick it up it will give you 5% to %30 armor or health. Is this possible?
Reply
#2

Yes it is, first of all get the player's XYZ on death, use CreatePickup, and when player picks it, he gets his benefits.
Reply
#3

Quote:
Originally Posted by DaniceMcHarley
Посмотреть сообщение
Yes it is, first of all get the player's XYZ on death, use CreatePickup, and when player picks it, he gets his benefits.
Thanks for reply. I know I can do the CreatePick but I don't know how to give random health or armor+ random value that it will not go down 5% and go up 30%.
Reply
#4

Try this.. (re-optimize the code)
pawn Код:
new createdPickups = 0;
new pickUp[10];

public OnPlayerDeath(playerid, killerid, reason)
{
   new Float:pos[3];

   GetPlayerPos(playerid, pos[0], pos[1], pos[2]);

   pickUp[createdPickups] = CreatePickup(1240, 1, pos[0], pos[1], pos[2], GetPlayerVirtualWorld(playerid));

   createdPickups ++;
 
   return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
   switch( pickupid )
       case pickUp:
          new ranHel = random(30), new Float:Healll;
              GetPlayerHealth(playerid, Healll);
                  SetPlayerHealth( playerid, Healll + ranHel );
   return 1;
Reply
#5

Quote:
Originally Posted by erminpr0
Посмотреть сообщение
Try this.. (re-optimize the code)
pawn Код:
new createdPickups = 0;
new pickUp[10];

public OnPlayerDeath(playerid, killerid, reason)
{
   new Float:pos[3];

   GetPlayerPos(playerid, pos[0], pos[1], pos[2]);

   pickUp[createdPickups] = CreatePickup(1240, 1, pos[0], pos[1], pos[2], GetPlayerVirtualWorld(playerid));

   createdPickups ++;
 
   return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
   switch( pickupid )
       case pickUp:
          new ranHel = random(30), new Float:Healll;
              GetPlayerHealth(playerid, Healll);
                  SetPlayerHealth( playerid, Healll + ranHel );
   return 1;
Код:
(2446) : error 008: must be a constant expression; assumed zero
(2448) : error 001: expected token: "-identifier-", but found "new"
(2449) : error 017: undefined symbol "Healll"
(2450) : error 017: undefined symbol "Healll"
Line

Код:
		case pickUp:
     {
			new ranHel = random(30), new Float:Healll;
   			GetPlayerHealth(playerid, Healll);
			SetPlayerHealth( playerid, Healll + ranHel );
Reply
#6

try replacing to this..
pawn Код:
case pickUp:
     {
            new ranHel = random(30), Float:Healll;
            GetPlayerHealth(playerid, Healll);
            SetPlayerHealth( playerid, Healll + ranHel );
Reply
#7

Quote:
Originally Posted by erminpr0
Посмотреть сообщение
try replacing to this..
pawn Код:
case pickUp:
     {
            new ranHel = random(30), Float:Healll;
            GetPlayerHealth(playerid, Healll);
            SetPlayerHealth( playerid, Healll + ranHel );
Last warning man

error 008: must be a constant expression; assumed zero

line

case pickUp:

thanks for the reply!
Reply
#8

I'd use it like that:
pawn Код:
// global variable:
new
    bool: RandomPickup_HealthArmour[ MAX_PLAYERS char ], // false = health and true = armour (saving space)
    RandomPickup
;

// When a player dies (get the position and set the as the coordinates of the pickup):
new
    r_health_armour = random( 2 )
;
if( !r_health_armour )
{
    RandomPickup_HealthArmour{ playerid } = false; // Health
    // Create health pickupid:
    RandomPickup = CreatePickup( ... ); // EDIT THE LINE
}
else
{
    RandomPickup_HealthArmour{ playerid } = true; // Armour
    // Create armour pickupid:
    RandomPickup = CreatePickup( ... ); // EDIT THE LINE
}

// When a player pickups the pickup:
if( pickupid == RandomPickup )
{
    new
        Float: amount
    ;
    if( !RandomPickup_HealthArmour{ playerid } ) // health pickupid
    {
        GetPlayerHealth( playerid, amount );
        SetPlayerHealth( playerid, amount + RandomEx( 5, 30 ) );
    }
    else
    {
        GetPlayerArmour( playerid, amount );
        SetPlayerArmour( playerid, amount + RandomEx( 5, 30 ) );
    }
    DestroyPickup( RandomPickup );
}

// the random function for 5-30 percent
stock RandomEx( min, max ) //By ******
{
    return random( max - min ) + min;
}
Reply
#9

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
I'd use it like that:
pawn Код:
// global variable:
new
    bool: RandomPickup_HealthArmour[ MAX_PLAYERS char ], // false = health and true = armour (saving space)
    RandomPickup
;

// When a player dies (get the position and set the as the coordinates of the pickup):
new
    r_health_armour = random( 2 )
;
if( !r_health_armour )
{
    RandomPickup_HealthArmour{ playerid } = false; // Health
    // Create health pickupid:
    RandomPickup = CreatePickup( ... ); // EDIT THE LINE
}
else
{
    RandomPickup_HealthArmour{ playerid } = true; // Armour
    // Create armour pickupid:
    RandomPickup = CreatePickup( ... ); // EDIT THE LINE
}

// When a player pickups the pickup:
if( pickupid == RandomPickup )
{
    new
        Float: amount
    ;
    if( !RandomPickup_HealthArmour{ playerid } ) // health pickupid
    {
        GetPlayerHealth( playerid, amount );
        SetPlayerHealth( playerid, amount + RandomEx( 5, 30 ) );
    }
    else
    {
        GetPlayerArmour( playerid, amount );
        SetPlayerArmour( playerid, amount + RandomEx( 5, 30 ) );
    }
    DestroyPickup( RandomPickup );
}

// the random function for 5-30 percent
stock RandomEx( min, max ) //By ******
{
    return random( max - min ) + min;
}
Its working nice. Really nice and additional how to add label on the pickup object sample: "Health Bonus + 7" or
"Armour Bonus +23"? and destroy the label after player pick up the object.
Reply
#10



Bug: The first object won't destroy or can't be picked up. It should be removed.


Please I need help.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)