Author Topic: functions called only by picking up pickup  (Read 2248 times)

0 Members and 2 Guests are viewing this topic.

Offline NeskWriter

  • Crime Boss
  • ****
  • Posts: 355
    • View Profile
functions called only by picking up pickup
« on: November 11, 2012, 09:32:54 pm »
How to make a system which will call function(s) only when player picks up any pickup?
No no no
I mean player can use commandtext only when he picks up a pickup


-Funniest quotes-

Quote from: asad3man
i cant able to understand

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: functions called only by picking up pickup
« Reply #1 on: November 11, 2012, 09:47:47 pm »
How to make a system which will call function(s) only when player picks up any pickup?
No no no
I mean player can use commandtext only when he picks up a pickup

One thing you can do is keep track of players that picked up a pickup with an array. At the top of the script, you could use this:
[pawn]new playersPickedUp[50];[/pawn]

When a player joins, you would set their entry to 0 to indicate that they haven't picked up a pickup yet, so in OnPlayerConnect, you would have this:
[pawn]playersPickedUp[playerid] = 0;[/pawn]

The purpose of this being that if a player leaves, when a player joins with the same ID that they had, they still have to pick up a pickup.

When a player picks up a pickup (OnPickedUp), you would then have this line of code to indicate that they picked up a pickup:
[pawn]playersPickedUp[playerid] = 1;[/pawn]

With a value of 0 (false) indicating they have not yet, and 1 (true) indicating that they have.

Lastly, in OnPlayerCommandText (or whatever it is, I haven't touched Pawn in a long while), you want to check if they've picked up a pickup. If they haven't yet, let them know to do so.

[pawn]
if( playersPickedUp[playerid] == 0 )
{
    // Message the player telling them to pick up a pickup
}
else if( strcmp( cmd, "command", true ) == 0 )
{
    // ......
}
else if( strcmp( cmd, "command2", true ) == 0 )
{
    // .......
}
[/pawn]

Because of the use of else if statements, and because we check to see if they picked up a pickup before we check any of the commands, the script will not run any commands until they pick up a pickup.
« Last Edit: November 11, 2012, 09:50:15 pm by stormeus »
Do not PM me for support.