Author Topic: 【Help】OnPickedUp is not working  (Read 3453 times)

0 Members and 1 Guest are viewing this topic.

Pain

  • Guest
【Help】OnPickedUp is not working
« on: March 16, 2013, 10:36:25 am »
OnPickedUp is not working
If picked up health will have $ 500
but don‘t have $ 500
« Last Edit: March 16, 2013, 06:01:53 pm by Pain »

Offline Doom

  • Made Man
  • ***
  • Posts: 105
    • View Profile
Re: 【Help】OnPickedUp is not working
« Reply #1 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;
}

Offline NeskWriter

  • Crime Boss
  • ****
  • Posts: 355
    • View Profile
Re: 【Help】OnPickedUp is not working
« Reply #2 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!
 :)


-Funniest quotes-

Quote from: asad3man
i cant able to understand

Offline Doom

  • Made Man
  • ***
  • Posts: 105
    • View Profile
Re: 【Help】OnPickedUp is not working
« Reply #3 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.

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re: 【Help】OnPickedUp is not working
« Reply #4 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);

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Doom

  • Made Man
  • ***
  • Posts: 105
    • View Profile
Re: HelpOnPickedUp is not working
« Reply #5 on: March 17, 2013, 09:54:38 am »
i made the variable to remove confusion and anyways that will also work ;)

Offline sseebbyy

  • VC:MP Veteran
  • *****
  • Posts: 774
  • Immortal VC:MP Player
    • View Profile
    • Zombie Invasion => Server Forum [DEAD PROJECT]
Re:
« Reply #6 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.

Quote
Painful/Noob scripters acts like: I Am The Best Scripter Because I Announce My Releases With Big Font Size Without Giving Too Much Info' In The Hope They All Will Download And Check It. I Ignore Bad Replies, Replies That I Could Learn From, And Replies With So Much Text.



Offline Doom

  • Made Man
  • ***
  • Posts: 105
    • View Profile
Re: 【Help】OnPickedUp is not working
« Reply #7 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

Pain

  • Guest
Re: 【Help】OnPickedUp is not working
« Reply #8 on: March 20, 2013, 02:39:53 pm »
OK