SA-MP Forums Archive
haw to use stock oO - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: haw to use stock oO (/showthread.php?tid=77404)



haw to use stock oO - user226 - 10.05.2009

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


Re: haw to use stock oO - Backwardsman97 - 10.05.2009

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


Re: haw to use stock oO - Weirdosport - 10.05.2009

I made an article on the wiki about stocks:

Links:

My Article

Part of another article


Re: haw to use stock oO - MenaceX^ - 10.05.2009

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.


Re: haw to use stock oO - Backwardsman97 - 10.05.2009

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.


Re: haw to use stock oO - user226 - 10.05.2009

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?


Re: haw to use stock oO - MenaceX^ - 10.05.2009

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.


Re: haw to use stock oO - beckzy - 10.05.2009

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.


Re: haw to use stock oO - Weirdosport - 10.05.2009

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...


Re: haw to use stock oO - ferriswheel - 10.05.2009

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!