Need two solutions for two problems -
Edward2013 - 11.08.2013
Hello. The title says everything.
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
new index, cmd[20];
cmd = strtok(cmdtext, index);
if (strcmp(cmd, "/heal", true) == 0)
{
new tmp[20];
tmp = strtok(cmdtext, index);
if(!strlen(tmp)) return SendClientMessage(playerid, 0xFF0000AA, "Usage : /heal <ID>");
if(!IsPlayerConnected(strval(tmp))) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
SetPlayerHealth(strval(tmp), 100.0);
SendClientMessage(strval(tmp), 0x00FF00AA, "You have been healed");
SendClientMessage(playerid, 0x00FF00AA, "Player healed");
return 1;
}
return 0;
}
I get these errors in this code -
D:\Games\Grand Theft Auto (GTA) San Andreas-HOODLUM\GTA San Andreas\filterscripts\revive.pwn(36) : error 033: array must be indexed (variable "cmd")
D:\Games\Grand Theft Auto (GTA) San Andreas-HOODLUM\GTA San Andreas\filterscripts\revive.pwn(41) : error 033: array must be indexed (variable "tmp")
How to fix it?
Код:
if(strcmp(cmd, "/sellvehicle", true) == 0)
{
new pvehicleid = GetPlayerVehicleID(playerid);
if(IsPlayerConnected(playerid))
{
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
return 1;
}
giveplayerid = ReturnUser(tmp);
tmp = strtok(cmdtext, idx);
if(!strlen(tmp))
{
SendClientMessage(playerid, COLOR_WHITE, "USAGE: /sellvehicle [playerid/PartOfName] [price]");
return 1;
}
new price = strvalEx(tmp);
if(IsPlayerConnected(giveplayerid))
{
if(ProxDetectorS(7.0, playerid, giveplayerid))
{
if(IsPlayerInAnyVehicle(playerid))
{
if(PlayerVehicleID1[playerid] == pvehicleid)
{
SellVehicleOffer[giveplayerid] = playerid;
SellVehicleOfferTime[giveplayerid] = 60;
SellVehiclePrice[giveplayerid] = price;
SellVehicleSlot[giveplayerid] = 1;
format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"%s has just offered to sell you their %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
SendClientMessage(giveplayerid,COLOR_YELLOW,string);
}
else if(PlayerVehicleID2[playerid] == pvehicleid)
{
SellVehicleOffer[giveplayerid] = playerid;
SellVehicleOfferTime[giveplayerid] = 60;
SellVehiclePrice[giveplayerid] = price;
SellVehicleSlot[giveplayerid] = 2;
format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"%s has just offered to sell you their %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
SendClientMessage(giveplayerid,COLOR_YELLOW,string);
}
else if(PlayerVehicleID3[playerid] == pvehicleid)
{
SellVehicleOffer[giveplayerid] = playerid;
SellVehicleOfferTime[giveplayerid] = 60;
SellVehiclePrice[giveplayerid] = price;
SellVehicleSlot[giveplayerid] = 3;
format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"%s has just offered to sell you their %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
SendClientMessage(giveplayerid,COLOR_YELLOW,string);
}
else if(PlayerVehicleID4[playerid] == pvehicleid)
{
SellVehicleOffer[giveplayerid] = playerid;
SellVehicleOfferTime[giveplayerid] = 60;
SellVehiclePrice[giveplayerid] = price;
SellVehicleSlot[giveplayerid] = 4;
format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"%s has just offered to sell you their %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
SendClientMessage(giveplayerid,COLOR_YELLOW,string);
}
else if(PlayerVehicleID5[playerid] == pvehicleid)
{
SellVehicleOffer[giveplayerid] = playerid;
SellVehicleOfferTime[giveplayerid] = 60;
SellVehiclePrice[giveplayerid] = price;
SellVehicleSlot[giveplayerid] = 5;
format(string,sizeof(string),"You have offered to sell your %s to %s for $%d.",vehName[GetVehicleModel(pvehicleid)-400],PlayerName(giveplayerid),price);
SendClientMessage(playerid,COLOR_YELLOW,string);
format(string,sizeof(string),"%s has just offered to sell you their %s for $%d, /accept vehicle to buy the vehicle.",PlayerName(playerid),vehName[GetVehicleModel(pvehicleid)-400],price);
SendClientMessage(giveplayerid,COLOR_YELLOW,string);
}
else
{
SendClientMessage(playerid,COLOR_GREY," You are not at a vehicle that you own.");
}
}
else
{
SendClientMessage(playerid,COLOR_GREY," You are not at any vehicle.");
}
}
else
{
SendClientMessage(playerid,COLOR_GREY," You are not near the player.");
}
}
else
{
SendClientMessage(playerid,COLOR_GREY," Player Not Connected.");
}
}
return 1;
}
I need help to create /accept vehicle command. This is the /sellvehicle code.
Re: Need two solutions with two problems -
Misiur - 11.08.2013
Don't use strcmp for commands, use ycmd/zcmd instead. Your strtok is diffrent than usual implementation, could you show it?
Re: Need two solutions with two problems -
Alternative112 - 11.08.2013
pawn Код:
CMD:heal(playerid, params[]) {
new id;
if (sscanf(params, "u", id)) return SendClientMessage(playerid, 0xFF0000AA, "Usage : /heal <ID>");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid, 0xFF0000AA, "Player not found");
SetPlayerHealth(id, 100.0);
SendClientMessage(id, 0x00FF00AA, "You have been healed");
SendClientMessage(playerid, 0x00FF00AA, "Player healed");
return 1;
}
strtok and strcmp commands = no. Once you get zcmd and sscanf, just copy and paste that code and the first should be fine.