Is it possible to make a /setskin command without using sscanf/zcmd/dcmd or any other but just using stock sa-mp functions? I've been looking for two hours trying to figure this out and can't find an answer or even anyone else asking the question so I figured I'd ask. It seems to be impossible but if it is can someone post an example?
Sorry I didn't specify, what I mean is /setskin [id] [skinid] so being able to change players skin id and your own. |
new sendername[MAX_PLAYER_NAME];
new giveplayer[MAX_PLAYER_NAME];
if(strcmp(cmd, "/setskin", true) == 0)
{
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, 0xFFFFFFAA, "USAGE: /setskin [playerid/PartOfName] [skin id]");
return 1;
}
new para1;
new level;
para1 = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
level = strval(tmp);
if(level > 299 || level < 1) { SendClientMessage(playerid, COLOR_GREY, "Wrong skin ID!"); return 1; }
if(para1 != INVALID_PLAYER_ID)
{
GetPlayerName(para1, giveplayer, sizeof(giveplayer));
GetPlayerName(playerid, sendername, sizeof(sendername));
format(string, sizeof(string), "Your skin has been changed by Admin %s", sendername);
SendClientMessage(para1, 0xFFFFFFAA, string);
format(string, sizeof(string), "You have given %s skin to %d.", giveplayer,level);
SendClientMessage(playerid, 0xFFFFFFAA, string);
SetPlayerSkin(para1, level);
}
else
{
SendClientMessage(playerid, COLOR_GRAD1, " you are not authorized to use that command!");
}
}
return 1;
}
/* CREDITS: UTILS INCLUDE */
ReturnUser(text[], playerid = INVALID_PLAYER_ID)
{
new pos = 0;
while (text[pos] < 0x21) // Strip out leading spaces
{
if (text[pos] == 0) return INVALID_PLAYER_ID; // No passed text
pos++;
}
new userid = INVALID_PLAYER_ID;
if (IsNumeric(text[pos])) // Check whole passed string
{
// If they have a numeric name you have a problem (although names are checked on id failure)
userid = strval(text[pos]);
if (userid >=0 && userid < MAX_PLAYERS)
{
if(!IsPlayerConnected(userid))
{
/*if (playerid != INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF0000AA, "User not connected");
}*/
userid = INVALID_PLAYER_ID;
}
else
{
return userid; // A player was found
}
}
/*else
{
if (playerid != INVALID_PLAYER_ID)
{
SendClientMessage(playerid, 0xFF0000AA, "Invalid user ID");
}
userid = INVALID_PLAYER_ID;
}
return userid;*/
// Removed for fallthrough code
}
// They entered [part of] a name or the id search failed (check names just incase)
new len = strlen(text[pos]);
new count = 0;
new name[MAX_PLAYER_NAME];
for (new i = 0; i < MAX_PLAYERS; i++)
{
if (IsPlayerConnected(i))
{
GetPlayerName(i, name, sizeof (name));
if (strcmp(name, text[pos], true, len) == 0) // Check segment of name
{
if (len == strlen(name)) // Exact match
{
return i; // Return the exact player on an exact match
// Otherwise if there are two players:
// Me and MeYou any time you entered Me it would find both
// And never be able to return just Me's id
}
else // Partial match
{
count++;
userid = i;
}
}
}
}
if (count != 1)
{
if (playerid != INVALID_PLAYER_ID)
{
if (count)
{
SendClientMessage(playerid, 0xFF0000AA, "Multiple users found, please narrow earch");
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "No matching user found");
}
}
userid = INVALID_PLAYER_ID;
}
return userid; // INVALID_USER_ID for bad return
}
Is it possible to make a /setskin command without using sscanf/zcmd/dcmd or any other but just using stock sa-mp functions? I've been looking for two hours trying to figure this out and can't find an answer or even anyone else asking the question so I figured I'd ask. It seems to be impossible but if it is can someone post an example?
Sorry I didn't specify, what I mean is /setskin [id] [skinid] so being able to change players skin id and your own. |
Why would you want to? It's slower, more time consuming and more lines of code. If it's because you don't understand how to use them, simply read the documentation and/or tutorials thouroughly. You won't regret it at all.
|