19.06.2011, 20:45
It doesn't update fuel, I have no idea what's causing this.
Код:
#include <a_samp> #include <streamer> //===============DIALOGS #define MAINDIALOG 12056 #define FUELDIALOG 12057 #define TANKDIALOG 12058 //===============FOR KEYS #define PRESSED(%0) \ (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0))) //================VAR new Float:VFuel[MAX_VEHICLES]; new Tank[MAX_PLAYERS]; new engine,lights,alarm,doors,bonnet,boot,objective; //================FUEL_STATIONS #define MAX_STATIONS 26 new Float:Station[MAX_STATIONS][3]={ {1944.3717,-1772.7307,13.3906}, {1939.1682,-1772.8269,13.3828}, {-99.0707,-1173.1080,2.4191}, {-93.8733,-1160.8280,2.1795}, {-87.3328,-1164.6559,2.2693}, {-91.9832,-1176.1752,2.1985}, {-1668.9750,407.6899,7.1797}, {-1675.1237,413.9737,7.1797}, {-1681.9315,420.2315,7.1797}, {-2407.6882,976.9827,45.2969}, {-1609.0656,-2718.9431,48.5391}, {-1605.5094,-2714.2961,48.5335}, {-1602.4349,-2709.7388,48.5391}, {-1465.0649,1866.5117,32.6328}, {-1477.5488,1865.7651,32.6398}, {-1477.4956,1858.0613,32.6398}, {-1464.8992,1858.6085,32.6328}, {-1328.7679,2671.9915,50.0625}, {-1328.3496,2677.5759,50.0625}, {-1327.6848,2682.9897,50.0625}, {2205.7717,2474.5010,10.8203}, {2199.0620,2474.8723,10.8203}, {2639.7009,1102.9178,10.8203}, {2639.8220,1109.6555,10.8203}, {1381.3658,457.4052,19.9383}, {1383.1332,461.8247,20.1210} }; //================TEXT new Text:Background0,Text:Background1,Text:Fuel[MAX_VEHICLES],Text:FuelLvl; //=====================================================================LOADPFUEL public OnFilterScriptInit() { for(new i=0;i<MAX_STATIONS;i++) { CreateDynamic3DTextLabel("[{C14124}Fuel Station{FFFFFF}]\n Press SPACE", 0xFFFFFFFF, Station[i][0], Station[i][1], Station[i][2], 100, INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0, -1, -1,-1); } SetTimer("FuelTimer",10000,true); SetTimer("TextDraw",500,true); ManualVehicleEngineAndLights(); Background0 = TextDrawCreate(504.000000, 130.000000, "Background"); TextDrawBackgroundColor(Background0, 0); TextDrawFont(Background0, 1); TextDrawLetterSize(Background0, 0.500000, 1.000000); TextDrawColor(Background0, 0); TextDrawSetOutline(Background0, 0); TextDrawSetProportional(Background0, 1); TextDrawSetShadow(Background0, 1); TextDrawUseBox(Background0, 1); TextDrawBoxColor(Background0, 255); TextDrawTextSize(Background0, 602.000000, 0.000000); Background1 = TextDrawCreate(506.000000, 133.000000, "Background2"); TextDrawBackgroundColor(Background1, 0); TextDrawFont(Background1, 1); TextDrawLetterSize(Background1, 0.500000, 0.399999); TextDrawColor(Background1, 0); TextDrawSetOutline(Background1, 0); TextDrawSetProportional(Background1, 1); TextDrawSetShadow(Background1, 1); TextDrawUseBox(Background1, 1); TextDrawBoxColor(Background1, 2018514120); TextDrawTextSize(Background1, 600.000000, 0.000000); FuelLvl = TextDrawCreate(502.000000, 114.000000, "Fuel level"); TextDrawBackgroundColor(FuelLvl, 255); TextDrawFont(FuelLvl, 0); TextDrawLetterSize(FuelLvl, 0.549999, 1.800000); TextDrawColor(FuelLvl, -1); TextDrawSetOutline(FuelLvl, 0); TextDrawSetProportional(FuelLvl, 1); TextDrawSetShadow(FuelLvl, 1); for(new i=1;i<MAX_VEHICLES;i++) { VFuel[i]=random(100); Fuel[i] = TextDrawCreate(506.000000, 133.000000, "Fuel"); TextDrawBackgroundColor(Fuel[i], 0); TextDrawFont(Fuel[i], 1); TextDrawLetterSize(Fuel[i], 0.500000, 0.399999); TextDrawColor(Fuel[i], 0); TextDrawSetOutline(Fuel[i], 0); TextDrawSetProportional(Fuel[i], 1); TextDrawSetShadow(Fuel[i], 1); TextDrawUseBox(Fuel[i], 1); TextDrawBoxColor(Fuel[i], -932962561); TextDrawTextSize(Fuel[i], 600.000000, 0.000000); } } //=====================================================================FUELTIMER forward FuelTimer(); public FuelTimer() { for(new i=1;i<MAX_VEHICLES;i++) { TextDrawTextSize(Fuel[i], 500.0+VFuel[i], 0.000000); GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective); if(engine==1 && IsAValidVehicle(i)) { VFuel[i]=VFuel[i]-0.1; if(VFuel[i]<=0) { SetVehicleParamsEx(i,0,0,alarm,doors,bonnet,boot,objective); VFuel[i]=0; } } } return 1; } //===========================================================ONPLAYERSTATECHANGE public OnPlayerStateChange(playerid,newstate,oldstate) { if(newstate==PLAYER_STATE_DRIVER) { GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective); if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) return SetVehicleParamsEx(GetPlayerVehicleID(playerid),1,lights,alarm,doors,bonnet,boot,objective); if(engine==1) SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] The engine is on. To turn it off press {C14124}ALT SX"); else SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] The engine is off. To turn it on press {C14124}ALT SX"); TextDrawShowForPlayer(playerid,Background0); TextDrawShowForPlayer(playerid,Background1); TextDrawShowForPlayer(playerid,FuelLvl); TextDrawShowForPlayer(playerid,Fuel[GetPlayerVehicleID(playerid)]); return 1; } if(newstate==PLAYER_STATE_ONFOOT) { TextDrawHideForPlayer(playerid,Fuel[playerid]); TextDrawHideForPlayer(playerid,Background0); TextDrawHideForPlayer(playerid,Background1); TextDrawHideForPlayer(playerid,FuelLvl); return 1; } return 1; } //===========================================================ONPLAYEREXITVEHICLE public OnPlayerExitVehicle(playerid) { GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective); if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) SetVehicleParamsEx(GetPlayerVehicleID(playerid),0,lights,alarm,doors,bonnet,boot,objective); return 1; } //========================================================ONPLAYERKEYSTATECHANGE public OnPlayerKeyStateChange(playerid,newkeys,oldkeys) { if(PRESSED(KEY_SUBMISSION) && GetPlayerState(playerid)==PLAYER_STATE_DRIVER) { GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective); if(lights==1) SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,0,alarm,doors,bonnet,boot,objective); else SetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,1,alarm,doors,bonnet,boot,objective); return 1; } //=====================================================KEYFIRE if(PRESSED(KEY_FIRE)) { //==================ENGINE ON if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsAValidVehicle(GetPlayerVehicleID(playerid))) { GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective); if(VFuel[GetPlayerVehicleID(playerid)]<=0) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}The vehicle run out of fuel."); if(engine<=0) { SetVehicleParamsEx(GetPlayerVehicleID(playerid),1,lights,alarm,doors,bonnet,boot,objective); SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] You turn on the engine."); return 1; } else { SetVehicleParamsEx(GetPlayerVehicleID(playerid),0,lights,alarm,doors,bonnet,boot,objective); SendClientMessage(playerid,0xFFFFFFFF,"[ENGINE:] You turn off the engine."); return 1; } } } //=======================================================KEYBRAKE if(PRESSED(KEY_HANDBRAKE) || PRESSED(KEY_SPRINT)) { //================FUEL STATION for(new i=0;i<MAX_STATIONS;i++) { if(IsPlayerInRangeOfPoint(playerid,3,Station[i][0],Station[i][1],Station[i][2])) { if(!IsPlayerInAnyVehicle(playerid) && PRESSED(KEY_SPRINT)) return ShowPlayerDialog(playerid,TANKDIALOG,0,"Tank menщ","{DEDEDE}Do you want to buy a {c14124}Fuel Tank{DEDEDE} of 10 lt. \nfor {89FF56}40${DEDEDE}?","Yes","No"); else if(GetPlayerState(playerid)==PLAYER_STATE_DRIVER && IsAValidVehicle(GetPlayerVehicleID(playerid)) && PRESSED(KEY_HANDBRAKE)) return ShowPlayerDialog(playerid,MAINDIALOG,DIALOG_STYLE_LIST,"Station menщ","{c14124}Refuel {DEDEDE} your vehicle.\nBuy a {c14124}Fuel Tank{DEDEDE} of 10 lt.","Select","Exit"); } } } return 1; } //==============================================================ONDIALOGRESPONSE public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[]) { //=========================TANKDIALOG if(dialogid==TANKDIALOG && response) { GivePlayerMoney(playerid,-40); SendClientMessage(playerid,0xFFFFFFFF,"[TANK:]You buyied a {C14124}fuel tank{FFFFFF}."); Tank[playerid]+=1; return 1; } //=========================MAINDIALOG if(dialogid==MAINDIALOG && response) { if (listitem==0) return ShowPlayerDialog(playerid,FUELDIALOG,DIALOG_STYLE_INPUT,"Fuel menu","{DEDEDE}Welcome to the gas station!\nPlease inserit the number of gallons you want to refill to your vehicle.\n {C14124}1 gallon {DEDEDE}= {C14124}2$","Refuel","Exit"); if (listitem==1) return ShowPlayerDialog(playerid,TANKDIALOG,0,"Tank menщ","{DEDEDE}Do you want to buy a {c14124}Fuel Tank{DEDEDE} of 10 lt. \nfor {89FF56}40${DEDEDE}?","Yes","No"); } //=========================FUELDIALOG if(dialogid==FUELDIALOG && response) { if(VFuel[GetPlayerVehicleID(playerid)]>=100) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}Your vehicle is full of fuel"); if(strval(inputtext)<=0 || strval(inputtext)>100) return ShowPlayerDialog(playerid,FUELDIALOG,DIALOG_STYLE_INPUT,"Fuel menu","{C14124}Error: inserit a number between 0 and 100 gallons.\n\n{DEDEDE}Welcome to the gas station!\nPlease inserit the number of gallons you want to refill to your vehicle.\n {C14124}1 gallon {DEDEDE}= {C14124}2$","Refuel","Exit"); if(VFuel[GetPlayerVehicleID(playerid)]+ strval(inputtext) > 100.0) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You can't refill your vehicle with so many gallons"); VFuel[GetPlayerVehicleID(playerid)]=VFuel[GetPlayerVehicleID(playerid)]+strval(inputtext); GivePlayerMoney(playerid,-strval(inputtext)*2); new stringa[256]; format(stringa,sizeof(stringa),"[FUEL:] You filled your vehicle with {C14124}%d {FFFFFF}gallons for {C14124}%d$",strval(inputtext),strval(inputtext)*2); SendClientMessage(playerid,0xFFFFFFFF,stringa); return 1; } return 1; } //===============================================================ISAVALIDVEHICLE stock IsAValidVehicle(vehicleid) { new x=GetVehicleModel(vehicleid); if(x>=400 && x!=509 && x!=481 && x!=510 && x!=548 && x!=425 && x!=417 && x!=487 && x!=488 && x!=497 && x!=563 && x!=447 && x!=469 && x!=592 && x!=577 && x!=511 && x!=512 && x!=593 && x!=520 && x!=553 && x!=476 && x!= 519 && x!=460 && x!=513 && x!=472 && x!=473 && x!=493 && x!=595 && x!=484 && x!=430 && x!=453 && x!=452 && x!=446 && x!=454 && x!=449 && x!=537 && x!=538) return 1; else return 0; } //================================================================ONPLAYERUPDATE forward TextDraw(); public TextDraw() { for(new i=0;i<MAX_PLAYERS;i++) { if(GetPlayerState(i)==PLAYER_STATE_DRIVER && GetPlayerState(i)!=PLAYER_STATE_EXIT_VEHICLE && IsAValidVehicle(GetPlayerVehicleID(i))) { TextDrawHideForPlayer(i,Fuel[GetPlayerVehicleID(i)]); TextDrawTextSize(Fuel[GetPlayerVehicleID(i)], 500.0+VFuel[i], 0.000000); TextDrawShowForPlayer(i,Fuel[GetPlayerVehicleID(i)]); } } return 1; } //================================================================ONVEHICLESPAWN public OnVehicleSpawn(vehicleid) { VFuel[vehicleid]=random(100); return 1; } //===========================================================ONPLAYERCOMMANDTEXT public OnPlayerCommandText(playerid,cmdtext[]) { if(!strcmp("/refuel",cmdtext,true)) { if(GetPlayerState(playerid)!=PLAYER_STATE_DRIVER) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You are not driving a vehicle."); if(!IsAValidVehicle(GetPlayerVehicleID(playerid))) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}This type of vehicle does not need to be refilled with fuel"); if(!Tank[playerid]) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You have no tank to refuel the vehicle"); if(VFuel[GetPlayerVehicleID(playerid)]>90) return SendClientMessage(playerid,0xFF0000FF,"[ERROR:] {FFFFFF}You have enough fuel for now."); Tank[playerid]--; VFuel[GetPlayerVehicleID(playerid)]+=10; SendClientMessage(playerid,0x00FF00FF,"[VEHICLE:] {FFFFFF}You refilled successfully your vehicle."); return 1; } return 0; } //=====================================================================ISNUMERIC stock isNumeric(const string[]) { new length=strlen(string); if (length==0) return false; for (new i = 0; i < length; i++) { if ( (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') || (string[i]=='-' && i!=0) || (string[i]=='+' && i!=0) ) return false; } if (length==1 && (string[0]=='-' || string[0]=='+')) return false; return true; }