Need help fixing /fixveh
#1

So, I thought my code was fine... I'm wondering what's wrong.. When I type the command properly, nothing shows up, and the car doesn't repair. But if I type /fixveh, it does the client message stating proper usage ofc. What's wrong?

Код:
	if(strcmp(cmd, "/fixveh", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
    	{
    	    new playa;
			playa = ReturnUser(tmp);
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
	 			SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fixveh [playerid/PartOfName]");
	            return 1;
			}
	        if(PlayerInfo[playerid][pAdmin] < 4)
			{
				SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !"); return 1;
			}
			if(IsPlayerConnected(playa))
			{
			    if(playa != INVALID_PLAYER_ID)
			    {
					if(IsPlayerInAnyVehicle(playerid))
					{
						SetVehicleHealth(GetPlayerVehicleID(playerid), 1000.0);
						RepairVehicle(GetPlayerVehicleID(playerid));
						SendClientMessage(playerid, COLOR_GREY, string);
      					format(string, sizeof(string), "* Admin %s has fixed your vehicle.",sendername);
					}
					else
					{
   						SendClientMessage(playerid, COLOR_GREY, string);
						format(string, sizeof(string),"I know you could fix cars, but since when can you fix players? %s isn't in a car. -Alex", PlayerName(giveplayerid));
					}
				}
   			}
		}
		return 1;
	}
Reply
#2

You're formatting the string after you send the clients message. That may be your issue with not seeing any message. You are also repairing your car rather than the other players. I would also highly recommend using something like ZCMD and sscanf because it's fare more efficient and and easy to understand.

pawn Код:
CMD:fixveh(playerid, params[])
{
    new id;
    if(sscanf(params, "u", id)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fixveh [playerid/PartOfName]");
    if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !");
    if(IsPlayerInAnyVehicle(id))
    {
        new vid = GetPlayerVehicleID(id);
        SetVehicleHealth(vid, 1000.0);
        RepairVehicle(GetPlayerVehicleID(vid));
        format(string, sizeof(string), "* Admin %s has fixed your vehicle.", sendername);
        SendClientMessage(playerid, COLOR_GREY, string);
    }
    else
    {
        format(string, sizeof(string),"I know you could fix cars, but since when can you fix players? %s isn't in a car. -Alex", PlayerName(giveplayerid));
        SendClientMessage(playerid, COLOR_GREY, string);
    }
    return 1;
}
So much easier isn't it :P?
Reply
#3

Switching to ZMD right now isn't an option for me. Thanks for the code, I'm doing something right now, but when I'm done I'll convert it and reply with my results.
Reply
#4

[code]
Fixed. I converted it from ZCMD. Your code has 1 or 2 flaws, but I made mine work perfectly. Thanks a lot - For any others with this problem or who needs it; here's the code.

Код:
	if(strcmp(cmd, "/fixveh", true) == 0)
	{
	    if(IsPlayerConnected(playerid))
	    {
			if(PlayerInfo[playerid][pAdmin] <=4)
			{
				SendClientMessage(playerid, COLOR_GRAD1, " You are not authorized to use that command !"); return 1;
			}
			tmp = strtok(cmdtext, idx);
			if(!strlen(tmp))
			{
			return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /fixveh [PlayerID/PartOfName]");
			}
			new playa;
			playa = ReturnUser(tmp);
			if(IsPlayerInAnyVehicle(playa))
			{
				new vid = GetPlayerVehicleID(playa);
				SetVehicleHealth(vid, 1000.0);
				RepairVehicle(GetPlayerVehicleID(playa));
				GetPlayerName(playerid, sendername, sizeof(sendername));
				format(string, sizeof(string), "* Admin %s has fixed your vehicle.", sendername);
				SendClientMessage(playa, COLOR_GREY, string);
			}
			else
			{
				format(string, sizeof(string),"I know you could fix cars, but since when can you fix players? %s isn't in a car. -Alex", PlayerName(giveplayerid));
				SendClientMessage(playerid, COLOR_GREY, string);
			}
			return 1;
		}
	}
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)