SA-MP Forums Archive
Code don't work, - Please help! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Code don't work, - Please help! (/showthread.php?tid=180213)



Code don't work, - Please help! - Danny - 30.09.2010

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.


Re: Code don't work, - Please help! - wups - 30.09.2010

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;
        }
    }
}



Re: Code don't work, - Please help! - samgreen - 01.10.2010

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?