[Tutorial] How to script /skin command
#1

Hello there. Here's a tutorial on how to script "/skin [ID]" command.

Well. We'll explain that right now. Firstly, open Pawno, Go on File -> New , Or press CTRL + N .

Cool? Now, before we script that command, We have to include a file which we have in "include" folder...

We'll have to include a file called "gl_common", We should have it already in the "include" folder... But, if you don't have it, Here's:

http://www.mediafire.com/?y20pclpl1e8y7oc


Okey, fine.

*NOTE: This is not for /skin command only. You can create any command you want as long as It has a lot of symbols. As /kick [ID], /ban [ID], etc...

Now, on the pawno codes. You see: "#include <a_samp>"

1. Go under it, type:
Code:
#include "../include/gl_common.inc"
2. We need to define the colours so... Search for "#endif"

Type under it:
Code:
#define COLOR_RED 0xAA3333AA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_SPAWN 0xFF8C55FF
#define COLOR_LIGHTBLUE 0x6DC5F3FF
#define COLOR_ADMIN 0xFF0000FF
#define COLOR_SAY 0x2986CEFF
#define COLOR_SYSGREY 0xC6BEBDFF
#define COLOR_BLACK 0x000000FF
#define COLOR_JOIN 0x74E80099
#define COLOR_WARN 0xBE615099
#define COLOR_RACE 0x00BBBB99
#define COLOR_KRED 0xFF0000FF
3. Now, don't move. Type under those colours:
Code:
new idx;
4. Now, It's time to type the command /skin ..

Search for "OnPlayerCommandText" and You'll see "{" mark...

Change: /mycommand to /skin

Okey... Here, we need to put a "tmp"...

For knowledge, "tmp" means the [ID] which the player is going to type.

So... Type under "{" mark the following:
Code:
new tmp[256];
// Don't play with [256] number. Just type what I'm telling you.


Okey. Now type under that code again:
Code:
        tmp = strtok ( cmdtext, idx );
        if ( !strlen ( tmp ) )
        {
            SendClientMessage(playerid, COLOR_RED, "USAGE: /skin [ID]");
            return 1;
  }
        SetPlayerSkin(playerid, strval(tmp));
Okey. I would rather telling you the full code, Explaining it to you at the end of the subject...


On:

"tmp = strtok ( cmdtext, idx );" // We are scripting that "tmp" is used for the ID.

"if ( !strlen ( tmp ) )" // This is for the USAGE message. If someone typed /skin with the ID, It'll show up.

"SendClientMessage(playerid, COLOR_RED, "USAGE: /skin [ID]");" // As I said before. This is used for the USAGE message.

"SetPlayerSkin(playerid, strval(tmp));" // It's obviously changing the skin. But, On "strval(tmp))" That's the ID which the player is going to type, Which we called it "tmp".


*WARNING: Be sure that you end up with "return 1;"


Full Code:
Code:
// This is a comment
// uncomment the line below if you want to write a filterscript
//#define FILTERSCRIPT

#include <a_samp>
#include "../include/gl_common.inc"
#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif
#define COLOR_RED 0xAA3333AA
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_ORANGE 0xFF9900AA
#define COLOR_SPAWN 0xFF8C55FF
#define COLOR_LIGHTBLUE 0x6DC5F3FF
#define COLOR_ADMIN 0xFF0000FF
#define COLOR_SAY 0x2986CEFF
#define COLOR_SYSGREY 0xC6BEBDFF
#define COLOR_BLACK 0x000000FF
#define COLOR_JOIN 0x74E80099
#define COLOR_WARN 0xBE615099
#define COLOR_RACE 0x00BBBB99
#define COLOR_KRED 0xFF0000FF

new idx;

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("Blank Script");
    AddPlayerClass(0, 1958.3783, 1343.1572, 15.3746, 269.1425, 0, 0, 0, 0, 0, 0);
    return 1;
}

public OnGameModeExit()
{
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraPos(playerid, 1958.3783, 1343.1572, 15.3746);
    SetPlayerCameraLookAt(playerid, 1958.3783, 1343.1572, 15.3746);
    return 1;
}

public OnPlayerConnect(playerid)
{
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    return 1;
}

public OnPlayerSpawn(playerid)
{
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/skin", cmdtext, true, 10) == 0)
    {
        new tmp[256];
        tmp = strtok ( cmdtext, idx );
        if ( !strlen ( tmp ) )
        {
            SendClientMessage(playerid, COLOR_RED, "USAGE: /skin [ID]");
            return 1;
  }
        SetPlayerSkin(playerid, strval(tmp));
        // Do something here
        return 1;
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}

Any questions I'm ready to answer
Reply
#2

This needs work.

Your teaching everyone to use 256 cells, which is just a waste of memory. You didnt really explain much, just told them what to do (you should explain WHY, and what everything is doing). Also, you arent checking if the skin is a valid one.

You should also look into sscanf and zcmd (they blow away strcmp/strtok), but thats for another time i guess :P.
Reply
#3

This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.

pawn Code:
command(skin, playerid, params[])
{
        new string[128], skinid;
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "d", skinid)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]");
        }
        else
        {
            SetPlayerSkin(playerid, skinid);
            format(string, sizeof(string), "You have set your skin ID to %d", skinid);
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
This checks if a player is an admin (RCON), if the sscanf params are correct, if not it sends a message with the correct usage (SYNTAX) if the params are correct, it continues the command. It will set your skin to the ID you chose and then send you a message telling you what skin you chose. I used ZCMD and SSCANF2 to do this. Took me 10 seconds.
Reply
#4

Quote:
Originally Posted by Kyosaur
View Post
This needs work.

Your teaching everyone to use 256 cells, which is just a waste of memory. You didnt really explain much, just told them what to do (you should explain WHY, and what everything is doing). Also, you arent checking if the skin is a valid one.

You should also look into sscanf and zcmd (they blow away strcmp/strtok), but thats for another time i guess :P.
Well. I'm a beginner and trying to help beginners like me...

Do you think this tutorial is good for a beginner scripting poster?

Reply
#5

Quote:
Originally Posted by RealCop228
View Post
This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.

pawn Code:
command(skin, playerid, params[])
{
        new string[128], skinid;
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "d", skinid)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]");
        }
        else
        {
            SetPlayerSkin(playerid, skinid);
            format(string, sizeof(string), "You have set your skin ID to %d", skinid);
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
This checks if a player is an admin (RCON), if the sscanf params are correct, if not it sends a message with the correct usage (SYNTAX) if the params are correct, it continues the command. It will set your skin to the ID you chose and then send you a message telling you what skin you chose. I used ZCMD and SSCANF2 to do this. Took me 10 seconds.
You can use it in my code too.

Just type after "SetPlayerSkin":
Code:
new skinid;
new msg[256];
skinid = strval(tmp);
format(msg,256,"You've chosen skin id %d",skinid);
SendClientMessage(playerid, COLOR_YELLOW, msg);
It's that simple :P
Reply
#6

Yeah do like Realcop use sscanf, and either dcmd or zcmd!
Reply
#7

Quote:
Originally Posted by Cameltoe
View Post
Yeah do like Realcop use sscanf, and either dcmd or zcmd!
Yea. I'm going to try his way to script ^^


Shouldn't we put dcmd(skin, 4, cmdtext); before, we do command(skin)... ?
Reply
#8

Visit the DCMD topic for more help.
Reply
#9

Quote:
Originally Posted by Kyosaur
View Post
This needs work.

Your teaching everyone to use 256 cells, which is just a waste of memory. You didnt really explain much, just told them what to do (you should explain WHY, and what everything is doing). Also, you arent checking if the skin is a valid one.

You should also look into sscanf and zcmd (they blow away strcmp/strtok), but thats for another time i guess :P.
Quote:
Originally Posted by Injector
View Post
Well. I'm a beginner and trying to help beginners like me...

Do you think this tutorial is good for a beginner scripting poster?

It's not good, but it's alright..
Still, I don't see why you are going to make a tutorial, when you're showing an unefficient and slow way of doing it, instead of learning some more about speed and effiency first, then try to make one.

Good effort anyway, though
Reply
#10

Quote:
Originally Posted by RealCop228
View Post
This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.

pawn Code:
command(skin, playerid, params[])
{
        new string[128], skinid;
    if(IsPlayerAdmin(playerid))
    {
        if(sscanf(params, "d", skinid)
        {
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]");
        }
        else
        {
            SetPlayerSkin(playerid, skinid);
            format(string, sizeof(string), "You have set your skin ID to %d", skinid);
            SendClientMessage(playerid, COLOR_WHITE, string);
        }
    }
    return 1;
}
This checks if a player is an admin (RCON), if the sscanf params are correct, if not it sends a message with the correct usage (SYNTAX) if the params are correct, it continues the command. It will set your skin to the ID you chose and then send you a message telling you what skin you chose. I used ZCMD and SSCANF2 to do this. Took me 10 seconds.
You don't really need to create another integer, as you can strval params:

pawn Code:
command(skin, playerid, params[]) // Declaring that this is a ZCMD command.
{
    if(IsPlayerAdmin(playerid)) { // Checking whether the player is an admin or not, if so the code continues!
        if(!isnull(params)) { // Here we check if the string contains no content.
            SendClientMessage(playerid, COLOR_WHITE, "SYNTAX: /skin [skinID]"); // It contains no content, let's send them a message showing them the syntax
        }
        else { // This else statement does the opposite to the check above, basically the params appear to be existant so the code continues like so
            new
                string[32]; // Create a string to send them a message with

            SetPlayerSkin(playerid, strval(params)); // Set the player skin. Here, we're using 'strval' which evaluates 'params' (a string) in to an integer
            format(string, sizeof(string), "Your new skin ID is: %d", strval(params)); // And again, however formatting a message.
            SendClientMessage(playerid, COLOR_WHITE, string); // Sending them the message
        }
    }
    return 1; // Command has finished processing. Returning 1!
}
Added comments to explain what's being done, too. A bit of a further explanation for how strval works (for those that didn't understand it):

By default, params is a string, which means it isn't expected to just contain the value of an integer (digit/number), therefore using strval, it evaluates the string and checks for numbers within the string, then throws them out as an integer. Hence 'strval'.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)