HELP WITH RANDOM PICKUPS SISTEM
#1

Hi guys, i want to make a sistem with hearts pickup , like an event .
So we have 2 hearts .
1 is good (Heart1), 1 is not(Heart2) . When a player enter in heart 1 is saying , the heart is good.
When a player enter in heart 2 is saying , the heart is bad. How can i make a switch between them ?I mean if we have 2 players ( Joe and Johnas) , the Heart is good for Joe but not for Johnas, how can i do this ?
Reply
#2

The whole "magic" is the "random" function.

pawn Код:
public OnPlayerPickUpPickup(playerid,pickupid)
{
    if(somepickup == pickupid)
    {
          switch(random(2)) // random(2) can produce either the number 0 or 1
          {
                   case 0: SendClientMessage(playerid,0xFF0000FF,"Sorry, the heart is bad");
                   case 1: SendClientMessage(playerid,0x00FF00FF,"Yeee this heart is cool and all");
          }
    }
}
Reply
#3

It's simple.
Assign an array like Heart1 to all create pickup lines which are for the good heart
And bring bad hearts under another array.

Under OnPlayerPickup
Check if pickupid = heart1 or heart2 and continue with the condition
Reply
#4

Quote:
Originally Posted by dusk
Посмотреть сообщение
The whole "magic" is the "random" function.

pawn Код:
public OnPlayerPickUpPickup(playerid,pickupid)
{
    if(somepickup == pickupid)
    {
          switch(random(2)) // random(2) can produce either the number 0 or 1
          {
                   case 0: SendClientMessage(playerid,0xFF0000FF,"Sorry, the heart is bad");
                   case 1: SendClientMessage(playerid,0x00FF00FF,"Yeee this heart is cool and all");
          }
    }
}
Your ideea is good ,but if i enter the heart once it's saying Yee this ... etc etc. , if i enter again it will say Sorry, the heart is bad, i want for playerid to be not good , so if u understand what i mean , If i am connected to server and my id is 39 , the Heart 1 is bad forever for me ( id 31) , but for another playerid is everytime good.
Reply
#5

Do something like

HeartType[MAX_PLAYERS];

Under Onplayerconnect

HeartType[playerid] = random(2);

Under your onplayerpickup
pawn Код:
If(pickupid == someid)
{
    If(HeartType(playerid)==0)
    {
         //Reduce health or whatever you want to do
    }
    Else
    {
        Code here
    }
}
Reply
#6

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
Your ideea is good ,but if i enter the heart once it's saying Yee this ... etc etc. , if i enter again it will say Sorry, the heart is bad, i want for playerid to be not good , so if u understand what i mean , If i am connected to server and my id is 39 , the Heart 1 is bad forever for me ( id 31) , but for another playerid is everytime good.
Oh, so how about you just set the player for whom the heart will be good as soon as you create it?
Reply
#7

pawn Код:
F:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(3582) : warning 205: redundant code: constant expression is zero
F:\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx : error 012: invalid function call, not a valid address
F:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(3584) : warning 215: expression has no effect
F:\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(3584) : error 001: expected token: ";", but found ")"
F:\xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(3584) : error 029: invalid expression, assumed zero
F:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(3584) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664          Copyright (c) 1997-2006, ITB CompuPhase


4 Errors.
My code:
pawn Код:
public OnPlayerPickUpPickup(playerid,pickupid)
{
    if(1240 == 1)
    {
        if(HeartType(playerid) == 0)
        {
         SendClientMessage(playerid, COLOR_GREY, "Bad");
        }
         else if(HeartType(playerid) == 1)
        {
         SendClientMessage(playerid, COLOR_GREY, "Good ");
        }
    }
    return 1;
}
Reply
#8

pawn Код:
if(1240 == 1)
This line of code is redudant. You don't need need the compiler to tell you that 1240 is NOT equal to 1, do you?

pawn Код:
new HeartPickup; // a global variable
new bool:IsHeartEventWinner[MAX_PLAYERS]; // a global array.

CMD:somevent(playerid,params[]) // you mentioned it should be like an event.
{
     if(IsPlayerAdmin(playerid)) // you probably don't want to let anyone create these events
     {
           SendClientMessageToAll(0xFF0000FF,"Some event has been started");
           HeartPickup = CreatePickup(1240, 1, x,y,z,-1); // change x,y,z to your positions
           IsHeartEventWinner[SelectRandomPlayer()] = true;
     }
     return 1;
}

public OnPlayerPickUpPickup(playerid,pickupid)
{
    if(pickupid == HeartPickup) // If its the heart pickup, not some other.
    {
            if(IsHeartEventWinner[playerid] == false)
            {
                   SendClientMessage(playerid,0xFF0000FF,"BAD");
            }
            else
            {
                   SendClientMessage(playerid,0x00FF00FF,"Good");
                   DestroyPickup(HeartPickup);
             }
    }
}

stock SelectRandomPlayer() // I found this function in forums.
{
     new random = Random(MAX_PLAYERS);
     if(IsPlayerConnected(random))
     {
           return random;
     }
     else
     {
           SelectRandomPlayer();
     }
}
Reply
#9

Dude i want to do a sistem like: We have 3 hearts , on player enter in the 3th heart the player wins.but he needs first to pickup heart 1 & heart2
Reply
#10

Ohhh so I misunderstood you from the very start....

Then it's actually easier.

pawn Код:
new HeartsCollected[MAX_PLAYERS], HeartPickups[3];

public OnGameModeInit()
{
   HeartPickups[0] = CreatePickup(.... first heart);
   HeartPickups[1] = CreatePickup(.... second heart);
   HeartPickups[2] = CreatePickup(... third heart);
}

public OnPlayerPickUpPickup(playerid,pickupid)
{
    if(HeartPickups[0] == pickupid)
    {
          SendClientMessage(playerid, 0xFF0000FF, "You collected the first  heart!");
          HeartsCollected[playerid] = 1;
          return 1;
    }
    if(HeartPickups[1] == pickupid)
    {
         SendClientMessage(playerid,0xFF0000FF,"You collected the second heart. Only one left...");
         HeartsCollected[playerid] = 2;
         return 1;
    }
    if(HeartPickups[2] == pickupid)
    {
           SendClientMessage(playerid,0x00FF00FF,"It's the third heart. You get something!");
           HeartsCollected[playerid] = 0; // Let's asign 0. Maybe you'll let him to do it again..
           // You should also set it to 0 when a player disconnects.
           return 1;
    }
    return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)