[Tutorial] Simple /frisk command!
#1

Welcome everyone to my first ever tutorial! I've decided to start to post on the SA-MP forums and share my scripting knowledge, instead of just browsing without an account.

My first post/tutorial will be about the /afk and the /back command! This is good for all servers, and will hopefully help you with it. This guide will hopefully help out all those new scripters - despite me still being relatively new to PAWN still.

Anyways, to the tutorial!

You're going to want to have Zcmd - which you can find here. This'll help us with command processing, without the default SA-MP command processor.

At the top of the script, you're gonna have to add this line:

pawn Код:
#include <zcmd>
What this will do is make sure you've added the zcmd include you downloaded from the first step.

Next, you're going to want to add some colour defines to make your frisk text pretty! At the top of the script, under the includes, type in this:

pawn Код:
#define WHITE           0xFFFFFFFF
#define RED             0xE60000FF
Next we're going to write the command. Hopefully by now you'll now how to write the basic command layout with Zcmd. If not, here we go!

pawn Код:
command(afk, playerid, params[])
{
Don't think I'll really explain these. If you don't know how to make those, go look at the ZCMD page.

Under that command, we're going to want to add a variable. This'll send them too a different virtual world then what the default people are in. (Default is 0.)

pawn Код:
SetPlayerVirtualWorld(playerid, 500);
Next we're going to want to assign them a colour in the tab list. Let's go with red, since we already have it in our defines.

pawn Код:
SetPlayerColor(playerid, RED);
Alright, so we've set their virtual world and our custom colour in the tab list. Next we'll make them so they have over 10k health and armour, just so no one can DM them by chance.

pawn Код:
SetPlayerHealth(playerid, 10000);
SetPlayerArmour(playerid, 10000);
We're almost done! We're going to want to have them frozen so they can't escape and do stuff.

pawn Код:
TogglePlayerControllable(playerid, 0);
Lastly, we'll send them a message after all the variables are completed.

pawn Код:
SendClientMessage(playerid, WHITE, "You have been set as AFK!");
At the bottom of the command, we'll want to add the proper indentation and the return.

pawn Код:
{
return 1;
Congrats! You finished making /afk! Now, we'll want to add a /back so they can de-activate all this stuff.
It's pretty easy, in fact, its the exact same thing as how we made the /afk command except for a few different variables.

pawn Код:
command(back, playerid, params[])
{
We're going to want to send them back to VW 0.

pawn Код:
SetPlayerVirtualWorld(playerid, 0);
Then set their name back to white.

pawn Код:
SetPlayerColor(playerid, WHITE);
Then unfreeze them.

pawn Код:
TogglePlayerControllable(playerid, 1);
Then we'll want to set their health and armour back to 100.

pawn Код:
SetPlayerHealth(playerid, 100);
SetPlayerArmour(playerid, 0);
Lastly, we'll want to send them a message to let them know they're back from being AFK.

pawn Код:
SendClientMessage(playerid, WHITE, "Welcome back! You are no longer set as being AFK.");
Congratulations! You made our /afk and /back command!

I may be making some more tuts after this - just depends on how busy I am and the feedback I get from this one.

I hoped you enjoyed, and no, I'm not gonna be one of those kids who 'omg!!!!! plz rep me lOl!!!11!!1"
Reply
#2

Very messy, and unorganized.. Also the code you supplied won't work due to you creating an enumeration and not including every variable that you've used in your example code.
Reply
#3

I've removed the original /frisk command and changed the post to /afk and /back. This is all working, as I've used it multiple times in a script.

Edit: The original title is there, however I changed it to /afk and /back. Didn't really want to create a thread, hence the old title.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)