/skin command
#1

Код:
if(strcmp(cmd, "/skin", true) == 0) {
	SendClientMessage(playerid, COLOR_RED, "USAGE: /skin [id]");
	SendClientMessage(playerid, COLOR_RED, "COST: $20000");
	    if(GetPlayerMoney(playerid) <20000)
	    return SendClientMessage(playerid, COLOR_RED, "ERRO: You don't have enough money to change your skin.");
	    // Checks if the player has enough money to change its skin ; Gives a message erro if doens't
	    GivePlayerMoney(playerid, -20000);
	    SetPlayerSkin(playerid,id);
	    return 1;
		}
Can anybody make this command the right way? I made it.. but im having a hard time fixing it.. Im a beginner at scripting :P
Reply
#2

pawn Код:
#include <sscanf2>
#include <ZCMD>

CMD:skin(playerid,params[])
{
 new id;
 if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE : /skin id \nCost : $20000");
 if(id<0 || id>299) return SendClientMessage(playerid,COLOR_RED,"Invalid ID : Usable ID 0-299");
 if(GetPlayerMoney(playerid) < 20000) return SendClientMessage(playerid,COLOR_RED,"Min amount needed is 20000$");
 SetPlayerSkin(playerid,id);
 GivePlayerMoney(playerid,-20000);
 new msg[50];
 format(msg,sizeof(msg),"Your skin has been set to ID %d",id);
 return SendClientMessage(playerid,-1,msg);
}
Reply
#3

Sure. Here's a skin command with explainations:

pawn Код:
if(!strcmp(cmdtext, "/skin", true, 5)) // 5 is the length of "/skin" (without quotes)
{
    if(!cmdtext[5]) // if it's only 5 characters (/skin is) tell them the right usage of it
    {
        SendClientMessage(playerid, COLOR_RED, "COST: $20000");
        return SendClientMessage(playerid, -1, "USAGE: /skin [skinid]");
    }
    // Here they entered something after /skin
    // cmdtext[6] is what the player typed after /skin but we can't use it because it's a string so
    // use strval to get the value of cmdtext string
    new skinid = strval(cmdtext[6]);
    if(skinid < 0 || skinid > 299) // IMPORTANT: check if the skin id below 0 or above 299 because it can cause a crash
        return SendClientMessage(playerid, -1, "ERROR: Invalid skin id!");

    if(GetPlayerMoney(playerid) < 20000)
        return SendClientMessage(playerid, COLOR_RED, "ERRO: You don't have enough money to change your skin.");

    GivePlayerMoney(playerid, -20000);
    SetPlayerSkin(playerid, skinid);
    return 1;
}
You may like to check this article about using strcmp for creating commands with multiple parameters.
Reply
#4

I don't use ZCMD, Can you make 1 with strcmp?
Reply
#5

Quote:
Originally Posted by [MM]RoXoR[FS]
Посмотреть сообщение
pawn Код:
#include <sscanf2>
#include <ZCMD>

CMD:skin(playerid,params[])
{
 new id;
 if(sscanf(params,"i",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE : /skin id \nCost : $20000");
 if(id<0 || id>299) return SendClientMessage(playerid,COLOR_RED,"Invalid ID : Usable ID 0-299");
 if(GetPlayerMoney(playerid) < 20000) return SendClientMessage(playerid,COLOR_RED,"Min amount needed is 20000$");
 SetPlayerSkin(playerid,id);
 GivePlayerMoney(playerid,-20000);
 new msg[50];
 format(msg,sizeof(msg),"Your skin has been set to ID %d",id);
 return SendClientMessage(playerid,-1,msg);
}
That won't work if he has strcmd on his script, but i'm sure he has the skills to convert it.
Reply
#6

@Hell

Thanks
Reply
#7

Quote:
Originally Posted by Arthur_K
Посмотреть сообщение
I don't use ZCMD, Can you make 1 with strcmp?
Ok
pawn Код:
#include <sscanf2>
public OnPlayerCommandText(playerid,cmdtext[])
{
  if(strcmp(cmdtext,"/skin",true)== 0)
  {
    new id;
    if(sscanf(cmdtext,"i",id)) return SendClientMessage(playerid,COLOR_RED,"USAGE : /skin id \nCost : $20000");
    if(id<0 || id>299) return SendClientMessage(playerid,COLOR_RED,"Invalid ID : Usable ID 0-299");
    if(GetPlayerMoney(playerid) < 20000) return SendClientMessage(playerid,COLOR_RED,"Min amount needed is 20000$");
    SetPlayerSkin(playerid,id);
    GivePlayerMoney(playerid,-20000);
    new msg[50];
    format(msg,sizeof(msg),"Your skin has been set to ID %d",id);
    return SendClientMessage(playerid,-1,msg);
  }
  return 0;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)