new cmd[256], vehicleid = GetPlayerVehicleID(playerid), v = GetPlayerVehicleID(playerid), idx, str[256];
cmd = strtok(cmdtext, idx);
strtok(const string[], &index)
{
new length = strlen(string);
while ((index < length) && (string[index] <= ' '))
{
index++;
}
new offset = index;
new result[20];
while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
{
result[index - offset] = string[index];
index++;
}
result[index - offset] = EOS;
return result;
}
add this to your script
pawn Код:
|
public OnPlayerCommandText(playerid, cmdtext[])
{
new cmd[256], vehicleid = GetPlayerVehicleID(playerid), v = GetPlayerVehicleID(playerid), idx, str[256];
cmd = strtok(cmdtext, idx);
if(!strcmp(cmd,"/BuyCar",true))
{
if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid,red,"You are not in a vehicle");
if(dini_Int(CarFile(vehicleid),"Owned")==1) return SendClientMessage(playerid,red," this car is already owned.");
if(dini_Int(CarFile(vehicleid),"Public")==1) return SendClientMessage(playerid,red," this car is unbuyable ");
if(dini_Int(PFile(playerid),"GotCar")==1) return SendClientMessage(playerid,red,"you already have a car ");
if(GetPlayerMoney(playerid) < 200000) return SendClientMessage(playerid,red,"You dont have the money (200000$)");
if(!dini_Exists(PFile(playerid)))
{
dini_Create(PFile(playerid));
dini_IntSet(PFile(playerid),"GotCar",1);
dini_IntSet(PFile(playerid),"CarId",vehicleid);
}
else if(dini_Exists(PFile(playerid)))
{
dini_IntSet(PFile(playerid),"GotCar",1);
dini_IntSet(PFile(playerid),"CarId",vehicleid);
}
if(!dini_Exists(CarFile(vehicleid)))
{
dini_Create(CarFile(vehicleid));
dini_Set(CarFile(vehicleid),"Owner",Gn(playerid));
dini_IntSet(CarFile(vehicleid),"Owned",1);
}
else if(dini_Exists(CarFile(vehicleid)))
{
dini_Set(CarFile(vehicleid),"Owner",Gn(playerid));
dini_IntSet(CarFile(vehicleid),"Owned",1);
}
format(str,256,"You bought a new %s",VehNames[GetVehicleModel(vehicleid)-400]);
SendClientMessage(playerid,green,str);
PlayerPlaySound(playerid,1056,0.0,0.0,0.0);
SendClientMessage(playerid,white,"To call your car use /CallCar");
format(TextCar,sizeof(TextCar),"This car %s\nBelong To %s",VehNames[GetVehicleModel(v)-400],dini_Get(CarFile(v),"Owner"));
Update3DTextLabelText(TextUpCar[vehicleid],colors[random(sizeof(colors))],TextCar);
Attach3DTextLabelToVehicle(TextUpCar[vehicleid],vehicleid,0.0,0.0,0.0);
GivePlayerMoney(playerid,-200000);
return 1;
}