give gun to a player
#1

The command
Код:
CMD:spray(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 2 || PlayerInfo[playerid][pFaction] != 5) return SCM(playerid, COLOR_LIGHTRED, "Nu esti mechanic.");
    if(IsPlayerInRangeOfPoint(playerid, 20.0, 2180.9875,-1979.7583,13.5606)) //Optional - CHANGE
	{
		new string[128], sendername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], pID;
	 	GetPlayerName(playerid, sendername, sizeof(sendername));
		GetPlayerName(pID, targetname, sizeof(targetname));
		if(sscanf(params, "uii", pID, pick, color)) return SendClientMessage(playerid, -1, "[FOLOSIRE] /spray [ID/Name][Culoare 1/2][culoare]");
		if(pick > 2 || pick < 1) return SendClientMessage(playerid, COLOR_RED,"Colorpick can't be lower than 1 and higher than 2.");
		if(color > 126 || color < 0) return SendClientMessage(playerid, COLOR_RED,"Color ID can't be lower than 0 and higher than 126.");
		vehid = GetPlayerVehicleID(pID);
		format(string, sizeof(string), "%s vrea sa-ti vopseasca vehiculul. Slot Culoare: {FFFFFF}%d{468CFF}, ID Culoare: {FFFFFF}%d", PlayerName(playerid), pick, color);
		SendClientMessage(pID, COLOR_LIGHTBLUE, string);
		SendClientMessage(pID, COLOR_LIGHTBLUE, "Foloseste /acceptmeh pentru a accepta.");
		Service[pID][0] = 1;
	}
	else return SendClientMessage(playerid, COLOR_RED, "Trebuie sa fii in garaj pentru a repara!");
	return 1;
}
The other command, just Service[playerid][0] == 1 is for spray others are for repair
Код:
CMD:acceptmeh(playerid, params[])
{
    new Float: X, Float: Y, Float: Z, pID;
	if(Service[playerid][0] == 1)
	{
		SendClientMessage(playerid, -1, "Ai acceptat serviciul, te rugam asteapta!");
		GetVehiclePos(vehid, X, Y, Z);
		Car[1] = X;
		Car[2] = Y;
		Car[3] = Z;
		Spray[pID] = 1;
		GivePlayerWeapon(pID, 41, 500);
	}
	else if(Service[playerid][1] == 1)
	{
	    new panels,doors,lights,tires;
	   	SendClientMessage(playerid, COLOR_LIGHTBLUE, "Ai acceptat serviciul, te rugam asteapta!");
		vehid = GetPlayerVehicleID(playerid);
		tires = encode_tires(0, 0, 0, 0); // fix all tires
	    panels = encode_panels(0, 0, 0, 0, 0, 0, 0); // fix all panels
	    doors = encode_doors(0, 0, 0, 0, 0, 0); // fix all doors
	    lights = encode_lights(0, 0, 0, 0); // fix all lights
		UpdateVehicleDamageStatus(vehid, panels, doors, lights, tires);
		Service[playerid][1] = 0;
		SendClientMessage(playerid, COLOR_GREEN, "Caroseria vehiculului a fost reparata!");
	}
	else if(Service[playerid][2] == 1)
	{
	    SendClientMessage(playerid, COLOR_LIGHTBLUE, "Ai acceptat serviciul, te rugam asteapta!");
		vehid = GetPlayerVehicleID(playerid);
		SetVehicleHealth(vehid, 1000.0);
		Service[playerid][2] = 0;
		SendClientMessage(playerid, COLOR_GREEN, "Motorul vehiculului a fost reparat!");
	}
	else return SendClientMessage(playerid, COLOR_RED, "Nu ti-a oferit nimeni sa-ti repare masina!");
	return 1;
}
The timer
Код:
forward OnPlayerSpray(playerid);
public OnPlayerSpray(playerid)
{
    if(pick == 1)
	{
    	ChangeVehicleColor(vehid, color, 0);
    	VehicleColor[playerid][0] = color;
	}
	else
	{   //new pID;
	    //new color2 = strval(inputtext);
		ChangeVehicleColor(vehid, 0, color);
		VehicleColor[playerid][1] = color;
		KillTimer(SprayT);
		Spray[playerid] = 0;
		Service[playerid][0] = 0;
		SaveVehicle(playerid);
		SendClientMessage(playerid, COLOR_GREEN, "Ai vopsit masina cu succes!");
	}
	return 1;
}
the timer
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if(newkeys & KEY_FIRE)
	{
	    if(IsPlayerInRangeOfPoint(playerid, 3.0, Car[1], Car[2], Car[3]))
	    {
		    if(Spray[playerid] == 1)
		    {
	    		SprayT = SetTimer("OnPlayerSpray", 5000, false);
		    }
		}
	}
	else return KillTimer(SprayT);
	return 1;
}
So if I use /spray on someone everything works fine, I get the can and spray the vehicle but if someone use the command on me and I /acceptmeh I will get the can, not them, also if they acceptmeh without any command I will still get a spray can..

I want that the guy who /spray me will get the can and the Spray[pID] = 1;, not me
Reply
#2

PHP код:
new Requested[MAX_PLAYER]; //EDIT
CMD:spray(playeridparams[])
{
    if(
PlayerInfo[playerid][pAdmin] < || PlayerInfo[playerid][pFaction] != 5
        return 
SCM(playeridCOLOR_LIGHTRED"Nu esti mechanic.");
    if(
IsPlayerInRangeOfPoint(playerid20.02180.9875,-1979.7583,13.5606)) //Optional - CHANGE
    
{
        new 
string[128], sendername[MAX_PLAYER_NAME], targetname[MAX_PLAYER_NAME], pID;
         
GetPlayerName(playeridsendernamesizeof(sendername));
        
//GetPlayerName(pID, targetname, sizeof(targetname)); //EDIT
        
if(sscanf(params"uii"pIDpickcolor)) 
        return 
SendClientMessage(playerid, -1"[FOLOSIRE] /spray [ID/Name][Culoare 1/2][culoare]");
        if(
pID == INVALID_PLAYER_ID || !IsPlayerConnected(pID))
            return 
SendClientMessage(playeridCOLOR_RED"Invalid PlayerID/PlayerName.");
        if(
pick || pick 1
            return 
SendClientMessage(playeridCOLOR_RED,"Colorpick can't be lower than 1 and higher than 2.");
        if(
color 255 || color 0//Refer: https://sampwiki.blast.hk/wiki/Vehicle_Color_IDs 0 - 255 COlors EDIT
            
return SendClientMessage(playeridCOLOR_RED,"Color ID can't be lower than 0 and higher than 255.");
        
GetPlayerName(pIDtargetnamesizeof(targetname)); //EDIT
        
vehid GetPlayerVehicleID(pID);
        
format(stringsizeof(string), "%s vrea sa-ti vopseasca vehiculul. Slot Culoare: {FFFFFF}%d{468CFF}, ID Culoare: {FFFFFF}%d"PlayerName(playerid), pickcolor);
        
SendClientMessage(pIDCOLOR_LIGHTBLUEstring);
        
SendClientMessage(pIDCOLOR_LIGHTBLUE"Foloseste /acceptmeh pentru a accepta.");
        
Service[pID][0] = 1;
        
//Suggestion
        
Requested[pID] = playerid//EDIT
    
}
    else 
        return 
SendClientMessage(playeridCOLOR_RED"Trebuie sa fii in garaj pentru a repara!");
    return 
1;
}
CMD:acceptmeh(playeridparams[])
{
    new 
FloatXFloatYFloatZpID;
    
pID Requested[playerid]; // You were not assigning pID to anything.. So pID was always 0..
    
if(Service[playerid][0] == 1)
    {
        
SendClientMessage(playerid, -1"Ai acceptat serviciul, te rugam asteapta!");
        
GetVehiclePos(vehidXYZ);
        
Car[1] = X;
        
Car[2] = Y;
        
Car[3] = Z;
        
Spray[pID] = 1;
        
GivePlayerWeapon(pID41500);
    }
    else if(
Service[playerid][1] == 1)
    {
        new 
panels,doors,lights,tires;
           
SendClientMessage(playeridCOLOR_LIGHTBLUE"Ai acceptat serviciul, te rugam asteapta!");
        
vehid GetPlayerVehicleID(playerid);
        
tires encode_tires(0000); // fix all tires
        
panels encode_panels(0000000); // fix all panels
        
doors encode_doors(000000); // fix all doors
        
lights encode_lights(0000); // fix all lights
        
UpdateVehicleDamageStatus(vehidpanelsdoorslightstires);
        
Service[playerid][1] = 0;
        
SendClientMessage(playeridCOLOR_GREEN"Caroseria vehiculului a fost reparata!");
    }
    else if(
Service[playerid][2] == 1)
    {
        
SendClientMessage(playeridCOLOR_LIGHTBLUE"Ai acceptat serviciul, te rugam asteapta!");
        
vehid GetPlayerVehicleID(playerid);
        
SetVehicleHealth(vehid1000.0);
        
Service[playerid][2] = 0;
        
SendClientMessage(playeridCOLOR_GREEN"Motorul vehiculului a fost reparat!");
    }
    else return 
SendClientMessage(playeridCOLOR_RED"Nu ti-a oferit nimeni sa-ti repare masina!");
    return 
1;
}
forward OnPlayerSpray(playerid);
public 
OnPlayerSpray(playerid)
{
    if(
pick == 1)
    {
        
ChangeVehicleColor(vehidcolor0);
        
VehicleColor[playerid][0] = color;
    }
    else
    {   
//new pID;
        //new color2 = strval(inputtext);
        
ChangeVehicleColor(vehid0color);
        
VehicleColor[playerid][1] = color;
        
KillTimer(SprayT);
        
Spray[playerid] = 0;
        
Service[playerid][0] = 0;
        
SaveVehicle(playerid);
        
SendClientMessage(playeridCOLOR_GREEN"Ai vopsit masina cu succes!");
    }
    return 
1;
}
public 
OnPlayerKeyStateChange(playeridnewkeysoldkeys)
{
    if(
newkeys KEY_FIRE)
    {
        if(
IsPlayerInRangeOfPoint(playerid3.0Car[1], Car[2], Car[3]))
        {
            if(
Spray[playerid] == 1)
            {
                
SprayT SetTimer("OnPlayerSpray"5000false);
            }
        }
    }
    else return 
KillTimer(SprayT);
    return 
1;

Reply
#3

It is working now, but after I painted his car and I send him a repair request, if he accep i'll get the spray can instead fixing the veh
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)