Breaking Lock Command
#1

It's me again, feeling like a huge idiot.

I have this really.. really messy command that i have no idea how to make work and was wondering if i could get some help. I basically want it so that you type /breaklock beside a car and you start to break the lock, if it fails then you loose a screwdriver and if it's successful then the doors of the car unlock.

Anyways, that's what i want and here's the really messy code. I apologise in advance

Код:
CMD:breaklock(playerid, params[])
{
	GetPlayerDistanceFromPoint(playerid, Positions[0][0], Positions[0][1], Positions[0][2]);
 	GetVehicleDistanceFromPoint(vehicleid, Positions[1][0], Positions[1][1], Positions[1][2]);
 	if(Positions[1][0] > 5 && Positions[1][1] > 5 && Positions[1][2] > 5) return SendClientMessage(playerid, COLOR_GRAD1, "I'm afraid you're too far away!");
	if(PlayerInfo[playerid][pScrewdriver] != 1) return SendClientMessage(playerid, COLOR_GRAD1, "You need a screwdriver to access this command!");
	if(PlayerInfo[playerid][pScrewdriver] >= 1)
	{
		new randnum = Random(1, 100);
		if(randnum >= 1 && randnum <= 49)
		{
		    SendClientMessage(playerid, COLOR_RED, "WARNING: {FFFFFF} You have failed to unlock this car and the screwdriver broke!");
		    PlayerInfo[playerid][pScrewdriver] = -1;
		    return 1;
		}
	    if(randnumb >= 50)
	    {
	        SendClientMessage(playerid, COLOR_RED, "WARNING: {FFFFFF} You've successfully broken the cars lock!");
	        PlayerVehicleInfo[ownerid][pvLocked] = 0;
	    }
	}
	return 1;
}
Reply
#2

First, the function is not "Random" but "random".
Second, it can't be used like random(1, 100);, if you just want a random between 100 use random(100);
Reply
#3

I use this and it works all good:

Код:
CMD:breaklock(playerid, params[])
{
	if(PlayerInfo[playerid][pScrewdriver] > 0)
	{
	    new Float:x, Float:y, Float:z, string[128];
	    foreach(Player, i)
	    {
	        for(new d = 0 ; d < MAX_PLAYERVEHICLES; d++)
		    {
		        if(PlayerVehicleInfo[i][d][pvId] != INVALID_PLAYER_VEHICLE_ID) GetVehiclePos(PlayerVehicleInfo[i][d][pvId], x, y, z);
		        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
				{
				    if(IsAPersonalCopCar(PlayerVehicleInfo[i][d][pvId]))
				    {
				        SendClientMessageEx(playerid, COLOR_GRAD2, "  You cannot steal this vehicle.");
				        return 1;
				    }
				    else if(PlayerVehicleInfo[i][d][pvLocked] == 1)
				    {
				        format(string, sizeof(string), "* %s takes out a screwdriver and begins attempting to break the door lock.", GetPlayerNameEx(playerid));
						ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

						TogglePlayerControllable(playerid, 0);
						GameTextForPlayer(playerid, "~r~Attempting to break the vehicles lock...", 5000, 3);

						SetTimerEx("BreakVehicleLock", 5000, 0, "ididd", playerid, PlayerVehicleInfo[i][d][pvId], i, d, 0);
						return 1;
					}
				    else
				    {
				        SendClientMessageEx(playerid, COLOR_GRAD2, "  The vehicle door is not locked, just open it!");
				        return 1;
					}
				}
			}
	    }
	    for(new f=0; f<MAX_FAMILY; f++)
	    {
	        for(new d = 0 ; d < MAX_GANG_VEHICLES; d++)
		    {
		        if(FamilyVehicleInfo[f][d][fvId] != INVALID_PLAYER_VEHICLE_ID) GetVehiclePos(FamilyVehicleInfo[f][d][fvId], x, y, z);
		        if(IsPlayerInRangeOfPoint(playerid, 3.0, x, y, z))
				{
				    if(IsAPersonalCopCar(FamilyVehicleInfo[f][d][fvId]))
				    {
				        SendClientMessageEx(playerid, COLOR_GRAD2, "  You cannot steal this vehicle.");
				        return 1;
				    }
				    else if(FamilyVehicleInfo[f][d][fvLocked] == 1)
				    {
				        format(string, sizeof(string), "* %s takes out a screwdriver and begins attempting to break the door lock.", GetPlayerNameEx(playerid));
						ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

						TogglePlayerControllable(playerid, 0);
						GameTextForPlayer(playerid, "~r~Attempting to break the vehicles lock...", 5000, 3);

						SetTimerEx("BreakVehicleLock", 5000, 0, "idddd", playerid, FamilyVehicleInfo[f][d][fvId], f, d, 1);
						return 1;
					}
				    else
				    {
				        SendClientMessageEx(playerid, COLOR_GRAD2, "  The vehicle door is not locked, just open it!");
				        return 1;
					}
				}
			}
	    }
	    SendClientMessageEx(playerid, COLOR_GRAD2, "  You are not near a car that can be broken in to!");
	}
	else
	{
	    SendClientMessageEx(playerid, COLOR_GRAD2, "  You do not have a screwdriver, which is needed to break the lock!");
	}
	return 1;
}
Make sure to define colors and other stuffs to void errors!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)