spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
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?
Re: spawn random armor/health onplayerdeath -
Beckett - 12.11.2013
Yes it is, first of all get the player's XYZ on death, use CreatePickup, and when player picks it, he gets his benefits.
Re: spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
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%.
Re: spawn random armor/health onplayerdeath -
erminpr0 - 12.11.2013
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;
Re: spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
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 );
Re: spawn random armor/health onplayerdeath -
erminpr0 - 12.11.2013
try replacing to this..
pawn Код:
case pickUp:
{
new ranHel = random(30), Float:Healll;
GetPlayerHealth(playerid, Healll);
SetPlayerHealth( playerid, Healll + ranHel );
Re: spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
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!
Re: spawn random armor/health onplayerdeath -
Konstantinos - 12.11.2013
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;
}
Re: spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
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.
Re: spawn random armor/health onplayerdeath -
enzo27 - 12.11.2013
Bug: The first object won't destroy or can't be picked up. It should be removed.
Please I need help.