SA-MP Forums Archive
[Tutorial] Less verbose function-making - 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: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Less verbose function-making (/showthread.php?tid=520020)



Less verbose function-making - Snipa - 17.06.2014

Are you tired of having to type so much just to create a function?

Instead, throw this code at the top of your script (under the includes).

pawn Code:
#define F:%0(%1)    forward %0(%1); \
                    public %0(%1)
This...
pawn Code:
forward KickPublic(playerid);
public KickPublic(playerid)
{
    Kick(playerid);
}
becomes this:

pawn Code:
F:KickPublic(playerid)
{
    Kick(playerid);
}
Just a simple text replacement. You can still call the functions, set them to timers, etc.


Re: Less verbose function-making - Ihateyou - 17.06.2014

hmm might be useful thx

but this is the entire tutorial? lol


Re: Less verbose function-making - Jack_Leslie - 17.06.2014

What the f*ck? Just use Kick(playerid); lol, bad example.


Re: Less verbose function-making - ]Rafaellos[ - 17.06.2014

Quote:
Originally Posted by Jack_Leslie
View Post
What the f*ck? Just use Kick(playerid); lol, bad example.
Actually is not bad example. Why? Because if you use Kick(playerid); messages aren't going to show. This example is now used by Everyone.


Re: Less verbose function-making - Jack_Leslie - 17.06.2014

Quote:
Originally Posted by ]Rafaellos[
View Post
Actually is not bad example. Why? Because if you use Kick(playerid); messages aren't going to show. This example is now used by Everyone.
Is that stated in the tutorial? No, it's not.


Re: Less verbose function-making - iZN - 17.06.2014

Quote:
Originally Posted by Jack_Leslie
View Post
Is that stated in the tutorial? No, it's not.
The tutorial is not meant for the Kick native, you should read the thread again, he just gave an example. Check wiki for more information about Kick native.


Re: Less verbose function-making - Snipa - 17.06.2014

Quote:
Originally Posted by Jack_Leslie
View Post
What the f*ck? Just use Kick(playerid); lol, bad example.



Re: Less verbose function-making - Jack_Leslie - 18.06.2014

Quote:
Originally Posted by iZN
View Post
The tutorial is not meant for the Kick native, you should read the thread again, he just gave an example. Check wiki for more information about Kick native.
As I said though, bad example, what if someone who's never scripted before comes across this thread, and thinks "Oh, that's how I need to kick a player from my server", they're going to start doing it that way, wasting time.


Re : Less verbose function-making - S4t3K - 18.06.2014

And if I can add something to the discussion, this is an example.

It could totally by something like this

PHP Code:

native IsValidVehicle
(vehicleid);
F:respawnVehs()
{
      for(new 
0MAX_VEHICLESi++)
      {
            if(
IsValidVehicle(i)) SetVehicleToRespawn(i);
      }
      return 
SendClientMessageToAll(-1"All the vehicles have been delay respawned by an administrator !");
}
CMD:respawnall(playeridparams[])
{
      if(!
IsNumeric(params)) return SCM(playerid, -1"SYNTAX : /respawnall [Delay (seconds)]");
      new 
time strval(params);
      
SetTimer("respawnVehs"time*1000false);
      return 
1;