haw to use stock oO
#1

Hello.
Help me please ( i am junior in pawno )
Explain how to use the stock
Examples of please..
Reply
#2

pawn Код:
stock ReturnPlayerID(playerid)
{
   return playerid;
}
lol that's how.
Reply
#3

I made an article on the wiki about stocks:

Links:

My Article

Part of another article
Reply
#4

stock is a function, it can have "stock" infront of the function's name and it can to not have it.

pawn Код:
stock playerid(playerid)
  return playerid;

//or
player(playerid)
  return playerid;
Not hard to uynderstand, also I suggest you to read wiki. It explains everything better than anyone else and shows examples.
Reply
#5

Quote:
Originally Posted by MenaceX^
stock is a function, it can have "stock" infront of the function's name and it can to not have it.

pawn Код:
stock playerid(playerid)
  return playerid;

//or
player(playerid)
  return playerid;
Not hard to uynderstand, also I suggest you to read wiki. It explains everything better than anyone else and shows examples.
The only difference in the two is that the second one will give a warning if not used. The first one just is ignored if unused.
Reply
#6

So for example, see:
pawn Код:
stock GivePlayerHealth(playerid, Float:health)
{
  new Float:pHealth;
  GetPlayerHealth(playerid, pHealth);
  SetPlayerHealth(playerid, pHealth + health);
}
How can you apply this command?
Reply
#7

Actualy I think a better explaination of stock is:

If you want to do a command like checking if a player exists in a code (mysql scripting)
instead of making your code like:
pawn Код:
///command.
format(string,sizeof(string),"SELECT * FROM `table` WHERE name='%s'",randomname);
samp_mysql_query(string);
samp_mysql_store_result(); // etc etc.
You can do it in a stock so you do it like
pawn Код:
///command
if(CheckPlayerExistant(variable))
{
  //code
  //code
  //code
}
else return SendClientMessage(playerid,color,"player does not exists");
I do everything in stocks also.


---------------
Your new question:
Quote:
Originally Posted by Buttig
So for example, see:
pawn Код:
stock GivePlayerHealth(playerid, Float:health)
{
  new Float:pHealth;
  GetPlayerHealth(playerid, pHealth);
  SetPlayerHealth(playerid, pHealth + health);
}
How can you apply this command?
You can do it like
pawn Код:
if(!strcmp(cmdtext,"/givehealth",true))
  return GiveHealth(playerid,50);
Will get your current health and will add 50.
Reply
#8

Uhm no-one who has posted in this topic actually knows what stock is... it can be used for the examples you have posted yes but that is not its main function. Look it up in pawn-lang.pdf.
Reply
#9

I posted links to my wikipedia article in which I explain briefly what it says in the pawn lang.pdf

A stock is a function that you can have in a script, but which is only compiled if you use it. For example if I put the (godforsaken) strtok stock in my script and never used it (thank god) it wouldn't be included in the compiled .amx... For more information go to the wikipedia article, or do as the previous posted told you to do...
Reply
#10

Quote:
Originally Posted by Weirdosport
I made an article on the wiki about stocks:

Links:

My Article

Part of another article
Off topic, but that is a well structured and easy-to-read article! Well done!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)