#include <a_samp>

#define TEAM_CIVILIAN 1
#define TEAM_MEDIC 2
#define TEAM_COP 3
#define TEAM_DEATHMATCH 4
#define Team__Color 0x98F5FFFF //Bright pastel blue 8EE5EE is darker
#define MEDIC_COLOR 0xFF0000FF //straight red for medics
//6495ED nice blue
//2B2B2B 2b or not 2b
//////////////////////////////////////////
////DracoBlue's wonderful code examiner///
#define dcmd(%1,%2,%3) if ((strcmp(%3, "/%1", true, %2+1) == 0)&&(((%3[%2+1]==0)&&(dcmd_%1(playerid,"")))||((%3[%2+1]==32)&&(dcmd_%1(playerid,%3[%2+2]))))) return 1
//////////////////////////////////////////
//00FFFF is orange
#define ADMIN_COLOR 0x00000000
#define COLOR_EVENT_NOTICE 0xcd3333FF
#define Color_Red 0xFF0000FF
#define COLOR_BLUE 0x0000FFFF
#define COP_COLOR 0x0000FFFF
#define CIVILIAN_COLOR 0xFFA031FF
#define DISTANCE 10
#define COLOR_NOTICE 0xFFAA43FF
#define COLOR_ADMINNOTICE 0x79FF68FF
#define COLOR_DMKILL 0x00FFFFFF
////
//Save stuff
new gMoney[MAX_PLAYERS];
new gXP[MAX_PLAYERS];
new gLevel[MAX_PLAYERS];
new gKills[MAX_PLAYERS];
new gLoggedin[MAX_PLAYERS];
new gAdmin[MAX_PLAYERS];
new gPass[MAX_PLAYERS][256];
new gJailed[MAX_PLAYERS];
new gLastIntNum[MAX_PLAYERS];
new gLastIntName[MAX_PLAYERS][256];
////
new gHour;
new gMinute;
//new gMinute2;
new gAlarm[MAX_PLAYERS];
new gLocked[MAX_VEHICLES];
new gLastVehicle[MAX_PLAYERS];

new gTeam[MAX_PLAYERS];
new gSkin[MAX_PLAYERS];
new gClass[MAX_PLAYERS];
//Deathmatch info
new gDeathmatch[MAX_PLAYERS];
new DMmode;
new gDMStarted;
new gDMKill[MAX_PLAYERS];
//Race information
new gCheckpoint[MAX_PLAYERS];
//Vehicles
new gHydra;
new gRhino;
new gHunter;


main()
{
	print("\n----------------------------------");
	print("  JohnSander's SuperDM  ");
	print("----------------------------------\n");
}
enum VehicleList {
	VehicleArea,
	Vehicle1,
	Vehicle2,
	Vehicle3,
	Vehicle4,
	Vehicle5
}
new gVehicle[][VehicleList] =
{
	{0,604,605,474,572,574}, //Shit cars glanshit, sadlershit, hermes,mower, sweeper
	{1,535,561,409,551,470}, //Expensive slamvan stratum,stretch,merit ,patriot
	{2,541,415,429,494,402}, //race bullet cheetah banshee hotknife buffalo
	{3,536,566,534,419,567}, //lowriders blade tahoma remmington esperanto savana
	{4,522,481,510,521,461}, //bikes NRG, bmx, mountain bike, fcr900, pcj600
	{5,602,558,559,560,562}, //imports alpha uranus jester sultan elegy
	{6,400,471,424,568,556}, //4x4 type LandStalker quadbike bjinjection bandito Monster
	{7,418,459,498,413,440}, //suv/minivan Moonbeam,topfun,boxville,pony,rumpo
	{8,522,522,522,522,522}, //
	{9,597,599,597,599,597} //police SFPD, ranger,
};
enum RandomSpawns {
	Float:SpawnX,
	Float:SpawnY,
	Float:SpawnZ,
	Float:SpawnAngle
}
new Float:gRspawn[][RandomSpawns] =
{
	{-1615.4398, 683.4144, 7.1875, 125.7192}, //At police station
	{-2026.8802, 156.4671, 29.0391, 275.7225} //In front of CJ garage
};
enum PlayerSpawnInfo {
	PlayerSkin,
	Float:PlayerX,
	Float:PlayerY,
	Float:PlayerZ,
	Float:PlayerAngle
}
new Float:gSpawns[][PlayerSpawnInfo] =
{
//-2072.2161,971.3054,62.8575 windy road spawn
	//Taxi spawns 182,206,220,234,261,262
	{182, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{206, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{220, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{234, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{261, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{262, 2025.4651, 1007.8082, 10.8203, 273.1360},
	//Cop Spawns 280-288
	{280, 2293.7468,2450.9131,10.8203,89.4848},
	{281, 2293.7468,2450.9131,10.8203,89.4848},
	{283, 2293.7468,2450.9131,10.8203,89.4848},
	{284, 2293.7468,2450.9131,10.8203,89.4848},
	{285, 2293.7468,2450.9131,10.8203,89.4848},
	{286, 2293.7468,2450.9131,10.8203,89.4848},
	{287, 2293.7468,2450.9131,10.8203,89.4848},
	{288, 2293.7468,2450.9131,10.8203,89.4848},
	{246, 2293.7468,2450.9131,10.8203,89.4848}, // this is the sexyass police bitch
	//Criminal Spawns 21,28,29,30,47,100,143,144,145,146,181,183,184,223,250,254,111,112,113
	{21, 2317.0427,1416.0547,23.6312,140.6091},
	{28, 2317.0427,1416.0547,23.6312,140.6091},
	{29, 2317.0427,1416.0547,23.6312,140.6091},
	{30, 2317.0427,1416.0547,23.6312,140.6091},
	{47, 2317.0427,1416.0547,23.6312,140.6091},
	{100, 2317.0427,1416.0547,23.6312,140.6091},
	{143, 2317.0427,1416.0547,23.6312,140.6091},
	{144, 2317.0427,1416.0547,23.6312,140.6091},
	{145, 2317.0427,1416.0547,23.6312,140.6091},
	{146, 2317.0427,1416.0547,23.6312,140.6091},
	{181, 2317.0427,1416.0547,23.6312,140.6091},
	{183, 2317.0427,1416.0547,23.6312,140.6091},
	{184, 2317.0427,1416.0547,23.6312,140.6091},
	{223, 2317.0427,1416.0547,23.6312,140.6091},
	{250, 2317.0427,1416.0547,23.6312,140.6091},
	{254, 2317.0427,1416.0547,23.6312,140.6091},
	{111, 2317.0427,1416.0547,23.6312,140.6091},
	{112, 2317.0427,1416.0547,23.6312,140.6091},
	{113, 2317.0427,1416.0547,23.6312,140.6091},
//Prostitute spawns.
	{63, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{64, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{75, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{85, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{152, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{207, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{237, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{238, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{243, 2025.4651, 1007.8082, 10.8203, 273.1360},
	{245, 2025.4651, 1007.8082, 10.8203, 273.1360}
};

enum RacePointInfo {
	Float:X,
	Float:Y,
	Float:Z
}
new Float:gRacePoint[][RacePointInfo] =
{
	{-2565.4375,1119.8685,55.0966},   // Race Strip 1
	{-2565.4375,1119.8685,55.0966}, // Race Strip 2
	{-2028.3096,1054.3479,55.0850}, // Race Strip 3
	{-1904.0623,910.8533,34.5307}, // Race Strip 4
	{-1902.0427,724.1657,44.8114}, // Race Strip 5
	{-2022.5460,731.2897,46.8056}, // Race Strip 6
	{-2005.0939,516.4975,34.2374}, // Race Strip 7
	{-2141.7278,507.2324,34.5338}  // Race Strip End
};

public OnGameModeInit()
{
	print("GameModeInit()");
	SetGameModeText("SF:Super DeathMatch");

	//Spawn Loops
	new i, j;
	for (i = 0, j = sizeof(gSpawns); i < j; i++)
	{
	    AddPlayerClass(
    		gSpawns[i][PlayerSkin],
			gSpawns[i][PlayerX],
			gSpawns[i][PlayerY],
			gSpawns[i][PlayerZ],
			gSpawns[i][PlayerAngle],
			0,0,0,0,0,0);
	}
	AddStaticPickup(350,2,1894.4594,976.4333,10.8203);
	AddStaticPickup(356,2,1898.4594,976.4333,10.8203);
	AddStaticPickup(350,2,1898.4594,976.4333,10.8203);
	AddStaticPickup(1240,2,1898.4594,976.4333,10.8203);
	AddStaticPickup(1242,2,1898.4594,976.4333,10.8203);
	AddStaticPickup(2461,2,1902.4561,971.1685,10.8203);
	AddStaticPickup(371,2,-1753.7496,885.7500,295.8750); //Parachute


	gHunter =	AddStaticVehicle(425,1901.6495,1005.8354,9.0127,5.8368,79,-1); // hunter
	gRhino =	AddStaticVehicle(432,1916.4216,1007.6584,10.8127,37.1470,79,-1); // rhino
	gHydra =	AddStaticVehicle(520,1911.0693,982.5377,10.5127,170.3150,79,-1); // hydra


	new shit1=ChooseCar(0);
	new shit2=ChooseCar(0);
	new shit3=ChooseCar(0);
	new shit4=ChooseCar(0);
	new shit5=ChooseCar(0);
	
	new expcar1=ChooseCar(1);
	new expcar2=ChooseCar(1);
	new expcar3=ChooseCar(1);
	new expcar4=ChooseCar(1);
	new expcar5=ChooseCar(1);
	
	new race1=ChooseCar(2);
	new race2=ChooseCar(2);
	new race3=ChooseCar(2);
	new race4=ChooseCar(2);
	new race5=ChooseCar(2);
	
	new lowrider1=ChooseCar(3);
	new lowrider2=ChooseCar(3);
	new lowrider3=ChooseCar(3);
	new lowrider4=ChooseCar(3);
	new lowrider5=ChooseCar(3);
	
	new	bike1=ChooseCar(4);
	new	bike2=ChooseCar(4);
	new	bike3=ChooseCar(4);
	new	bike4=ChooseCar(4);
	new	bike5=ChooseCar(4);
	
	new import1=ChooseCar(5);
	new import2=ChooseCar(5);
	new import3=ChooseCar(5);
	new import4=ChooseCar(5);
	new import5=ChooseCar(5);
	
	new fbf1=ChooseCar(6);
	new fbf2=ChooseCar(6);
	new fbf3=ChooseCar(6);
	new fbf4=ChooseCar(6);
	new fbf5=ChooseCar(6);
	
	new minivan1=ChooseCar(7);
	new minivan2=ChooseCar(7);
	new minivan3=ChooseCar(7);
	new minivan4=ChooseCar(7);
	new minivan5=ChooseCar(7);
	
	new nrg=ChooseCar(8);
	
	new police1=ChooseCar(9);
	new police2=ChooseCar(9);
	new police3=ChooseCar(9);
	new police4=ChooseCar(9);
	new police5=ChooseCar(9);


    AddStaticVehicle(police1,-1629.0022,651.0097,7.1875,359.6445,-1,-1); //cop ranger in SFPD parking lot.
    AddStaticVehicle(lowrider1,-1615.9602,-494.3299,8.0184,144.7776,-1,-1); //voodoo at airport in SF
    AddStaticVehicle(race1,-1615.6405,-505.9040,8.6940,137.5713,-1,-1); //infernus airport vehicle
    AddStaticVehicle(race2,-1356.9530,-488.5559,13.7427,190.0777,-1,-1); //SHAMAL
    AddStaticVehicle(import1,-1452.0516,-534.7979,13.7376,227.9990,-1,-1); //Rustler
	AddStaticVehicle(race3,-1424.0959,-517.4756,13.7493,174.4578,-1,-1); //Dodo
	AddStaticVehicle(minivan1,-1920.6599,280.8154,40.6103,174.6477,-1,-1); //At paynspray for convenience.
	AddStaticVehicle(bike1,-1679.9358,705.8205,30.6016,91.9216,-1,-1); //heli at SFPD
	AddStaticVehicle(bike2,-1579.9543,129.5598,3.5547,133.6622,-1,-1); // carspawn at crane
	AddStaticVehicle(police2,-2058.2830,60.3794,28.1437,266.9240,-1,-1); //Firettruck at SFFD
    AddStaticVehicle(fbf1,-2545.3850,654.2702,27.6506,88.5909,-1,-1); // perfect place for a huntley(sf)
    AddStaticVehicle(lowrider2,-2034.7813,179.1171,28.5649,270.7400,-1,-1); // remington infront of SF garage
	AddStaticVehicle(lowrider3,-2319.0049,-126.0030,35.0375,359.3459,-1,-1); // remington behind burger shot SF
	AddStaticVehicle(expcar1,-2775.0205,-295.6199,6.7636,179.3774,-1,-1); // CHANGE to stafford (uppity club)
	AddStaticVehicle(import2,-2796.0391,-136.6668,6.9114,89.6492,-1,-1); // Put jester here. it would do nicely
	AddStaticVehicle(fbf2,-2686.6116,267.9969,4.0606,164.5553,-1,-1); // Patriot here. Cluckin Bell SF
	AddStaticVehicle(bike3,-2639.0957,201.7009,4.0553,358.8967,-1,-1); // dont know what to put by ammunation SF
	AddStaticVehicle(police3,-2425.8513,518.4341,29.6514,223.6406,-1,-1); // CHANGE FBITruck
	AddStaticVehicle(police4,-2416.6165,528.4776,29.6491,237.9619,-1,-1); //  SFPD car
	AddStaticVehicle(minivan2,-1575.9484,1102.5117,6.9122,359.3457,-1,-1); // CHANGE limo SF
	AddStaticVehicle(fbf3,-1575.2815,1163.2511,6.9117,0.7342,-1,-1); // CHANGE taxi SF
	AddStaticVehicle(expcar2,-2625.1228,1376.0883,6.8479,181.7514,-1,-1); // CHANGE broadway in front of jizzys
	AddStaticVehicle(shit1,-2449.2683,-86.3737,33.6604,356.7954,-1,-1); // car
	AddStaticVehicle(fbf4,-2463.6726,-103.7589,25.5222,184.1406,-1,-1); // car
	AddStaticVehicle(minivan3,-2480.0510,-170.9779,25.2759,93.7903,-1,-1); // cae
	AddStaticVehicle(nrg,-2479.8931,-178.1809,25.2773,85.8213,-1,-1); // car
	AddStaticVehicle(expcar3,-2488.1587,-190.9415,25.2761,265.0513,-1,-1); // car
	AddStaticVehicle(expcar4,-2723.6550,219.0172,4.1527,90.0000,-1,-1); // arch angles
	AddStaticVehicle(import3,-1929.1616,585.0818,34.7883,180.1093,-1,-1); // car
	AddStaticVehicle(fbf5,-2496.3303,153.4076,7.3497,106.1362,-1,-1); // car
	AddStaticVehicle(import4,-2166.9851,304.8333,34.8981,180.4763,-1,-1); //
	AddStaticVehicle(expcar5,-2176.0081,294.5191,34.8973,3.4222,-1,-1); // jester
	AddStaticVehicle(shit2,-2039.1501,136.9674,28.6104,89.7956,-1,-1); // monster
	AddStaticVehicle(minivan4,-2268.3538,73.2327,34.9265,271.0487,-1,-1); // minivan
	AddStaticVehicle(fbf1,-2265.4373,125.0599,34.9336,270.2742,-1,-1); // fbf
	AddStaticVehicle(expcar1,-2413.7627,330.7389,34.7334,324.8912,-1,-1); // expcar
	AddStaticVehicle(race4,-2393.3972,351.1750,34.7338,269.6867,-1,-1); // racecar
	AddStaticVehicle(shit3,-2646.7744,314.3017,4.1432,255.6026,-1,-1); // shitcar
	AddStaticVehicle(fbf2,-2960.2534,460.0230,4.6758,271.0197,-1,-1); // fbf
	AddStaticVehicle(bike4,-2871.8696,719.0272,28.4192,98.4193,-1,-1); // bike?
	AddStaticVehicle(import5,-2484.6965,1132.4869,55.4890,269.8627,-1,-1); // import
	AddStaticVehicle(import1,-2386.7842,1121.0667,55.4925,253.4338,-1,-1); // import
	AddStaticVehicle(police5,-2443.4626,1038.3558,50.1525,94.0717,-1,-1); // police
	AddStaticVehicle(police1,-2778.8057,765.2980,50.8636,271.8076,-1,-1); // police
	AddStaticVehicle(import2,-2729.2546,555.5773,14.3239,269.8671,-1,-1); // import
	AddStaticVehicle(police2,-2544.4355,658.2588,14.2218,90.2940,-1,-1); // police
	AddStaticVehicle(expcar2,-1750.0399,1088.3462,45.2205,268.8066,-1,-1); // expcar
	AddStaticVehicle(import3,-1732.5371,1087.9807,45.2187,268.7562,-1,-1); // import
	AddStaticVehicle(minivan5,-1757.4866,949.1738,24.5137,89.4559,-1,-1); // minivan
	AddStaticVehicle(fbf3,-1919.5386,886.9063,35.1073,84.2060,-1,-1); // fbf
	AddStaticVehicle(import4,-1905.2645,531.3078,34.9443,37.9175,-1,-1); // import
	AddStaticVehicle(shit4,-2121.0403,484.5849,34.9439,214.4292,-1,-1); // shitcar
	AddStaticVehicle(police3,-2117.5710,301.0163,34.6108,190.8382,-1,-1); // police
	AddStaticVehicle(race5,-2087.4028,-311.6066,35.3828,80.7260,-1,-1); // race
	AddStaticVehicle(shit5,-2229.1572,-222.1572,35.2684,12.0557,-1,-1); // shit
	AddStaticVehicle(expcar3,-2246.7688,397.6371,35.0213,19.8203,-1,-1); // expcar
	AddStaticVehicle(import5,-2247.4558,544.6915,34.8912,266.5540,-1,-1); // import
	AddStaticVehicle(bike5,-2214.7639,615.0442,34.9448,181.0111,-1,-1); // bike
	AddStaticVehicle(minivan1,-2245.9033,770.4118,49.2254,0.2457,-1,-1); // minivanw
	AddStaticVehicle(import1,-2244.1587,883.3676,66.4243,358.8293,-1,-1); // import
	AddStaticVehicle(race1,-2276.9971,915.2485,66.4279,6.6171,-1,-1); // race
	AddStaticVehicle(shit1,-2242.0347,1122.3348,72.3795,64.2688,-1,-1); // shit
	AddStaticVehicle(police4,-2324.8135,1378.5822,6.9686,253.6926,-1,-1); // police
	AddStaticVehicle(import2,-2643.2813,1341.4769,6.9369,270.1066,-1,-1); // import
	AddStaticVehicle(race1,-2863.4863,1037.5658,34.8839,182.4886,-1,-1); // racew
	AddStaticVehicle(bike1,-2789.2568,1015.9780,49.9625,279.6655,-1,-1); // bike
	AddStaticVehicle(shit2,-2634.2461,1035.0160,74.3621,282.2274,-1,-1); // shit
	AddStaticVehicle(shit3,-1785.4707,428.4988,16.2188,325.8888,22,1); // shit
	AddStaticVehicle(race2,-1801.1379,-632.2748,17.7572,4.0671,22,1); // race
	AddStaticVehicle(expcar4,-1861.5156,-549.9273,23.2572,207.5111,22,1); // expcar
	AddStaticVehicle(fbf4,-2072.9524,-84.8814,34.7888,358.1904,22,1); // fbf
	AddStaticVehicle(race3,-2089.7712,-85.1954,34.7890,357.1413,22,1); // race
	AddStaticVehicle(lowrider4,-2174.8225,-145.4757,34.8910,178.7408,22,1); // lowrider
	AddStaticVehicle(minivan2,-2402.1421,-43.9242,34.9452,354.4485,22,1); // minivan
	AddStaticVehicle(bike2,-2399.9285,87.5535,34.8972,10.5737,22,1); // bike
	AddStaticVehicle(import3,-2354.4910,343.7368,34.7898,299.4597,22,1); // import
	AddStaticVehicle(minivan2,-2447.3960,740.6454,34.6408,359.7853,2,1); // minivan
	AddStaticVehicle(lowrider5,-2425.3140,741.1752,34.6406,1.8963,2,1); // lowrider
	AddStaticVehicle(shit4,-2508.3188,741.1871,34.6438,1.0756,2,1); // shitcar
	AddStaticVehicle(bike3,-2475.2583,916.6542,62.8995,90.5115,2,1); // bike
	AddStaticVehicle(fbf5,-2573.2620,901.7360,64.6089,74.0400,2,1); // fbf
	AddStaticVehicle(expcar5,-2671.1733,890.1783,79.3285,104.4810,2,1); // expcar
	AddStaticVehicle(import4,-2733.9067,819.2957,52.8358,272.5417,2,1); // import
	AddStaticVehicle(fbf1,-2575.9067,801.2755,49.6066,271.6192,2,1); // fbf
	AddStaticVehicle(import5,-2476.3027,783.3314,34.7967,112.7802,2,1); // import
	AddStaticVehicle(import1,-2090.1567,739.0192,69.1870,268.6805,2,1); // import
	AddStaticVehicle(import2,-1734.4241,1365.3027,6.8120,46.0636,2,1); // import
	AddStaticVehicle(minivan3,-1935.8873,1320.1122,6.8617,119.2830,2,1); // minivan
	AddStaticVehicle(bike4,-2100.5989,925.9483,74.9087,359.0454,2,1); // bike
	AddStaticVehicle(lowrider1,-1884.5239,944.5295,34.7968,9.9466,2,1); // lowrider
	AddStaticVehicle(fbf1,-1775.0811,1205.7698,24.7502,268.1508,2,1); // fbf
	AddStaticVehicle(police5,-1420.1985,457.7434,6.8121,348.3458,2,1); // police
	AddStaticVehicle(police1,-1576.5123,311.4044,6.8125,177.2626,2,1); // police

	SetTimer("Clock",60000,1);
	SetTimer("EventTimer",300000,1);

	SetTimer("SaveTimer",60000,1);
	SetTimer("PositionTimer",1000,1);
	SetTimer("ManHunt",600000,1);
	
	return 1;
}
public ChooseCar(slot){
	new ran0=random(5)+1;
//	printf("%d is the random chosen for %s",ran0,slot);
	new retval;
	if(ran0==1){
		retval=gVehicle[slot][Vehicle1];
	}
	else if(ran0==2){
	    retval=gVehicle[slot][Vehicle2];
	}
	else if(ran0==3){
        retval=gVehicle[slot][Vehicle3];
	}
	else if(ran0==4){
		retval=gVehicle[slot][Vehicle4];
	}
	else if(ran0==5){
		retval=gVehicle[slot][Vehicle5];
	}
	else { print("Big fuckup in vehicle selection."); }
	return retval;
}
public EventTimer(){
	new string[256],eventname[256],i;
	i=random(3);
	if(i==0){
		eventname="Deathmatch";
		DMstarter();
	}
	if(i==1){
	    eventname="Race";
		StartRace();
 	}
 	if(i==2){
 	    eventname="ManHunt";
 	    ManHunt();
	}
	format(string,sizeof(string),"New %s starting.",eventname);
	SendClientMessageToAll(COLOR_EVENT_NOTICE,string);
}

public OnPlayerRequestClass(playerid, classid)
{
//	printf("OnPlayerRequestClass(%d, %d)", playerid, classid);
	SetPlayerInterior(playerid,1);
	SetPlayerPos(playerid,-749.7272,490.6404,1371.7596);
	SetPlayerFacingAngle(playerid,222.7349);
	SetPlayerCameraPos(playerid,-748.3483,489.1574,1371.5956);
	SetPlayerCameraLookAt(playerid,-749.7272,490.6404,1371.7596);

	SetTeam(playerid,classid);
	SetSkin(playerid,gSpawns[classid][PlayerSkin]);
//	SetSpnIfo(playerid,classid);
	return 1;
}
/*public SetSpnIfo(playerid,classid){
	SetSpawnInfo(playerid,gTeam[playerid],gSkin[playerid],gRandSpawn[0][PlayerX],gRandSpawn[0][PlayerY],gRandSpawn[0][PlayerZ],100,0,0,0,0,0,0);
}*/

public OnGameModeExit()
{
	print("GameModeExit()");
	return 1;
}

public OnPlayerConnect(playerid)
{
	printf("OnPlayerConnect(%d)", playerid);
	return 1;
}

public OnPlayerDisconnect(playerid)
{
	printf("OnPlayerDisconnect(%d)", playerid);
	if(gLoggedin[playerid]==1){
		SaveCharInfo(playerid);
	}
	gMoney[playerid]=0;
	gXP[playerid]=0;
	gLevel[playerid]=0;
	gKills[playerid]=0;
	gLoggedin[playerid]=0;
	gAdmin[playerid]=0;
	gJailed[playerid]=0;
	gPass[playerid]="0";
	gLastIntNum[playerid]=0;
	gLastIntName[playerid]="0";
	return 1;
}

//public OnPlayerRequestSpawn(playerid)
public OnPlayerSpawn(playerid)
{
//	printf("OnPlayerSpawn(%d)", playerid);
	SetPlayerInterior(playerid,0);
	new i=random(sizeof(gRspawn));
//	printf("%d was chosen for spawning",i);
/*	new Float:X,Float:Y,Float:Z;
	X=gRandSpawn[i][PlayerX];
	Y=gRandSpawn[i][PlayerY];
	Z=gRandSpawn[i][PlayerZ];*/
	SetPlayerPos(playerid,gRspawn[i][SpawnX],gRspawn[i][SpawnY],gRspawn[i][SpawnZ]);
	SetPlayerFacingAngle(playerid,gRspawn[i][SpawnAngle]);
	
	SetVehicleParamsForPlayer(gHydra,playerid,0,1);
	SetVehicleParamsForPlayer(gRhino,playerid,0,1);
	SetVehicleParamsForPlayer(gHunter,playerid,0,1);
//	SetPlayerPos(playerid,-2342.0408,1384.1245,6.7340);
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
//	if(DMmode==1){
	    if(gDeathmatch[killerid]==1){
			if(killerid == INVALID_PLAYER_ID) {
		        SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
		        gKills[playerid]--;
			}
			else{
			    gDMKill[killerid]++;
			    gDMKill[playerid]--;
			    new string[256],killername[256],playername[256];
			    GetPlayerName(killerid, killername, sizeof(killername));
			    GetPlayerName(playerid, playername, sizeof(playername));
			    format(string,sizeof(string),"%s killed %s",killername,playername);
			    SendClientMessageToAll(COLOR_DMKILL,string);
		    }
		    return 1;
	    }
//	}
	else{
		if(killerid == INVALID_PLAYER_ID) {
	        SendDeathMessage(INVALID_PLAYER_ID,playerid,reason);
	        gKills[playerid]--;
		}
		else{
		    new Float:x,Float:y,Float:z;
		    GetPlayerPos(killerid,x,y,z);
		    if(z>=600){Kick(killerid);SendClientMessageToAll(COLOR_NOTICE,"Player kicked for killing in an interior.");print("A player was kicked for interior killing");}
			gKills[killerid]++; //Increases overall kills for saving purposes
			gKills[playerid]--; //Decreases for the bitch who died
			if(gKills[killerid]==10){gKills[killerid]=0;AddXP(killerid);}
			SendDeathMessage(killerid,playerid,reason);
		}
 	}
	return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
//	printf("OnPlayerEnterVehicle(%d, %d, %d)", playerid, vehicleid, ispassenger);
	if(vehicleid==gHydra || vehicleid==gRhino || vehicleid==gHunter){
		if(!IsPlayerAdmin(playerid)){
			SetVehicleParamsForPlayer(gHydra,playerid,0,1);
			SetVehicleParamsForPlayer(gRhino,playerid,0,1);
			SetVehicleParamsForPlayer(gHunter,playerid,0,1);
			new string[256],fuckedname[256];
			GetPlayerName(playerid,fuckedname,sizeof(fuckedname));
			format(string,sizeof(string),"%s attempted to use admin only vehicles",fuckedname);
			SendClientMessageToAll(COLOR_NOTICE,string);
		}
	}
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
//	printf("OnPlayerExitVehicle(%d, %d)", playerid, vehicleid);
	return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
//	printf("OnPlayerStateChange(%d, %d, %d)", playerid, newstate, oldstate);
	if(newstate==PLAYER_STATE_DRIVER){
		if(gLocked[gLastVehicle[playerid]]){
		    new i=0,j=100;
		    while(i<j){
				SetVehicleParamsForPlayer(gLastVehicle[playerid],i,0,0);
				i++;
			}
	  		gLocked[gLastVehicle[playerid]]=0;
	  		GameTextForPlayer(playerid,"Previous Car Unlocked",3000,3);
		}
	    gLastVehicle[playerid]=GetPlayerVehicleID(playerid);
		new i=0,j=100;
		while(i<j){
		    if(gAlarm[i]==GetPlayerVehicleID(playerid) && i!=playerid){
		    	SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),i,1,0);
		    	new string[256],name[256];
		    	GetPlayerName(playerid,name,sizeof(name));
		    	format(string,sizeof(string),"%s has stolen your car!",name);
		    	GameTextForPlayer(i,string,5000,6);
		    	gLastVehicle[playerid]=GetPlayerVehicleID(playerid);
		    }
			i++;
		}
		if(gAlarm[playerid]==GetPlayerVehicleID(playerid)){
			SetVehicleParamsForPlayer(GetPlayerVehicleID(playerid),playerid,0,0);
   			GameTextForPlayer(i,"Alarm disengaged",5000,6);
		}
	}
	return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
	if(strcmp(cmdtext,"/dmstart",true)==0){
		if(DMmode==0){
			DMstarter();
		}
		else{SendClientMessage(playerid,0xac0affff,"DM mode is already started");}
		return 1;
	}
	if(strcmp(cmdtext,"/jdm",true)==0){
	    JoinDM(playerid);
	    return 1;
	}
	if(strcmp(cmdtext, "/time", true) == 0) {
		SayTime(playerid);
		return 1;
	}
	if(strcmp(cmdtext,"/race",true)==0){
		StartRace();
 		return 1;
	}
	if(strcmp(cmdtext,"/toadmin",true)==0){\
		if(IsPlayerAdmin(playerid)){
		    SetPlayerPos(playerid,1898.4594,976.4333,10.8203);
			return 1;
		}
	}
	if(strcmp(cmdtext,"/alock",true)==0){
		if(IsPlayerAdmin(playerid)){
			SetVehicleParamsForPlayer(gHydra,playerid,0,0);
			SetVehicleParamsForPlayer(gRhino,playerid,0,0);
			SetVehicleParamsForPlayer(gHunter,playerid,0,0);
		    return 1;
		}
	}
	if(strcmp(cmdtext,"/find",true)==0){
	    findpersonincar(gHydra,playerid);
	    print("/find works");
		return 1;
	}
	if(strcmp(cmdtext,"/to",true,3)==0){
	    if(cmdtext[3]==' '){
	        ReadWarps(playerid,cmdtext[4]);
	        //SendClientMessage(playerid,0xFFFF0000,"u got to readval");
	    }
	    else{//SendClientMessage(playerid,0xFFFF0000,"SYNTAX: /tele [name]");}
	        ListWarps(playerid);
	    }
	    return 1;
	}
	if(strcmp(cmdtext,"/enter",true)==0){
		new Float:x,Float:y,Float:z;
		GetPlayerPos(playerid,x,y,z);
			if(x<=-2765 && x>=-2769 && y>=786 && y<=790){ReadWarps(playerid,"indonut");gLastIntNum[playerid]=0;gLastIntName[playerid]="Tuff Nutt";} //Tuff Nutt-2767.3667,  788.6859,  52.7813 is location
			else if(x<=-2095 && x>=-2099 && y>=671 && y<=675){ReadWarps(playerid,"svsfbg");gLastIntNum[playerid]=1;gLastIntName[playerid]="Hill House";} //House on hill of chinatown -2097.8601,  673.8524,  58.4893
			else if(x<=-2032 && x>=-2036 && y>=901 && y<=905){ReadWarps(playerid,"sfhsb3");gLastIntNum[playerid]=2;gLastIntName[playerid]="Winding Road";}//House on winding road -2034.4194,903.4708,50.5367
			else if(x<=-2350 && x>=-2354 && y>=1224 && y<=1228){ReadWarps(playerid,"svlabig");gLastIntNum[playerid]=3;gLastIntName[playerid]="Close To Jizzy";}//House close to jizzys? -2352.3113,1226.5773,33.0940
			else if(x<=-2030 && x>=-2034 && y>=159 && y<=163){ReadWarps(playerid,"cjgarage");gLastIntNum[playerid]=4;gLastIntName[playerid]="CJ Garage";}//CJs garage in san fierro -2032.3160,161.5269,29.0461
			else{SendClientMessage(playerid,0xFFFFFFFF,"You are not at a house.");}
	    return 1;
	}
	if(strcmp(cmdtext,"/exit",true,5)==0){
	    if(gLastIntNum[playerid]==0){SetPlayerPos(playerid,-2767.3667, 788.6859,  52.7813);SetPlayerInterior(playerid,0);}
	    else if(gLastIntNum[playerid]==1){SetPlayerPos(playerid,-2097.8601,  673.8524,  58.4893);SetPlayerInterior(playerid,0);}
	    else if(gLastIntNum[playerid]==2){SetPlayerPos(playerid,-2034.4194,903.4708,50.5367);SetPlayerInterior(playerid,0);}
	    else if(gLastIntNum[playerid]==3){SetPlayerPos(playerid,-2352.3113,1226.5773,33.0940);SetPlayerInterior(playerid,0);}
	    else if(gLastIntNum[playerid]==4){SetPlayerPos(playerid,-2032.3160,161.5269,29.0461);SetPlayerInterior(playerid,0);}
		return 1;
	}
	if(strcmp(cmdtext,"/level",true)==0){
		new string[256];
		format(string,sizeof(string),"Kills: %d XP: %d Level: %d",gKills[playerid],gXP[playerid],gLevel[playerid]);
		SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
		return 1;
	}
	if(strcmp(cmdtext,"/admins",true)==0){
	    new i=0,j=100,playername[256],string[256];
	    SendClientMessage(playerid,COLOR_ADMINNOTICE,"Admins online:");
		while(i<j){
		    if(gAdmin[i]>=1){
		    	GetPlayerName(i,playername,sizeof(playername));
		    	format(string,sizeof(string),"** %s Level: %d",playername,gAdmin[i]);
		    	SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
		    }
		    i++;
		}
		return 1;
	}
	if(strcmp(cmdtext,"/alarm",true)==0){
	    if(IsPlayerInAnyVehicle(playerid) && GetPlayerState(playerid)== PLAYER_STATE_DRIVER){
			//new vid;
	    	gAlarm[playerid]=GetPlayerVehicleID(playerid);
	    	GameTextForPlayer(playerid,"Alarm Set",5000,6);
	    	//SetAlarm(playerid,vid);
	    }
		return 1;
	}
	if(strcmp(cmdtext,"/lock",true)==0){
	    new i=0,j=100;
	    if(gLocked[gLastVehicle[playerid]]){
	    	while(i<j){
		  		SetVehicleParamsForPlayer(gLastVehicle[playerid],i,0,0);
		  		gLocked[gLastVehicle[playerid]]=0;
		  		GameTextForPlayer(playerid,"Car Unlocked",5000,3);
		  	//	printf("%d car unlocked",gLastVehicle[playerid]);
		  		i++;
	  	  	}
	    }
	    else{
		    while(i<j){
		  		SetVehicleParamsForPlayer(gLastVehicle[playerid],i,0,1);
		  		gLocked[gLastVehicle[playerid]]=1;
		  		GameTextForPlayer(playerid,"Car Locked",5000,3);
		  	//	printf("%d car locked",gLastVehicle[playerid]);
		  		i++;
	  	  	}
  	  	}
	    return 1;
	}
	dcmd(register,8,cmdtext);
	dcmd(login,5,cmdtext);
	//dcmd(akill,5,cmdtext);
	if(gAdmin[playerid]>=1){
	    dcmd(goto,4,cmdtext);
	    dcmd(gethere,7,cmdtext);
	    dcmd(btalk,5,cmdtext);
	    dcmd(freeze,6,cmdtext);
	    dcmd(thaw,4,cmdtext);
	    dcmd(jail,4,cmdtext);
	    if(gAdmin[playerid]>=10){
		    dcmd(alvl,4,cmdtext);
		}
	}
	dcmd(towcar,6,cmdtext);
	dcmd(gun,3,cmdtext);
	return 0;
}
dcmd_register(const playerid,const params[]){
	if(params[0]){
		new index=0;
		new password[256],passhandler[256],string[256];
		passhandler=admin_strtok(params,index);
		format(string,sizeof(string),"Password is: %s",passhandler);
		SendClientMessage(playerid,0xffffffff,string);
		password=encrypt(passhandler);
		NewCharacter(playerid,password);
		return 1;
	}
	else{SendClientMessage(playerid,COLOR_ADMINNOTICE,"Syntax: /register [password]");}
	return 1;
}
dcmd_login(const playerid,const params[]){
	if(params[0]){
		if(gLoggedin[playerid]==0){
			new index=0;
			new password[256],passhandler[256];
			passhandler=strchk(params,index);
			password=encrypt(passhandler);
			LoginCharacter(playerid,password);
			return 1;
		}
		else{
			SendClientMessage(playerid,0xFFCC42FF,"You are already logged in.");
		    return 1;
		}
	}
	else{SendClientMessage(playerid,COLOR_ADMINNOTICE,"Syntax: /login [password]");}
	return 1;
}
/*dcmd_akill(const playerid,const params[]){
	gKills[playerid]++;
	return 1;
}*/
dcmd_goto(const playerid,const params[]){
	if(params[0]){
		if(IsPlayerConnected(strval(params))){
	        new Float:x,Float:y,Float:z;
	        GetPlayerPos(strval(params),x,y,z);
	        teleport(playerid,x,y,z);
	   }
  	}
	return 1;
}
dcmd_gethere(const playerid,const params[]){
	if(params[0]){
		if(IsPlayerConnected(strval(params))){
	        new Float:x,Float:y,Float:z;
	        GetPlayerPos(playerid,x,y,z);
	        teleport(strval(params),x,y,z);
		}
	}
	return 1;
}
dcmd_towcar(const playerid,const params[]){
	SetVehicleToRespawn(strval(params));
	SendClientMessage(playerid,0xCC33A1FF,"Car towed to original position");
	return 1;
}
dcmd_btalk(const playerid,const params[]){
	if(params[0]){
		new index=0,time[256],type[256],words[256];
		time = strchk(params,index);
		type = strchk(params,index);
		words = strchk(params,index);
		if(time && type && words){
			GameTextForAll(words,strval(time)*1000,strval(type));
			SendClientMessage(playerid,COLOR_ADMINNOTICE,"You have spoken");
		}
	}
	return 1;
}
dcmd_gun(const playerid,const params[]){
	if(params[0]){
		if (strcmp(params,"mp5",true)==0){
			GivePlayerWeapon(playerid,29,5000);
		}
		if (strcmp(params,"minigun",true)==0 && gAdmin[playerid]>=6){
			GivePlayerWeapon(playerid,38,5000);
		}
		if (strcmp(params,"spaz",true)==0){
			GivePlayerWeapon(playerid,27,5000);
		}
		if (strcmp(params,"tec9",true)==0){
			GivePlayerWeapon(playerid,32,5000);
		}
		if (strcmp(params,"sawnoff",true)==0){
		    GivePlayerWeapon(playerid,26,5000);
		}
	}
	return 1;
}
dcmd_freeze(const playerid,const params[]){
	if(params[0]){
		if(IsPlayerConnected(strval(params))){
			new string[256],playername[256];
			TogglePlayerControllable(strval(params),0);
		 	GetPlayerName(strval(params),playername,sizeof(playername));
			format(string,sizeof(string),"You have frozen %s",playername);
			SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
			GetPlayerName(playerid,playername,sizeof(playername));
			format(string,sizeof(string),"%s has frozen you.",playername);
			SendClientMessage(strval(params),COLOR_ADMINNOTICE,string);
		}
		else{SendClientMessage(playerid,COLOR_ADMINNOTICE,"INVALID PLAYER ID");}
	}
	return 1;
}
dcmd_thaw(const playerid,const params[]){
	if(params[0]){
		if(IsPlayerConnected(strval(params))){
			new string[256],playername[256];
		    TogglePlayerControllable(strval(params),1);
		    GetPlayerName(strval(params),playername,sizeof(playername));
		    format(string,sizeof(string),"You have thawed %s",playername);
			SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
		 	GetPlayerName(playerid,playername,sizeof(playername));
			format(string,sizeof(string),"%s has thawed you.",playername);
			SendClientMessage(strval(params),COLOR_ADMINNOTICE,string);
		}
		else{SendClientMessage(playerid,COLOR_ADMINNOTICE,"INVALID PLAYER ID");}
	}
	return 1;
}
dcmd_alvl(const playerid,const params[]){
//	if(params[0]){
        new index=0,person,level,personname[256];
        person=strval(strchk(params,index));
        level=strval(strchk(params,index));
		if(IsPlayerConnected(person)){
		    if(gLoggedin[strval(params)]){
				gAdmin[person]=level;
				new string[256];
				GetPlayerName(person,personname,sizeof(personname));
				format(string,sizeof(string),"%s is now admin level %d",personname,level);
                SendClientMessage(playerid,COLOR_ADMINNOTICE,"Player is not logged in.");
		    }
		    else{SendClientMessage(playerid,COLOR_ADMINNOTICE,"Player is not logged in.");}
		}
//	}
	return 1;
}
dcmd_jail(const playerid,const params[]){
	if(params[0]){
		new string[256],playername[256];
		if(IsPlayerConnected(strval(params))){
			SetPlayerPos(strval(params),0,0,10000);
			TogglePlayerControllable(strval(params),0);
			GetPlayerName(strval(params),playername,sizeof(playername));
			format(string,sizeof(string),"%s has been jailed.",playername);
			SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
		}
	}
	return 1;
}
public encrypt(string[]) /////THX Y_LESS FOR THIS ENCRYPTION
{
	static key[] = "IasSumEthatYoucouldPlaceWhaTeVeryOUwishSofoxaflyingxylophoneWithCoLoRs1230456789.";
//	static key[] = "aa";
	// The more different characters there are in here, the better the code
	static size = sizeof(key) - 1;
	// Theres a slight bug, you don't want to count the end \0
	new retval[64];
	// Passwords limited to 48 chars (64 - 16 for rounding)
	new j, k, sum, tmp[] = {0, 0};
	// Initialise the variables
	j = strlen(string);
	sum = j;
	// Get the length of the source string
	k = ((j >> 4) + 1) << 4;
	// Round up to the nearest 16 (trust me, it does)
	for (new i = 0; i < k; i++)
	{
		if (i < j)
		{
			tmp[0] = string[i];
			// Get the next character
		}
		else
		{
			tmp[0] = ' ';
			// Add the padding
		}
		sum = ((sum + strfind(key, tmp) + 1) % size);
		// Add the new position to the running total and limit
		// it to the size of the array (thus carrying character
		// data over to the next)
		retval[i] = key[sum];
		// Add the new character to the running array.
	}
	return retval;
}
public SayTime(playerid){
	new string[256];
	if(gMinute < 10) {
		format(string,sizeof(string),"~w~Time~r~: ~b~%d:0%d",gHour,gMinute);
	}
	else if(gMinute >=10) {
		format(string,sizeof(string),"~w~Time~r~: ~b~%d:%d",gHour,gMinute);
	}
	GameTextForPlayer(playerid, string, 2000,1);
}

/*public SetAlarm(playerid,vid){
	gAlarm[playerid]=vid;
}*/

public OnPlayerEnterCheckpoint(playerid)
{
	//printf("OnPlayerEnterCheckpoint(%d)", playerid);
	ChangeRacePoint(playerid);
	return 1;
}



public OnPlayerInfoChange(playerid)
{
	printf("OnPlayerInfoChange(%d)");
	return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
	printf("OnPlayerLeaveCheckpoint(%d)", playerid);
	return 1;
}
public OnVehicleSpawn(vehicleid)
{
	printf("OnVehicleSpawn(%d)", vehicleid);
	return 1;
}
/////// Deathmatch stuff////////
public SendToDM(playerid){
	TogglePlayerControllable(playerid,0);
	ResetPlayerWeapons(playerid);
	SetPlayerInterior(playerid,0); //JUST IN CASE they are in an interior
	SetPlayerPos(playerid,243.1350,1822.2220,4.7109);
	GivePlayerWeapon(playerid,28,5000);
	SetPlayerColor(playerid,0x4444AAFF);
	GameTextForPlayer(playerid,"Wait for other players",5000,4);
	SetSpawnInfo(playerid,TEAM_DEATHMATCH,gSkin[playerid],243.1350,1822.2220,4.7109,0,28,5000,0,0,0,0);
}
public DMtimer(){
	//if(DMmode==0){
		StartDM();
	//}
}
public StartDM(){
	new i,j;
	i=0;
	j=100;
	while(i<j){
		if(gDeathmatch[i]==1){
			TogglePlayerControllable(i,1);
			GameTextForPlayer(i,"Good Luck",3000,4);
		}
		i++;
	}
	SendClientMessageToAll(0x4a4f00FF,"Deathmatch Started now");
	gDMStarted=1;
}
public DMstarter(){
//  SetTimer("DMtimer",60000,0);
//	SetTimer("EndDMtimer",120000,0);
    SetTimer("DMtimer",30000,0);
	SetTimer("EndDMtimer",300000,0);
	DMmode=1;
	GameTextForAll("Deathmatch starting in 30 seconds. Type /jdm to join deathmatch",5000,4);
}
public EndDMtimer(){
	new i,j;
	i=0;
	j=100;
	while(i<j){
	    if(gDeathmatch[i]==1){
			RemoveFromDM(i);
		    gDeathmatch[i]=0;
     	}
     	i++;
	}
//	SendClientMessageToAll(0x4a4f00FF,"Deathmatch Ended");
	DMmode=0;
	gDMStarted=0;
}
public JoinDM(playerid){
	if(DMmode==1 && gDMStarted==0 && gDeathmatch[playerid]==0){
	    gDeathmatch[playerid]=1;
	    SendToDM(playerid);
	}
	else{SendClientMessage(playerid,0xFa4f0FFF,"You cannot join the deathmatch at this time.");}
}
public RemoveFromDM(playerid){
	SetColor(playerid,gTeam[playerid]);
	new cid;
	cid=gClass[playerid];
	SetSpawnInfo(playerid,gTeam[playerid],gSkin[playerid],gSpawns[cid][PlayerX],gSpawns[cid][PlayerY],gSpawns[cid][PlayerZ],gSpawns[cid][PlayerAngle],0,0,0,0,0,0);
	SpawnPlayer(playerid);
	new i,j;
	i=0;
	j=100;
	while(i<j){
		if(gDMKill[playerid]>=1){
		    new string[256],playername[256];
		    GetPlayerName(playerid, playername, sizeof(playername));
		    format(string,sizeof(string),"%s ended with %d kills.",playername,gDMKill[playerid]);
			SendClientMessageToAll(COLOR_DMKILL,string);
		}
		gDMKill[playerid]=0;
		i++;
	}
	GameTextForPlayer(playerid,"Deathmatch is now over.",5000,4);
}
public SetTeam(playerid,classid)
{
	if(classid < 6){
		//SetPlayerTeam(playerid,TEAM_TAXI);
//		gTeam[playerid] = TEAM_TAXI;
//		SetPlayerColor(playerid,TAXI_COLOR);
		GameTextForPlayer(playerid,"Taxi Driver",5000,4);
	}
	if(classid < 14 && classid > 5){

//	    gTeam[playerid] = TEAM_COP;
//	    SetPlayerColor(playerid,COPS_COLOR);
		GameTextForPlayer(playerid,"Cop",5000,4);
	}
	if(classid>13 && classid<35){
//	    gTeam[playerid]=TEAM_ROBBERS;
//	    SetPlayerColor(playerid,ROBBER_COLOR);
		GameTextForPlayer(playerid,"Criminal",5000,4);
	}
	if(classid>34 && classid<100){
		GameTextForPlayer(playerid,"Prostitute",5000,4);
	}
	SetColor(playerid,gTeam[playerid]);
//	gPID[playerid] = playerid;
	gClass[playerid]=classid;
	return 1;
}
public SetColor(playerid,team){
	if(team==TEAM_CIVILIAN){SetPlayerColor(playerid,CIVILIAN_COLOR);}
	if(team==TEAM_COP){SetPlayerColor(playerid,COP_COLOR);}
	if(team==TEAM_MEDIC){SetPlayerColor(playerid,MEDIC_COLOR);}
}
public SetSkin(playerid,skin){
	gSkin[playerid]=skin;
}
/////////////////////////////////////////
///////// Race Mode Information /////////
/////////////////////////////////////////
public StartRace(){
	new i,j;
	i=0;
	j=100;
	while(i<j){
		SetPlayerCheckpoint(i,gRacePoint[0][X],gRacePoint[0][Y],gRacePoint[0][Z],10);
	/*	new string[256];
		format(string,sizeof(string),"gSpawns: %d",sizeof(gRacePoint[][RacePointInfo]));
		SendClientMessage(i,0xFFFFFFFF,string);*/
		ResetPlayerWeapons(i);
		i++;
	}
}
public ChangeRacePoint(playerid){
	if(gCheckpoint[playerid]==7){
	    //PlayerPlaySound(playerid,34602);
	    new string[256];
	    format(string,sizeof(string),"~w~Winner ~r~%s ~w~awarded ~b~$500,000",PlayerName(playerid));
	    GameTextForAll(string,6000,4);
	    GivePlayerMoney(playerid,500000);
	    AddXP(playerid);
	    EndRace();
		return 1;
	}
	gCheckpoint[playerid]++;
/*	new string[256];
	format(string,sizeof(string),"You are gCheckpoint: %d",gCheckpoint[playerid]);
	SendClientMessage(playerid,0xFFFFFFFF,string);*/
	new chp=gCheckpoint[playerid];
	SetPlayerCheckpoint(playerid,gRacePoint[chp][X],gRacePoint[chp][Y],gRacePoint[chp][Z],10);
	return 1;
}
public PlayerName(id){
new string[256];
GetPlayerName(id,string,sizeof(string));
return string;
}
public EndRace(){
	new i,j;
	i=0,j=100;
	while(i<j){
		DisablePlayerCheckpoint(i);
		gCheckpoint[i]=-1;
		i++;
	}
}
public Race(){
}
/////////////////////////////////////////
////////////Time/////////////////////////
/////////////////////////////////////////
public Clock(){
	if(gMinute==59){
		if(gHour<24){
			gHour++;
		}
		else{gHour=0;}
		gMinute=0;
		SetWorldTime(gHour);
	}
	gMinute++;
}


///////////////////////////////////////
//////////////Save Stuff///////////////
///////////////////////////////////////
public ReadWarps(playerid,place[]){
	new File:fhandle,index2,optionname[256],temp[256],value[256],value2[256],value3[256],value4[256];
	if(!fexist("mine.txt")){print("File doesn't exist");return 1;}
	fhandle = fopen("mine.txt",io_read);
			while(fread(fhandle,temp,sizeof(temp),false)) {
			    index2 = 0;
				optionname = strchk(temp,index2);
				if(strcmp(optionname,place,true)==0){
					value = strchk(temp,index2);
					value2 = strchk(temp,index2);
					value3 = strchk(temp,index2);
					SetPlayerPos(playerid,strval(value),strval(value2),strval(value3));
					value4 = strchk(temp,index2);
					SetPlayerInterior(playerid,strval(value4));
				}
			}
	fclose(fhandle);
	return 0;
}
public ListWarps(playerid){
	new File:fhandle,index2,optionname[256],temp[256],string[256];
	if(!fexist("mine.txt")){print("File doesn't exist");return 1;}
	fhandle = fopen("mine.txt",io_read);
			while(fread(fhandle,temp,sizeof(temp),false)) {
			    index2 = 0;
				optionname = admin_strtok(temp,index2);
				format(string,sizeof(string),"%s",optionname);
				SendClientMessage(playerid,0xFFFFFFFF,string);
			}
	fclose(fhandle);
	return 0;
}
///////////////////////////////////////
//////////////House Info///////////////
///////////////////////////////////////
public ReadHouse(playerid,place[]){
	new File:fhandle,index2,housename[256],temp[256],owner[256],price[256],level[256],interior[256],housenumber[256];
	if(!fexist("house.txt")){print("File doesn't exist");return 1;}
	fhandle = fopen("house.txt",io_read);
			while(fread(fhandle,temp,sizeof(temp),false)) {
			    index2 = 0;
				housename = strchk(temp,index2);
				if(strcmp(housename,place,true)==0){
					owner = strchk(temp,index2);
					price = strchk(temp,index2);
					level = strchk(temp,index2);
//					SetPlayerPos(playerid,strval(value),strval(value2),strval(value3));
					interior = strchk(temp,index2);
					housenumber = strchk(temp,index2);
//					SetPlayerInterior(playerid,strval(value4));
				}
				//printf("Opt: %s value: %s value2: %s value3: %s",optionname,value,value2,value3);
			//	if(strcmp(optionname,"servername",true) == 0) servername = value;
			//	else if(strcmp(optionname,"onspawn-action",true) == 0) onspawnaction = value;
			//	else printf("  |--WARNING: Unknown option %s",optionname);
			}
	fclose(fhandle);
	return 0;
}
public ListHouse(playerid){
	new File:fhandle,index2,optionname[256],temp[256],string[256];
	if(!fexist("mine.txt")){print("File doesn't exist");return 1;}
	fhandle = fopen("mine.txt",io_read);
			while(fread(fhandle,temp,sizeof(temp),false)) {
			    index2 = 0;
				optionname = admin_strtok(temp,index2);
				format(string,sizeof(string),"%s",optionname);
				SendClientMessage(playerid,0xFFFFFFFF,string);
			}
	fclose(fhandle);
	return 0;
}

/////////////////////////////////////
//Saved character information////////
/////////////////////////////////////
public AddXP(playerid){
	gXP[playerid]++;
	SendClientMessage(playerid,COLOR_ADMINNOTICE,"You have gained one eXperience Point");
	if(gXP[playerid]==10){
	    gLevel[playerid]++;
	    SendClientMessage(playerid,COLOR_ADMINNOTICE,"You have gained a level");
	}
}
public NewCharacter(playerid,password[256]){
	new File:fhandle,playername[256],fname[256];
	GetPlayerName(playerid,playername,sizeof(playername));
	format(fname,sizeof(fname),"%s.txt",playername);
	if(!fexist(fname)){ //Make the file if it doesnt exist for that character
		print("File doesn't exist");
		MakeFile(fname,playerid);
//		return 1;
	}
	else{SendClientMessage(playerid,0xFFAACC00,"Already registered"); return 1;}
	fhandle = fopen(fname,io_write);
 	new string[256];
    format(string,sizeof(string),"%s,%s,%d,%d,%d,%d,%d",playername,password,gMoney[playerid],gXP[playerid],gLevel[playerid],gKills[playerid],gAdmin[playerid]);
    SendClientMessage(playerid,0x00000000,string);
	fwrite(fhandle,string);
	fclose(fhandle);
	SendClientMessage(playerid,0xffaacc00,"You are now registered, remember your password.");
	gLoggedin[playerid]=1;
	gPass[playerid]=password;
	return 1;
}

public LoginCharacter(playerid,password[]){
	new File:fhandle,index2,playername[256],temp[256],fname[256],money[256],level[256],xp[256],pass[256],kills[256],admin[256];
	GetPlayerName(playerid,playername,sizeof(playername));
	format(fname,sizeof(fname),"%s.txt",playername);
	if(!fexist(fname)){
		SendClientMessage(playerid,0xFF1133FF,"You are not registered. Type /register [password]");
		return 1;
	}
	fhandle=fopen(fname,io_read);
//	while(fread(fhandle,temp,sizeof(temp),false)){
	fread(fhandle,temp,sizeof(temp),false);
	    index2=0;
	    playername= strchk(temp,index2);
	    pass = strchk(temp,index2);
   		money = strchk(temp,index2);
		xp = strchk(temp,index2);
		level = strchk(temp,index2);//GetPlayerHealth()
		kills = strchk(temp,index2);
		admin = strchk(temp,index2);
//	}
	fclose(fhandle);
	if(strcmp(password,pass,true)==0){
		SendClientMessage(playerid,0xFFCC44FF,"You are now logged in.");
//		ReadCharInfo(playerid);
		gLoggedin[playerid]=1;
		gPass[playerid]=pass;
		gMoney[playerid]=strval(money);
		gLevel[playerid]=strval(level);
		gXP[playerid]=strval(xp);
		gKills[playerid]=strval(kills);
		gAdmin[playerid]=strval(admin);
		ResetPlayerMoney(playerid);
		GivePlayerMoney(playerid,gMoney[playerid]);
		return 1;
	}
	else{SendClientMessage(playerid,0xFFCC44FF,"Incorrect Password");}
	return 1;
}
public SaveCharInfo(playerid){
	new File:fhandle,playername[256],fname[256];
	GetPlayerName(playerid,playername,sizeof(playername));
	format(fname,sizeof(fname),"%s.txt",playername);
	fremove(fname);
	fhandle = fopen(fname,io_write);
    new string[256];
    format(string,sizeof(string),"%s,%s,%d,%d,%d,%d,%d",playername,gPass[playerid],gMoney[playerid],gXP[playerid],gLevel[playerid],gKills[playerid],gAdmin[playerid]);
//    SendClientMessage(playerid,COLOR_ADMINNOTICE,string);
	fwrite(fhandle,string);
	fclose(fhandle);
	return 1;
}
public MakeFile(fname[],pid){
	new string[256],playername[256],File:fhandle;
	GetPlayerName(pid,playername,sizeof(playername));
	fhandle=fopen(fname,io_write);
	format(string,sizeof(string),"%s,%d,%d,%d,%d,%d,%d",playername,0,0,0,0,0,0);
	fwrite(fhandle,string);
	fclose(fhandle);
	return 1;
}
public SaveTimer(){
	new i=0,j=100;
	while(i<j){
	    if(IsPlayerConnected(i)==1){
			gMoney[i]=GetPlayerMoney(i);
			if(gLoggedin[i]==1){SaveCharInfo(i);}
		}
		i++;
	}
}
////////////////////////////////////////////
//////End of Save functions/////////////////
////////////////////////////////////////////
public PositionTimer(){
	new i,j,Float:x,Float:y,Float:z;
	for(i=0,j=100;i<j;i++){
	    if(IsPlayerConnected(i)==1){
			GetPlayerPos(i,x,y,z);
			if(x<=-2765 && x>=-2769 && y>=786 && y<=790){GameTextForPlayer(i,"Tuff Nutt Type /enter to enter",2000,4);} //Tuff Nutt-2767.3667,  788.6859,  52.7813 is location
			else if(x<=-2095 && x>=-2099 && y>=671 && y<=675){GameTextForPlayer(i,"Chinatown house Type /enter to enter",2000,4);} //House on hill of chinatown -2097.8601,  673.8524,  58.4893
			else if(x<=-2032 && x>=-2036 && y>=901 && y<=905){GameTextForPlayer(i,"Winding road House Type /enter to enter",2000,4);}//House on winding road -2034.4194,903.4708,50.5367
			else if(x<=-2350 && x>=-2354 && y>=1224 && y<=1228){GameTextForPlayer(i,"Close to jizzy? Type /enter to enter",2000,4);}//House close to jizzys? -2352.3113,1226.5773,33.0940
			else if(x<=-2030 && x>=-2034 && y>=159 && y<=163){GameTextForPlayer(i,"CJs Garage Type /enter to enter",2000,4);}//CJs garage in san fierro -2032.3160,161.5269,29.0461
			else{}
		}
	}
	return 0;
}

admin_strtok(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ' ') && (string[index] > '\r'))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
strchk(const string[], &index)
{
	new length = strlen(string);
	while ((index < length) && (string[index] <= ',') && (string[index] > '\r'))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ',') && ((index - offset) < (sizeof(result) - 1)) && (string[index] > '\r'))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
findpersonincar(vhid,rid){
	new i,j=100,culname[256],string[256],anyone;
	while(i<j){
	    if(IsPlayerConnected(i)){
			if(IsPlayerInVehicle(i,vhid)){
			    anyone=1;
			    GetPlayerName(i,culname,sizeof(culname));
				format(string,sizeof(string),"%s is in your vehicle",culname);
				SendClientMessage(rid,0xFFFFFFFF,string);
			}
		}
		i++;
	}
	if(anyone==0){
		SendClientMessage(rid,0xFFFFFFFF,"Noone is in your vehicle");
	}
}
//On start of server, you can save the ID of the vehicle to a TXT file (dynamic change)... format = NAME ID (read as name space eye dee)
public VehicleStuff(){
//	new File:vehicles;

}
public teleport(playerid,Float:x,Float:y,Float:z){
	if (IsPlayerInAnyVehicle(playerid)){
		new vehicleid;
		vehicleid=GetPlayerVehicleID(playerid);
		SetVehiclePos(vehicleid,x,y,z);
	}
	else{
		SetPlayerPos(playerid,x,y,z);
	}
	return 1;
}
public ManHunt(){
	new i=0,j=100;
	while(i<j){
		new player=random(MAX_PLAYERS);
		if(IsPlayerConnected(player)){
			SetPlayerColor(player,0xffffffff);
			GameTextForAll("Kill the white guy!!",5000,4);
			i=1000;
		}
		i++;
		//else{ManHunt();}
	}
}
