#include "../include/gl_common.inc"
#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;
new tmp[256];
tmp = strtok ( cmdtext, idx ); if ( !strlen ( tmp ) ) { SendClientMessage(playerid, COLOR_RED, "USAGE: /skin [ID]"); return 1; } SetPlayerSkin(playerid, strval(tmp));
// 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; }
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 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. |
This is definitely the bad way to make this command. It's a lot easier doing it with sscanf.
pawn Code:
|
new skinid; new msg[256]; skinid = strval(tmp); format(msg,256,"You've chosen skin id %d",skinid); SendClientMessage(playerid, COLOR_YELLOW, msg);
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? ![]() |
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[]) // 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!
}