SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Thread Tools Display Modes
Old 23/11/2017, 05:11 PM   #11
Join Date: Dec 2013
Location: GetPlayerPos(playerid, pos); Scripter/Mapper.
Posts: 3,133
Reputation: 445
Default Re: Fuel

Originally Posted by frouzen View Post
PHP Code:

PlayerInfo[playerid][Admin] < 2) return SendClientMessage(playerid,-1,"{FF0000}[ADMIN] {FFFFFF}Nemas AdminLevel 2"); 
format(string,sizeof(string),"Administrator %s all vehicle fuel",PlayerName(playerid)); 
IsValidVehicle(i)) Benzin[i] = 100

Could be done better. For one, string doesn't need to be declared before admin level check, it also does not need to be 128 cells. The most you'll get from "Administrator all vehicle fuel" is 32 characters, add in MAX_PLAYER_NAME + 1, you have 57. If you want to be even, use 60 cells. Still better than 128. Also, make use of GetVehiclePoolSize if using 0.3.7. If you have 50 vehicles, you loop through 50. If you use MAX_VEHICLES, you loop through an additional 1950 not even being used. You can also count out vehicle 0, as vehicle indexes start from 1.

pawn Code:
CMD:tankovat(playerid, params[])
    if(PlayerInfo[playerid][Admin] < 2) return SendClientMessage(playerid,-1,"{FF0000}[ADMIN] {FFFFFF}Nemas AdminLevel 2");

   new string[60];
   format(string,sizeof(string),"Administrator %s all vehicle fuel",PlayerName(playerid));
   for(new i = 1; i < GetVehiclePoolSize();i++)
          If(IsValidVehicle(i)) Benzin[i] = 100;
    return 1;

It's things like this that are good habits to develop. They don't really slow down the scripting process but if these types of practices are used, they can make your gamemode neater to look at and also perform better, even if marginally.
Abagail is offline   Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
fuel system problem all vehicles use same fuel(enum variables, timers) grymtn Scripting Help 7 09/04/2017 08:16 PM
Fuel System - No Fuel Scottylad Scripting Help 3 31/10/2015 12:51 AM
[FilterScript] Fuel System [Fuel/Speed/Vehicle Name/Health] reddromero Filterscripts 5 10/05/2014 02:50 AM
Custom Fuel system taking 2 fuel instead of 1. ricardo178 Scripting Help 6 27/04/2013 10:16 AM
Fuel[i] -= 1; (Insted of taking 1, takes all fuel) HondaCBR Scripting Help 2 15/04/2012 01:03 PM

All times are GMT. The time now is 07:03 PM.

Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.