12.11.2013, 18:11
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?
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;
Try this.. (re-optimize the code)
pawn Код:
|
(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"
case pickUp: { new ranHel = random(30), new Float:Healll; GetPlayerHealth(playerid, Healll); SetPlayerHealth( playerid, Healll + ranHel );
case pickUp:
{
new ranHel = random(30), Float:Healll;
GetPlayerHealth(playerid, Healll);
SetPlayerHealth( playerid, Healll + ranHel );
try replacing to this..
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;
}
I'd use it like that:
pawn Код:
|