stock GetDrugName ( playerid ) { new drugname [ 30 ]; for( new slot = 0; slot != 12; slot++ ) { if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 1 ) { drugname = "Marijuana"; } if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 2 ) { drugname = "Cocaine"; } if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 3 ) { drugname = "Heroine"; } } return drugname; }
format(string, sizeof(string), "[ 1. %s (%d) ]", GetDrugName(PlayerInfo [ playerid ] [ pDrug ] [ 0]), PlayerInfo[playerid][pDrugAmount][0]);
GetDrugName(drugid)
{
static const DRUG_NAMES[][] = {
"Marijuana",
"Cocaine",
"Heroine"
// more ...
};
return (0 <= drugid< sizeof DRUG_NAMES) ? (DRUG_NAMES[drugid]) : ("Unknown");
}
error 001: expected token: ";", but found "return"
return (0 <= slot < sizeof DRUG_NAMES) ? (DRUG_NAMES[slot]) : ("Unknown");
GetDrugName ( playerid ) {
new drugname [ 30 ];
for( new slot = 0; slot != 12; slot++ )
{
if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 1 ) { drugname = "Marijuana"; }
if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 2 ) { drugname = "Cocaine"; }
if ( PlayerInfo [ playerid ] [ pDrug ] [ slot ] == 3 ) { drugname = "Heroine"; }
}
return drugname;
}
format(string, sizeof(string), "[ 1. %s (%d) ]", GetDrugName(playerid), PlayerInfo[playerid][pDrugAmount][0]);
PHP код:
|
GetDrugName(playerid, slotID) {
new drugname [30];
switch(PlayerInfo [ playerid ] [ pDrug ] [ slotID ]) {
case 1: {
drugname = "Marijuana";
}
case 2: {
drugname = "Cocaine";
}
case 3: {
drugname = "Heroine";
}
default: {
drugname = "-255";
}
}
return drugname;
}
public OnPlayerConnect(playerid) {
new string[128];
for( new slot = 0; slot < 13; slot++ ) {
new drugname[30];
drugname = GetDrugName(playerid, slot);
if(strval(drugname) != -255) {
format(string, sizeof(string), "%s[ %d. %s (%d) ], ",string, slot+1, GetDrugName(playerid, slot), PlayerInfo[playerid][pDrugAmount][slot]);
}
}
}