I need your help
#1

Hi, samp forum.

Can i make this code smaller

Код:
if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND4)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND5)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND6)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND7)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND8)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDUND9)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	  if(vehicleid == PD_LSPDTAXI)
   {
      if(PInfo[playerid][pCop] <= 7)
        {
            new Float:x, Float:y, Float:z;
            GetPlayerPos(playerid, x, y, z);
            SetPlayerPos(playerid, x, y, z+1);
            SendClientMessage(playerid,0xAA3333AA, "You are not a Detective I");
        }
	  }
	    return 0;
}
When i remove this code
Код:
	PD_CAR = CreateVehicle(596,1558.8412,-1711.6847,5.6107,0.2152,0,1); // LSPD1
	PD_CAR2 = CreateVehicle(596,1562.9648,-1711.0802,5.6118,0.0865,0,1); // LSPD2
	PD_CAR3 = CreateVehicle(596,1570.4252,-1711.2849,5.6113,0.1652,0,1); // LSPD3
	PD_CAR4 = CreateVehicle(596,1574.5020,-1711.2111,5.6105,0.7812,0,1); // LSPD4
	PD_CAR5 = CreateVehicle(596,1578.6610,-1711.2418,5.6115,359.9628,0,1); // LSPD5
	PD_CAR6 = CreateVehicle(596,1583.5205,-1711.1624,5.6111,359.9993,0,1); // LSPD6
	PD_CAR7 = CreateVehicle(596,1587.4843,-1710.9558,5.6105,359.5211,0,1); // LSPD7
	PD_CAR8 = CreateVehicle(596,1591.5603,-1710.9192,5.6110,0.3880,0,1); // LSPD8
	PD_CAR9 = CreateVehicle(596,1595.4760,-1711.1044,5.6106,359.1207,0,1); // LSPD9
	PD_CAR10 = CreateVehicle(596,1601.6406,-1704.0292,5.6107,90.6271,0,1); // LSPD10
	PD_CAR11 = CreateVehicle(596,1601.4740,-1700.0243,5.6108,90.7542,0,1); // LSPD11
	PD_CAR12 = CreateVehicle(596,1601.4498,-1696.0110,5.6109,90.4040,0,1); // LSPD12
	PD_CAR13 = CreateVehicle(596,1601.6042,-1692.0181,5.6109,90.1785,0,1); // LSPD13
	PD_CAR14 = CreateVehicle(596,1601.5448,-1687.9376,5.6109,90.5516,0,1); // LSPD14
	PD_CAR15 = CreateVehicle(596,1601.8317,-1683.8500,5.6108,89.6264,0,1); // LSPD15
	PD_NRG = CreateVehicle(521,1599.4846,-1713.0972,5.4622,15.1706,0,1); // LSPDSpeedBike
	PD_HPV = CreateVehicle(523,1604.4741,-1670.3304,5.4618,90.2007,0,1); // LSPDHPV1
	PD_HPV2 = CreateVehicle(523,1604.4326,-1672.7900,5.4645,92.6691,0,1); // LSPDHPV2
	PD_HPV3 = CreateVehicle(523,1603.4644,-1676.4287,5.4600,87.8529,0,1); // LSPDHPV3
	PD_HPV4 = CreateVehicle(523,1603.5798,-1679.2388,5.4605,89.8969,0,1); // LSPDHPV4
	PD_SPEED = CreateVehicle(415,1584.3889,-1667.6753,5.6649,269.7265,1,1); // LSPDCheeta
	PD_SPEED2 = CreateVehicle(541,1584.3314,-1671.6809,5.5179,270.4131,1,0); // LSPDBullet
	PD_SPEED3 = CreateVehicle(402,1584.4209,-1675.5552,5.7270,269.3290,1,1); // LSPDBuffalo
	PD_LSPDTOW = CreateVehicle(525,1585.3226,-1680.3849,5.7683,269.2274,0,0); // LSPDTow
	PD_LSPDRancher = CreateVehicle(528,1528.0724,-1688.3204,5.9339,269.3846,1,1); // LSPDBear2
	PD_LSPDRancher2 = CreateVehicle(528,1527.9764,-1683.4500,5.9347,270.5230,1,1); // LSPDBear1
	PD_LSPDRancher3 = CreateVehicle(490,1526.7581,-1644.0273,6.0186,180.0747,0,0); // LSPDRancher1
	PD_LSPDRancher4 = CreateVehicle(490,1530.4824,-1643.9750,6.0183,179.9766,0,0); // LSPDRancher2
	PD_LSPDRancher5 = CreateVehicle(490,1534.6812,-1643.7118,6.0187,180.0512,0,0); // LSPDRancher3
	PD_LSPDSWAT = CreateVehicle(490,1538.8079,-1643.5621,6.0187,179.5128,0,0); // LSPDRancher4
	PD_LSPDSWAT2 = CreateVehicle(490,1545.9469,-1644.5985,6.0179,134.0692,0,0); // LSPDRancher5
	PD_LSPDSWAT3 = CreateVehicle(427,1544.5010,-1650.9823,6.0225,90.1126,0,1); // LSPDEnforcer1
	PD_LSPDUND = CreateVehicle(427,1544.8378,-1654.8641,6.0225,89.0770,0,1); // LSPDEnforcer2
	PD_LSPDUND2 = CreateVehicle(426,1545.8666,-1659.0496,5.6339,89.9158,0,0); // LSPDUnd1
	PD_LSPDUND3 = CreateVehicle(426,1545.2424,-1663.0219,5.6336,88.7208,0,0); // LSPDUnd2
	PD_LSPDUND4 = CreateVehicle(426,1545.8109,-1667.9266,5.6337,89.3767,8,8); // LSPDUnd3
	PD_LSPDUND5 = CreateVehicle(426,1545.4313,-1671.9921,5.6340,89.2795,9,9); // LSPDUnd4
	PD_LSPDTAXI = CreateVehicle(420,1527.9890,-1656.0585,5.6688,269.8552,6,6); // LSPDTaxi
	PD_LSPDUND7 = CreateVehicle(492,1545.7913,-1676.0049,5.6724,89.5243,4,4); // LSPDUnd5
	PD_LSPDUND8 = CreateVehicle(560,1546.3625,-1680.2058,5.5956,89.3625,0,0); // LSPDUnd6
	PD_LSPDUND9 = CreateVehicle(560,1545.2932,-1684.1990,5.5954,89.6851,0,0); // LSPDUnd7
The server starts perfect.

No errors
Reply
#2

Yes;

PHP код:
switch (vehicleid)
{
    case 
PD_LSPDUND4PD_LSPDUND5PD_LSPDUND6PD_LSPDUND7PD_LSPDUND8PD_LSPDUND9PD_LSPDTAXI:
    {
        if(
PInfo[playerid][pCop] <= 7)
        {
            new 
Float:xFloat:yFloat:z;
            
GetPlayerPos(playeridxyz);
            
SetPlayerPos(playeridxyz+1);
            
SendClientMessage(playerid,0xAA3333AA"You are not a Detective I");
        }
    }

However, the way you are creating the vehicles is bad for this condition. You can create a custom function to create a vehicle and inside the function while creating those police vehicles (or whatever they are), you can assign a variable to them. For example; g_PoliceVehicle[vehicleid] = 1;

Then you can simply check if the variable is positive then eject the player without having to detect every created vehicle IDs.
Reply
#3

Quote:
Originally Posted by Sjn
Посмотреть сообщение
Yes;

PHP код:
switch (vehicleid)
{
    case 
PD_LSPDUND4PD_LSPDUND5PD_LSPDUND6PD_LSPDUND7PD_LSPDUND8PD_LSPDUND9PD_LSPDTAXI:
    {
        if(
PInfo[playerid][pCop] <= 7)
        {
            new 
Float:xFloat:yFloat:z;
            
GetPlayerPos(playeridxyz);
            
SetPlayerPos(playeridxyz+1);
            
SendClientMessage(playerid,0xAA3333AA"You are not a Detective I");
        }
    }

However, the way you are creating the vehicles is bad for this condition. You can create a custom function to create a vehicle and inside the function while creating those police vehicles (or whatever they are), you can assign a variable to them. For example; g_PoliceVehicle[vehicleid] = 1;

Then you can simply check if the variable is positive then eject the player without having to detect every created vehicle IDs.
Thanks for the help btw.

Can you show me a example
Reply
#4

When i put
Код:
PD_CAR = CreateVehicle(596,1558.8412,-1711.6847,5.6107,0.2152,0,1); // LSPD1
	PD_CAR2 = CreateVehicle(596,1562.9648,-1711.0802,5.6118,0.0865,0,1); // LSPD2
	PD_CAR3 = CreateVehicle(596,1570.4252,-1711.2849,5.6113,0.1652,0,1); // LSPD3
	PD_CAR4 = CreateVehicle(596,1574.5020,-1711.2111,5.6105,0.7812,0,1); // LSPD4
	PD_CAR5 = CreateVehicle(596,1578.6610,-1711.2418,5.6115,359.9628,0,1); // LSPD5
	PD_CAR6 = CreateVehicle(596,1583.5205,-1711.1624,5.6111,359.9993,0,1); // LSPD6
	PD_CAR7 = CreateVehicle(596,1587.4843,-1710.9558,5.6105,359.5211,0,1); // LSPD7
	PD_CAR8 = CreateVehicle(596,1591.5603,-1710.9192,5.6110,0.3880,0,1); // LSPD8
	PD_CAR9 = CreateVehicle(596,1595.4760,-1711.1044,5.6106,359.1207,0,1); // LSPD9
	PD_CAR10 = CreateVehicle(596,1601.6406,-1704.0292,5.6107,90.6271,0,1); // LSPD10
	PD_CAR11 = CreateVehicle(596,1601.4740,-1700.0243,5.6108,90.7542,0,1); // LSPD11
	PD_CAR12 = CreateVehicle(596,1601.4498,-1696.0110,5.6109,90.4040,0,1); // LSPD12
	PD_CAR13 = CreateVehicle(596,1601.6042,-1692.0181,5.6109,90.1785,0,1); // LSPD13
	PD_CAR14 = CreateVehicle(596,1601.5448,-1687.9376,5.6109,90.5516,0,1); // LSPD14
	PD_CAR15 = CreateVehicle(596,1601.8317,-1683.8500,5.6108,89.6264,0,1); // LSPD15
	PD_NRG = CreateVehicle(521,1599.4846,-1713.0972,5.4622,15.1706,0,1); // LSPDSpeedBike
	PD_HPV = CreateVehicle(523,1604.4741,-1670.3304,5.4618,90.2007,0,1); // LSPDHPV1
	PD_HPV2 = CreateVehicle(523,1604.4326,-1672.7900,5.4645,92.6691,0,1); // LSPDHPV2
	PD_HPV3 = CreateVehicle(523,1603.4644,-1676.4287,5.4600,87.8529,0,1); // LSPDHPV3
	PD_HPV4 = CreateVehicle(523,1603.5798,-1679.2388,5.4605,89.8969,0,1); // LSPDHPV4
	PD_SPEED[0] = CreateVehicle(415,1584.3889,-1667.6753,5.6649,269.7265,1,1); // LSPDCheeta
	PD_SPEED[1] = CreateVehicle(541,1584.3314,-1671.6809,5.5179,270.4131,1,0); // LSPDBullet
	PD_SPEED[2] = CreateVehicle(402,1584.4209,-1675.5552,5.7270,269.3290,1,1); // LSPDBuffalo
	PD_LSPDTOW[0] = CreateVehicle(525,1585.3226,-1680.3849,5.7683,269.2274,0,0); // LSPDTow
	PD_LSPDRancher[0] = CreateVehicle(528,1528.0724,-1688.3204,5.9339,269.3846,1,1); // LSPDBear2
	PD_LSPDRancher[1] = CreateVehicle(528,1527.9764,-1683.4500,5.9347,270.5230,1,1); // LSPDBear1
	PD_LSPDRancher[2] = CreateVehicle(490,1526.7581,-1644.0273,6.0186,180.0747,0,0); // LSPDRancher1
	PD_LSPDRancher[3] = CreateVehicle(490,1530.4824,-1643.9750,6.0183,179.9766,0,0); // LSPDRancher2
	PD_LSPDRancher[4] = CreateVehicle(490,1534.6812,-1643.7118,6.0187,180.0512,0,0); // LSPDRancher3
	PD_LSPDSWAT[0] = CreateVehicle(490,1538.8079,-1643.5621,6.0187,179.5128,0,0); // LSPDRancher4
	PD_LSPDSWAT[1] = CreateVehicle(490,1545.9469,-1644.5985,6.0179,134.0692,0,0); // LSPDRancher5
	PD_LSPDSWAT[2] = CreateVehicle(427,1544.5010,-1650.9823,6.0225,90.1126,0,1); // LSPDEnforcer1
	PD_LSPDUND[0] = CreateVehicle(427,1544.8378,-1654.8641,6.0225,89.0770,0,1); // LSPDEnforcer2
	PD_LSPDUND[1] = CreateVehicle(426,1545.8666,-1659.0496,5.6339,89.9158,0,0); // LSPDUnd1
	PD_LSPDUND[2] = CreateVehicle(426,1545.2424,-1663.0219,5.6336,88.7208,0,0); // LSPDUnd2
	PD_LSPDUND[3] = CreateVehicle(426,1545.8109,-1667.9266,5.6337,89.3767,8,8); // LSPDUnd3
	PD_LSPDUND[4] = CreateVehicle(426,1545.4313,-1671.9921,5.6340,89.2795,9,9); // LSPDUnd4
	PD_LSPDTAXI[0] = CreateVehicle(420,1527.9890,-1656.0585,5.6688,269.8552,6,6,-1); // LSPDTaxi
	PD_LSPDUND[5] = CreateVehicle(492,1545.7913,-1676.0049,5.6724,89.5243,4,4); // LSPDUnd5
	PD_LSPDUND[6] = CreateVehicle(560,1546.3625,-1680.2058,5.5956,89.3625,0,0); // LSPDUnd6
	PD_LSPDUND[7] = CreateVehicle(560,1545.2932,-1684.1990,5.5954,89.6851,0,0); // LSPDUnd7
Into my OnGameModeInit. And then starts the server up. It instant crashes. But when i remove it. The server starts up fine. Sorry for my bad english.... Late night-
Reply
#5

Have you made the new definitions of each variable you're using here?

If you haven't, make something like new LSPDCAR, LSPDCAR1, etc. and then use the defined variables on ongamemodeinit.
Reply
#6

Yeah, i tryed that... If i remove the half of them. The server starts up. But if i add them again... It crashes
Reply
#7

Quote:
Originally Posted by canip
Посмотреть сообщение
Yeah, i tryed that... If i remove the half of them. The server starts up. But if i add them again... It crashes
What if you try to make something like this
Код:
stock LoadVehicles();
{
     // insert the codes from OnGameModeInit here
     return 1;
}
Don't forget the new variables definitions I told you to do.

When you have done that, just add LoadVehicles(); to OnGameModeInit.


Also try to use AddStaticVehicle instead of CreateVehicle. Put this at the top of your script aswell.
Код:
#undef MAX_VEHICLES
#define MAX_VEHICLES 2000
Tell me what happens.
Reply
#8

Alright, this is a very basic example I can provide you right now. I hope you can understand something from this

PHP код:
// Just defining the model to avoid the confusion
#define PoliceLSPD 596
#define PoliceSFPD 597
#define PoliceLVPD 598
// Boolean variable to indicate it's a police vehicle
new boolg_PoliceVehicle[MAX_VEHICLES];
// Custom function to create a vehicle
server_AddStaticVehicle(modelFloat:xFloat:yFloat:zFloat:anglecolor_1color_2delay)
{
    new 
vehicleid AddStaticVehicleEx(modelxyzanglecolor_1color_2delay);
    switch (
model)
    {
        case 
PoliceLSPDPoliceSFPDPoliceLVPD// Police vehicles, you can add more
        
{
            
g_PoliceVehicle[vehicleid] = true;
        }
    }
    return 
vehicleid;
}
// Adding the vehicle
public OnGamemodeInit()
{
    
server_AddStaticVehicle(PoliceLSPD0.00.00.00.0, -1, -1120); // With your coordinates ofc
    
return 1;
}
// Detecting if players are allowed to drive these vehicles
public OnPlayerStateChange(playeridnewstateoldstate)
{
    new 
vehicleid GetPlayerVehicleID(playerid);
    if (
newstate == PLAYER_STATE_DRIVER)
    {
        if (
g_PoliceVehicle[vehicleid] == true)
        {
            
// if (player is not detective)
                    // Eject
        
}
    }
    return 
1;

And, you must set the g_PoliceVehicle[vehicleid]'s value to false whenever you destroy one of the created police vehicle. In the similar way you can check for other vehicles too.

Note that this method is probably not that efficient. But still works pretty good and is easier to use so.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)