Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define col_red 0xFF0000FF
- #define PRESSED(%0) (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
- //simplify OnPlayerKeyStateChange
- #define CarAmount 6 //NUMBER OF VEHICLES IN CARHOUSEARRAY!!
- #define DialogCarhouseColor1 1
- #define DialogCarhouseColor1Code 2
- #define DialogCarhouseColor2 3
- #define DialogCarhouseColor2Code 4
- //Pickups
- new CarhousePickup;
- //Textdraws
- enum e_CarhouseTD
- {
- PlayerText:name,
- PlayerText:price,
- PlayerText:info
- }
- new Text:CarhouseTD[e_CarhouseTD];
- //Parking Positions for Spawned Cars
- new CarhouseParkingPosition=0;
- enum e_CarhouseParkingPositions
- {
- Float:x,
- Float:y,
- Float:z,
- Float:rot
- }
- new CarhouseParkingPositions[][e_CarhouseParkingPositions]=
- {
- {549.0,-1290.0,17.0,1.0},
- {542.2,-1290.0,17.0,1.0},
- {535.4,-1290.0,17.0,1.0},
- {528.6,-1290.0,17.0,1.0},
- {521.8,-1290.0,17.0,1.0}
- };
- //Cars available in the Carhouse
- enum e_Carhouse
- {
- name[16],
- id,
- price
- }
- // below you can find the list with the cars available,
- // add or delete as many vehicles as you want
- new Carhouse[CarAmount][e_Carhouse]= //name,id,price
- {
- {"Bullet",541,45},
- {"Comet",480,50},
- {"Infernus",411,55},
- {"Phoenix",603,60},
- {"Super GT",506,65},
- {"Turismo",451,70}
- };
- //Variables for every Player to use the Carhose
- enum e_PlayerCarhouse
- {
- index,
- vehicle
- }
- new PlayerCarhouse[MAX_PLAYERS][e_PlayerCarhouse];
- public OnFilterScriptInit()
- {
- CarhousePickup=CreatePickup(1318,1,556,-1292,17);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- //Textdraws
- CarhouseTD[name]=CreatePlayerTextDraw(playerid,30,150,"");
- PlayerTextDrawFont(playerid,CarhouseTD[name],0);
- PlayerTextDrawLetterSize(playerid,CarhouseTD[name],2,3);
- PlayerTextDrawSetOutline(playerid,CarhouseTD[name],2);
- CarhouseTD[price]=CreatePlayerTextDraw(playerid,30,180,"");
- PlayerTextDrawFont(playerid,CarhouseTD[price],1);
- PlayerTextDrawLetterSize(playerid,CarhouseTD[price],1,1.5);
- PlayerTextDrawSetOutline(playerid,CarhouseTD[price],2);
- CarhouseTD[info]=CreatePlayerTextDraw(playerid,330,410,"~g~~k~~PED_SPRINT~ ~w~buy car~n~~g~~k~~CONVERSATION_YES~ ~w~exit");
- PlayerTextDrawFont(playerid,CarhouseTD[info],1);
- PlayerTextDrawLetterSize(playerid,CarhouseTD[info],0.9,1.35);
- PlayerTextDrawSetOutline(playerid,CarhouseTD[info],2);
- }
- public OnPlayerPickUpPickup(playerid,pickupid)
- {
- if(pickupid==CarhousePickup)
- {
- SetPVarInt(playerid,"Carhouse",1);
- PlayerTextDrawShow(playerid,CarhouseTD[name]);
- PlayerTextDrawShow(playerid,CarhouseTD[price]);
- PlayerTextDrawShow(playerid,CarhouseTD[info]);
- TogglePlayerControllable(playerid,0);
- SetPlayerPos(playerid,-1656,1213,22);
- SetPlayerVirtualWorld(playerid,playerid+1);
- SetPlayerCameraPos(playerid,-1658.4591,1211.7958,22);
- SetPlayerCameraLookAt(playerid,-1660.3522,1208.1630,21.1563);
- PlayerCarhouse[playerid][index]=0;
- CreateCarhouseCar(playerid);
- }
- return 1;
- }
- public OnPlayerUpdate(playerid)
- {
- if(GetPVarInt(playerid,"Carhouse"))
- {
- new keys,ud,lr;
- GetPlayerKeys(playerid,keys,ud,lr);
- if(lr==KEY_LEFT)
- {
- PlayerCarhouse[playerid][index]-=1;
- if(PlayerCarhouse[playerid][index] < 0) PlayerCarhouse[playerid][index]=CarAmount-1;
- CreateCarhouseCar(playerid);
- }
- if(lr==KEY_RIGHT)
- {
- PlayerCarhouse[playerid][index]+=1;
- if(PlayerCarhouse[playerid][index] >= CarAmount) PlayerCarhouse[playerid][index]=0;
- CreateCarhouseCar(playerid);
- }
- }
- return 1;
- }
- public OnPlayerKeyStateChange(playerid,newkeys,oldkeys)
- {
- if(PRESSED(KEY_YES) && GetPVarInt(playerid,"Carhouse"))
- {
- ExitCarhouse(playerid);
- return 1;
- }
- if(PRESSED(KEY_SPRINT) && GetPVarInt(playerid,"Carhouse"))
- {
- if(GetPlayerMoney(playerid)<Carhouse[PlayerCarhouse[playerid][index]][price])return SendClientMessage(playerid,col_red,"You haven't got enough money for this car");
- ShowPlayerDialog(playerid,DialogCarhouseColor1,2,"Choose 1st color",\
- "{000000}Black\n{ffffff}White\n{ff0000}Red\n{00ff00}Green\n{0000ff}Blue\n{ffff00}\
- Yellow\n{ffffff}Enter Color ID","Okay","Cancel");
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(response)
- {
- switch(dialogid)
- {
- case 1: //CarhouseColor1
- {
- switch(listitem)
- {
- case 0: SetPVarInt(playerid,"CarhouseColor1",0); //black
- case 1: SetPVarInt(playerid,"CarhouseColor1",1); //white
- case 2: SetPVarInt(playerid,"CarhouseColor1",3); //red
- case 3: SetPVarInt(playerid,"CarhouseColor1",128); //green
- case 4: SetPVarInt(playerid,"CarhouseColor1",162); //blue
- case 5: SetPVarInt(playerid,"CarhouseColor1",194); //yellow
- case 6: ShowPlayerDialog(playerid,DialogCarhouseColor1Code,1,"Colorcode1",\
- "Enter Code for Color1","Okay","Cancel");
- }
- if(listitem != 6) ShowPlayerDialog(playerid,DialogCarhouseColor2,2,"Choose 2nd color",\
- "{000000}Black\n{ffffff}White\n{ff0000}Red\n{00ff00}Green\n{0000ff}Blue\n\
- {ffff00}Yellow\n{ffffff}Enter Color ID","Okay","Cancel");
- }
- case 2: //CarhouseColor1Code
- {
- SetPVarInt(playerid,"CarhouseColor1",strval(inputtext));
- ShowPlayerDialog(playerid,DialogCarhouseColor2,2,"Choose 2nd color",\
- "{000000}Black\n{ffffff}White\n{ff0000}Red\n{00ff00}Green\n{0000ff}Blue\n{ffff00}\
- Yellow\n{ffffff}Enter Color ID","Okay","Cancel");
- }
- case 3: //CarhouseColor2
- {
- switch(listitem)
- {
- case 0: SetPVarInt(playerid,"CarhouseColor2",0); //black
- case 1: SetPVarInt(playerid,"CarhouseColor2",1); //white
- case 2: SetPVarInt(playerid,"CarhouseColor2",3); //red
- case 3: SetPVarInt(playerid,"CarhouseColor2",128); //green
- case 4: SetPVarInt(playerid,"CarhouseColor2",162); //blue
- case 5: SetPVarInt(playerid,"CarhouseColor2",194); //yellow
- case 6: ShowPlayerDialog(playerid,DialogCarhouseColor2Code,1,
- "Colorcode2","Enter Code for Color2","Okay","Cancel");
- }
- if(listitem != 6) ExitCarhouse(playerid,1);
- }
- case 4: //CarhouseColor2Code
- {
- SetPVarInt(playerid,"CarhouseColor2",strval(inputtext));
- ExitCarhouse(playerid,1);
- }
- }
- }
- }
- stock CreateCarhouseCar(playerid)
- {
- new car;
- if(PlayerCarhouse[playerid][vehicle]) DestroyVehicle(PlayerCarhouse[playerid][vehicle]);
- car=CreateVehicle(Carhouse[PlayerCarhouse[playerid][index]][id],-1661.7758,1208.3453,21.1563,287.4759,1,0,0);
- SetVehicleVirtualWorld(car,playerid+1);
- PlayerCarhouse[playerid][vehicle]=car;
- new carname[64], TDPrice[16];
- format(carname,64,"~b~%s",Carhouse[PlayerCarhouse[playerid][index]][name]);
- format(TDPrice,16,"price: %i",Carhouse[PlayerCarhouse[playerid][index]][price]);
- PlayerTextDrawSetString(playerid,CarhouseTD[name],carname);
- PlayerTextDrawSetString(playerid,CarhouseTD[price],TDPrice);
- return 1;
- }
- stock ExitCarhouse(playerid,BuyCar=0)
- {
- PlayerTextDrawHide(playerid,CarhouseTD[name]);
- PlayerTextDrawHide(playerid,CarhouseTD[price]);
- PlayerTextDrawHide(playerid,CarhouseTD[info]);
- SetPlayerPos(playerid,556.0813,-1290.2650,17.2482);
- SetPlayerVirtualWorld(playerid,0);
- TogglePlayerControllable(playerid,1);
- SetCameraBehindPlayer(playerid);
- SetPVarInt(playerid,"Carhouse",0);
- if(!BuyCar) return 1;
- new Float:_x,Float:_y,Float:_z,Float:_rot,ind=CarhouseParkingPosition;
- _x=CarhouseParkingPositions[ind][x];
- _y=CarhouseParkingPositions[ind][y];
- _z=CarhouseParkingPositions[ind][z];
- _rot=CarhouseParkingPositions[ind][rot];
- new car;
- car=CreateVehicle(Carhouse[PlayerCarhouse[playerid][index]][id],_x,_y,_z,_rot,\
- GetPVarInt(playerid,"CarhouseColor1"),GetPVarInt(playerid,"CarhouseColor2"),0);
- //Set Vehicle Numplate; not necessary, but makes things easier
- new numid[8];
- format(numid,8,"%i",car);
- SetVehicleNumberPlate(car,numid);
- CarhouseParkingPosition +=1;
- if(CarhouseParkingPosition > 4)CarhouseParkingPosition=0;
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement