Code don't work, - Please help!
#1

Hello,
I try to make a code that makes possible to tow other cars with a towtruck, Only this piece of code dont work, whats wrong with it?:

Код:
dcmd_tow(playerid, cmdtext[]) {
	#pragma unused cmdtext
	new VID = GetPlayerVehicleID(playerid);
	if(GetVehicleModel(VID) != 525) {
	    SendClientMessage(playerid, COLOR_RED,"You have to be in a towtruck to tow a car."); return 1;
    }
	if(GetPlayerVehicleSeat(playerid) != 0) {
        SendClientMessage(playerid, COLOR_RED,"You have to be the driver to tow a car."); return 1;
    }
    new Float:vX,Float:vY,Float:vZ;
    new towtruckdriver = playerid;
    for(new c = 0; c < MAX_VEHICLES; c++)
	{
		GetVehiclePos(c, vX, vY, vZ);
		if(IsPlayerInRangeOfPoint(towtruckdriver, 20.0, vX, vY, vZ))
		{
           	AttachTrailerToVehicle(c, VID);
           	SendClientMessage(towtruckdriver, COLOR_RED,"You have succesfully attached a vehicle!");
           	return 1;
		}
 		else
  		{
			SendClientMessage(towtruckdriver,COLOR_RED,"There is no towable vehicle in range.");
			return 1;
		}
	}
}
NOTE: I know that there's a filterscript that does this, but i want to make it myself.
Reply
#2

pawn Код:
dcmd_tow(playerid, cmdtext[]) {
    #pragma unused cmdtext
    new VID = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(VID) != 525) return  SendClientMessage(playerid, COLOR_RED,"You have to be in a tow truck");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED,"You have to be the driver to tow a car.");
    new Float:vX,Float:vY,Float:vZ;
    for(new c = 0; c < MAX_VEHICLES; c++)
    {
        GetVehiclePos(c, vX, vY, vZ);
        if(IsPlayerInRangeOfPoint(playerid, 20.0, vX, vY, vZ) && c != VID)
        {
                AttachTrailerToVehicle(c, VID);
                SendClientMessage(playerid, COLOR_RED,"You have succesfully attached a vehicle!");
                break;
        }
    }
}
Reply
#3

pawn Код:
// samgreen: I believe it is dcmd practice to name this variable params
dcmd_tow(playerid, params[]) {
    // If you use zcmd you will not have to suppress this warning.
    #pragma unused params

    new VID = GetPlayerVehicleID(playerid);
    if(GetVehicleModel(VID) != 525) return  SendClientMessage(playerid, COLOR_RED,"You have to be in a tow truck");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED,"You have to be the driver to tow a car.");
    new Float:vX,Float:vY,Float:vZ;
    for(new c = 0; c < MAX_VEHICLES; c++)
    {
        GetVehiclePos(c, vX, vY, vZ);
        if(IsPlayerInRangeOfPoint(playerid, 20.0, vX, vY, vZ) && c != VID)
        {
                AttachTrailerToVehicle(c, VID);
                SendClientMessage(playerid, COLOR_RED,"You have succesfully attached a vehicle!");
                break;
        }
    }
}
Now try this code and explain to us exactly how it is not working? Is it not attaching the vehicles? Are you getting any status messages?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)