About "Stock"
#1

Hello guys!

So i have been doing a simple stock as a test..

so my question is if i created a stock like:

PHP код:
stock DestroyKid(kidid)
{
   
SetPlayerHealth(kidid0);
   return 
1;

When i type DestroyKid it have to show a hint or it's not possible?
Reply
#2

Protip: Don't use stocks, just create it as a normal function.

If you want it as a hint you have to find an IDE that provides that automatically or change a PAWN.xml in for instance your notepad++ or sublime editor. https://sampforum.blast.hk/showthread.php?tid=174046
Reply
#3

Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Protip: Don't use stocks, just create it as a normal function.

If you want it as a hint you have to find an IDE that provides that automatically or change a PAWN.xml in for instance your notepad++ or sublime editor. https://sampforum.blast.hk/showthread.php?tid=174046
Create it as a function? may you can please provide an example i'm quite opened for examples
Reply
#4

Quote:
Originally Posted by RxErT
Посмотреть сообщение
Create it as a function? may you can please provide an example i'm quite opened for examples
Read this informative topic by Vince.
Reply
#5

Stock is used mainly by avoiding "not used" warning by the compiler which I don't think should ever be used as having the compiler tell you that you forgot something in your code can be helpful in the future since you probably forgot about it. Am myself having lots of warnings (had 25 in total before) and I keep them there since I am making a very big project:

Код:
h_functions.pwn(201) : warning 203: symbol is never used: "playerid"
h_functions.pwn(366) : warning 203: symbol is never used: "playerid"
h_script.pwn(357) : warning 204: symbol is assigned a value that is never used: "vehicle"
h_script.pwn(2479) : warning 203: symbol is never used: "GetLockStatus"
h_script.pwn(2479) : warning 203: symbol is never used: "IsPlayerFalling"
h_script.pwn(2479) : warning 203: symbol is never used: "IsVehicleFalling"
h_script.pwn(2479) : warning 203: symbol is never used: "PlayAnimation"
h_script.pwn(2479) : warning 203: symbol is never used: "PrintAdminHelp"
h_script.pwn(2479) : warning 203: symbol is never used: "PrintFactionHelp"
h_script.pwn(2479) : warning 203: symbol is never used: "_RenderBar"
Again, they are good as reminders! Now that you know what stock is, let's move on to another type of declaration of functions: callbacks. They are recognized by their famous keywords "forward" and "public". If you are using those, that means that the function will be called directly from the SA-MP server instead of from the script. Typical examples are callbacks such as "OnPlayerSpawn" or normal timer callbacks.

The normal functions I was talking about looks like the one below.

Код:
DestroyKid(kidid) 
{ 
   SetPlayerHealth(kidid, 0); 
   return 1; 
}
Further information about this can be found here: https://sampwiki.blast.hk/wiki/Stock
Reply
#6

Quote:
Originally Posted by Burridge
Посмотреть сообщение
Thanks, i'll be reading it!


Quote:
Originally Posted by Hansrutger
Посмотреть сообщение
Stock is used mainly by avoiding "not used" warning by the compiler which I don't think should ever be used as having the compiler tell you that you forgot something in your code can be helpful in the future since you probably forgot about it. Am myself having lots of warnings (had 25 in total before) and I keep them there since I am making a very big project:

Код:
h_functions.pwn(201) : warning 203: symbol is never used: "playerid"
h_functions.pwn(366) : warning 203: symbol is never used: "playerid"
h_script.pwn(357) : warning 204: symbol is assigned a value that is never used: "vehicle"
h_script.pwn(2479) : warning 203: symbol is never used: "GetLockStatus"
h_script.pwn(2479) : warning 203: symbol is never used: "IsPlayerFalling"
h_script.pwn(2479) : warning 203: symbol is never used: "IsVehicleFalling"
h_script.pwn(2479) : warning 203: symbol is never used: "PlayAnimation"
h_script.pwn(2479) : warning 203: symbol is never used: "PrintAdminHelp"
h_script.pwn(2479) : warning 203: symbol is never used: "PrintFactionHelp"
h_script.pwn(2479) : warning 203: symbol is never used: "_RenderBar"
Again, they are good as reminders! Now that you know what stock is, let's move on to another type of declaration of functions: callbacks. They are recognized by their famous keywords "forward" and "public". If you are using those, that means that the function will be called directly from the SA-MP server instead of from the script. Typical examples are callbacks such as "OnPlayerSpawn" or normal timer callbacks.

The normal functions I was talking about looks like the one below.

Код:
DestroyKid(kidid) 
{ 
   SetPlayerHealth(kidid, 0); 
   return 1; 
}
Further information about this can be found here: https://sampwiki.blast.hk/wiki/Stock
Well thank you so much! i wasted your time but i got your idea and tested it and it works thanks!
Reply
#7

Putting the keyword stock in front of a function doesn't make it a stock, it can be called a stock function however, as the guide refers to it that way.

There is no known downside in using stock in front of functions, or any benefits for not using it in front of functions. The only thing that matters is to acknowledge its use, which is the action of lacking everything with the keyword from the compiled source (.amx) if "x" factor is not being used anywhere in the script. Having unused stock "x" factors would increase compile time depending on the number of "x" factors, but their existence in the source code doesn't affect anything since when compiled it won't be included in the .amx file.
Reply
#8

Im pretty sure he meant hint in text editor (pawno).
If you want hints and code auto completion you should use sublime with shoutclaw's package. There are some other solutions as far as im aware of, but for me sublime is perfect. Here is the link to Shoutclaws topic: https://sampforum.blast.hk/showthread.php?pid=3158607#pid3158607
Reply
#9

Only natives show in the function list. Create a new .inc file and write "native function_name();" for each function (don't use the include in production use or pretty much anywhere, it would just be a visual add-on).
Reply
#10

It's ok guys, i already got it thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)