Vice City Multiplayer

VC:MP 0.3 => mIRC/pawn Scripting => Topic started by: Pain on March 16, 2013, 10:36:25 am

Title: 【Help】OnPickedUp is not working
Post by: Pain on March 16, 2013, 10:36:25 am
OnPickedUp is not working
If picked up health will have $ 500
but don‘t have $ 500
Title: Re: 【Help】OnPickedUp is not working
Post by: Doom on March 16, 2013, 11:44:44 am
Create a global variable.

Code: [Select]
new hpickup;
put in gamemodeinit

Code: [Select]
hpickup = AddStaticPickup(366, 1, x, y, z ); //Make sure you modify it to the location you want that pickup
add this on pickeduppickup

Code: [Select]
public OnPickedUp(pickupid, playerid)
{
if(pickupid == hpickup)
         {
             new Float:cash;
             cash = GetPlayerMoney(playerid);
             if(cash < 500 )
             {
                SendClientMessage(playerid, -1, "You don't have enough cash to use this heal pickup");
                return 0;
             }
             else if( cash >= 500 )
             {
                GivePlayerMoney(playerid, -500);
                SendClientMessage(playerid, -1, "You have been healed");
             }
   }
return 1;
}
Title: Re: 【Help】OnPickedUp is not working
Post by: NeskWriter on March 16, 2013, 01:06:55 pm
in OnGameModeInit:
[pawn]    AddStaticPickup(5, 431, X, Y, Z); // we have added pickup with id 5 and it's modelid - 431. Add your X, Y, Z coords[/pawn]

in OnPickedUp:
[pawn]
   if(pickupid==5) // we check if pickup's id is 5.
   {
      new pcash = GetPlayerMoney(playerid); // we get player money though "pcash" variable.
      new Float:hp; // we create a new float - hp.
      GetPlayerHealth(playerid, hp); // we get player health, expressing it in "hp" which we created before.
      if(hp < 100) // we check if player's hp < 100, this'll let us heal him only if his health's not 100.
      {
          if(pcash < 500) // we check if player doesn't have enough money ($500)
          {
              new str[256]; // if he's not, we make a new string,
              format(str, sizeof(str), "You don't have $500. You got only $%d", pcash); // we set the 1st string format
              SendClientMessage(playerid, 0xFF0000AA, str); // we send him formated string, which explains him that he's bum
          }
          else // else ( it means if he's got $500)
          {
              SetPlayerHealth(playerid, 100); // we set his health to 100 (restore).
              SetPlayerMoney(playerid, pcash - 500); // we take a bit of his cash.
              new str2[256]; // we make a new string, now "str2".
              format(str2, sizeof(str2), "You have been healed for $500. You got now $%d", pcash - 500); // we set it's format.
              SendClientMessage(playerid, 0xFFFFFFAA, str2); // we send him the 2nd formated string, which says that we healed him and took $500 from his pocket :)
          }
          return 1;
      } // we lock the condition which calls function if he's got enough money or he's not.
      else // else if his hp's 100
      {
          SendClientMessage(playerid, 0xFF0000AA, "You don't need to heal yourself"); // we send him a message that he's healthy
      }
    }
   return 1;[/pawn]

Done!
 :)
Title: Re: 【Help】OnPickedUp is not working
Post by: Doom on March 16, 2013, 06:15:39 pm
Well the same way... the only difference is that you made it a little more complicated and advanced.
Title: Re: 【Help】OnPickedUp is not working
Post by: sseebbyy on March 16, 2013, 08:20:37 pm
Code: [Select]
hpickup = AddStaticPickup(366, 1, x, y, z ); //Make sure you modify it to the location you want that pickup

The correct syntax is: AddStaticPickup(pickupid, modelid, x, y, z);
Title: Re: HelpOnPickedUp is not working
Post by: Doom on March 17, 2013, 09:54:38 am
i made the variable to remove confusion and anyways that will also work ;)
Title: Re:
Post by: sseebbyy on March 17, 2013, 01:40:26 pm
i made the variable to remove confusion and anyways that will also work ;)

How do you know if him have the same version of function or have the standard one ? You can't know that, so will be better to put the standard function.
Title: Re: 【Help】OnPickedUp is not working
Post by: Doom on March 17, 2013, 03:53:43 pm
i have 2 answers for that question.

1. In this case we know he don't have it

2. Someone who is scripting is not noob enough who dont even know that if he has already defined it or not... and if he already have then leave that step and if not then create it, Simple
Title: Re: 【Help】OnPickedUp is not working
Post by: Pain on March 20, 2013, 02:39:53 pm
OK