16.07.2014, 01:30
Using sscanf is a very common thing to use along with ZCMD, and I would recommend it. If you don't already have it installed, you can download it here: https://sampforum.blast.hk/showthread.php?tid=120356.
I tried explaining why I had done what, if you need more explanation on it I can do so.
I tried explaining why I had done what, if you need more explanation on it I can do so.
Code:
CMD:setcolor(playerid, params[]) { if (!IsPlayerAdmin(playerid)) SendClientMessage(playerid, -1, "SERVER: Unknown command."); else if (IsPlayerAdmin(playerid)) { new iTargetID, iColor; //define the variables we want the data from the command going to (written after /setcolor in-game) if(sscanf(params, "ud", iTargetID, iColor)) { SendClientMessage(playerid, -1, "USAGE: /setcolor [playerid] [color]"); //In sscanf, 'u' is a player id and 'd' is an integer SendClientMessage(playerid, -1, "Colors: 1 - Yellow, 2 - White, 3 - Red"); } /* a switch statement is like multiple 'if' and 'else if' statements however compressed to look like this rather than if(iColor == 1) iColor = 0xFFFF0000; if(iColor == 2) iColor = 0xFFFFFF00; if(iColor == 3) iColor = 0xFF0606FF; else iColor = 0xFFFFFF00; Just like if statements, brackets are optional if it is only 1 line. */ if(!IsPlayerConnected(iTargetID)) return SendClientMessage(playerid, -1, "The specified player is not connected."); switch(iColor) { case 1: iColor = 0xFFFF0000; case 2: iColor = 0xFFFFFF00; case 3: iColor = 0xFF0606FF; default: iColor = 0xFFFFFF00; //default will set the color as white if the number isnt 1, 2 or 3. } SetPlayerColor(iTargetID, iColor); SendClientMessage(playerid, COLOR_GREEN, "You succesfully changed the player his color."); } return 1; }