LUF.nut
/*
Liberty Unleashed Fuel Script - Server
Version 1.0
by [MKs]X_94
*/
//--- Data ---
const Price_Per_Liter = 20;
const Max_Gas = 50;
const Min_Gas = 10;
const Rand_Gas = 20;
const FSphereRadius = 5.0;
local fuel = array( MAX_VEHICLES 1, 0 );
local Dispatchers = array( MAX_SPHERES 1, null );
BLUE <- ::Colour( 0, 0, 255 );
ORANGE <- ::Colour( 255, 153, 0 );
LBLUE <- ::Colour( 51, 51, 153 );
GREEN <- ::Colour( 0, 255, 0 );
RED <- ::Colour( 255, 0, 0 );
SKYBLUE <- ::Colour( 0, 102, 255 );
PURPLE <- ::Colour( 204, 0, 204 );
iCPURPLE <- ::Colour( 100, 20, 255 );
//--- Script Events ---
function onScriptLoad()
{
for ( local i = 0; i <= MAX_VEHICLES; i ) fuel[ i ] = Random( Min_Gas, Rand_Gas );
Dispatchers[ 0 ] = CreateDispatcher( 0, Vector( 1155.50, -74.10, 7.47 ) );
Dispatchers[ 1 ] = CreateDispatcher( 1, Vector( 1163.50, -74.31, 7.47 ) );
Dispatchers[ 2 ] = CreateDispatcher( 2, Vector( 1171.50, -74.40, 7.47 ) );
NewTimer( "FuelProcess", 60000, 0 );
print( "LU Fuel Script Loaded" );
return 1;
}
function onPlayerEnterSphere( player, Sph )
{
local Dispatcher = FindDispatcher( Sph.ID );
if ( Dispatcher )
{
if ( !Dispatcher.Player || Dispatcher.Player == player.Name )
{
if ( FindPlayerDispatcher( player ) ) MessagePlayer( "You are using other dispatcher yet", player, RED );
else
{
Dispatcher.Player = player;
CallClientFunc( player, "LU-FS/LUFC.nut", "CreateMenu" );
}
}
else MessagePlayer( "Sorry, this fuel dispatcher is being using, go to other dispatcher or fuel station", player, RED );
}
return 1;
}
function onPlayerExitSphere( player, Sph )
{
local Dispatcher = FindDispatcher( Sph.ID );
if ( Dispatcher )
{
if ( Dispatcher.Player )
{
Dispatcher.Player = null;
CallClientFunc( player, "LU-FS/LUFC.nut", "DeleteMenu" );
}
}
return 1;
}
function onVehicleRespawn( vehicle )
{
fuel[ vehicle.ID ] = Random( Min_Gas, Rand_Gas );
return 1;
}
function onPlayerEnteredVehicle( player, vehicle, door )
{
if ( fuel[ vehicle.ID ] <= 0 )
{
CallClientFunc( player, "LU-FS/LUFC.nut", "DisplayFuelMeter", "EMPTY" );
vehicle.SetEngineState( false );
fuel[ vehicle.ID ] = 0;
}
else
{
CallClientFunc( player, "LU-FS/LUFC.nut", "DisplayFuelMeter", fuel[ vehicle.ID ] );
}
return 1;
}
function FindPlayerDispatcher( plr )
{
for ( local i = 0; i <= MAX_SPHERES; i )
{
local D = FindDispatcher( i );
if ( D && D.Player == plr.Name ) { return true; break; }
}
return false;
}
//---- Script Functions ----
function FuelProcess()
{
for ( local i = 0; i <= MAX_PLAYERS; i )
{
local player = FindPlayer( i );
if ( player && player.Vehicle )
{
local veh = player.Vehicle;
if ( IsVehicleCar( veh.Model ) )
{
if ( veh.Driver.ID == player.ID )
{
fuel[ veh.ID ] --;
}
if ( fuel[ veh.ID ] <= 0 )
{
CallClientFunc( player, "LU-FS/LUFC.nut", "DisplayFuelMeter", "EMPTY" );
if ( veh.Driver.ID == player.ID )
{
veh.SetEngineState( false );
}
fuel[ veh.ID ] = 0;
}
else
{
veh.SetEngineState( true );
CallClientFunc( player, "LU-FS/LUFC.nut", "DisplayFuelMeter", fuel[ veh.ID ] );
}
}
}
}
}
class CreateDispatcher
{
function constructor( id, pos )
{
Player = null;
Pos = pos;
ID = id;
local D = ::CreateSphere( pos, FSphereRadius, ::Colour( Random( 0, 256 ), Random( 0, 256 ), Random( 0, 256 ) ) );
if ( D )
{
D.Type = 2;
Sphere = D.ID;
}
}
Player = null;
Pos = null;
ID = 0;
Sphere = 0;
}
function FindDispatcher( sphID )
{
for ( local i = 0; i <= MAX_SPHERES; i )
{
local D = Dispatchers[ i ];
if ( D && D.Sphere == sphID ) { return Dispatchers[ i ]; break; }
}
return null;
}
function Random( min, max )
{
min = min.tointeger(), max = max.tointeger() 1;
local a = rand() % ( max - min ) min;
return a;
}
function SetVehicleTank( player, tank )
{
local veh = player.Vehicle;
if ( veh )
{
local cost = Price_Per_Liter * tank;
if ( player.Cash < cost ) MessagePlayer( "Error - You need at least $" cost " in your pocket", player, RED );
else
{
if ( fuel[ veh.ID ] == Max_Gas ) MessagePlayer( "Error - Your car is full yet", player, RED );
else if ( ( fuel[ veh.ID ] tank ) > Max_Gas ) MessagePlayer( "Error - Excesive amount, you cannot have more than " Max_Gas " liters in your car", player, RED );
else
{
MessagePlayer( "Your car has been refuelled with " tank " liters of fuel, Cost: $" cost " good luck
", player, GREEN );
fuel[ veh.ID ] = tank;
player.Cash -= cost;
}
}
}
}
//---- Juppi's function ----
function IsVehicleCar( model )
{
switch ( model )
{
case VEH_PREDATOR:
case VEH_TRAIN:
case VEH_CHOPPER:
case VEH_DODO:
case VEH_RCBANDIT:
case VEH_AIRTRAIN:
case VEH_DEADDODO:
case VEH_SPEEDER:
case VEH_REEFER:
return false;
}
return true;
}
LUFC.nut
/*
Liberty Unleashed Fuel Script - Client
Version 1.0
by [MKs]X_94
*/
//---- Script Data ----
local lP = FindLocalPlayer();
local BLUE = Colour( 0, 0, 255 );
local ORANGE = Colour( 255, 153, 0 );
local LBLUE = Colour( 51, 51, 153 );
local GREEN = Colour( 0, 255, 0 );
local RED = Colour( 255, 0, 0 );
local SKYBLUE = Colour( 0, 102, 255 );
local PURPLE = Colour( 204, 0, 204 );
local iCPURPLE = Colour( 100, 20, 255 );
const Price_Per_Liter = 20;
const Max_Gas = 50;
const Min_Gas = 10;
const Rand_Gas = 20;
const FSphereRadius = 5.0;
//----- GUI -----
local FLabel = GUILabel( VectorScreen( ScreenWidth - 225, ScreenHeight - 25 ), ScreenSize( 5, 25 ), "Fuel:" );
local FullTank_Button = GUIButton( VectorScreen( 5, 5 ), ScreenSize( 225, 25 ), "Full Tank" );
local MenuWindow = GUIWindow( VectorScreen( ScreenWidth - ( ScreenWidth / 2 ), ScreenHeight - ( ScreenHeight / 2 ) ), ScreenSize( 350, 250 ), "Fuel Dispatcher Menu" );
local ExitMenu_Button = GUIButton( VectorScreen( 5, 95 ), ScreenSize( 225, 25 ), "Exit Menu" );
local FuelBox = GUIEditbox( VectorScreen( 5, 65 ), ScreenSize( 225, 25 ) );
local otherwL = GUILabel( VectorScreen( 5, 35 ), ScreenSize( 225, 25 ), "Or if you want choose how many fuel wanna you buy" );
//----- Script Events -----
function onScriptLoad()
{
BindKey( KEY_RETURN, BINDTYPE_DOWN, "PressEnter" );
MenuWindow.Colour = Colour( 5, 5, 5 );
MenuWindow.Visible = false;
FLabel.FontName = "Calibri";
FLabel.FontSize = 10;
FLabel.TextColour = RED;
otherwL.FontName = "Calibri";
otherwL.FontSize = 13;
otherwL.TextColour = ORANGE;
ExitMenu_Button.TextColour = GREEN;
FullTank_Button.TextColour = SKYBLUE;
ExitMenu_Button.Colour = Colour( 5, 5, 5 );
FullTank_Button.Colour = RED;
FullTank_Button.Text = "Full Tank";
FuelBox.TextColour = iCPURPLE;
FuelBox.Colour = LBLUE;
FuelBox.Active = true;
FLabel.Visible = false;
otherwL.Visible = true;
MenuWindow.AddChild( FullTank_Button );
MenuWindow.AddChild( ExitMenu_Button );
MenuWindow.AddChild( otherwL );
MenuWindow.AddChild( FuelBox );
AddGUILayer( MenuWindow );
AddGUILayer( FLabel );
FullTank_Button.SetCallbackFunc( "SetFullTank" );
ExitMenu_Button.SetCallbackFunc( "DeleteMenu" );
return 1;
}
function onClientExitedVehicle( veh )
{
if ( FLabel.Visible ) FLabel.Visible = false;
return 1;
}
//----- Script Functions -----
function DisplayFuelMeter( fuel )
{
if ( !FLabel.Visible ) FLabel.Visible = true;
FLabel.Text = "Fuel: " fuel;
}
function SetFullTank()
{
CallServerFunc( "LU-FS/LUF.nut", "SetVehicleTank", lP, Max_Gas );
}
function PressEnter()
{
if ( MenuWindow.Visible )
{
local f = FuelBox.Text;
if ( f && IsNum( f ) )
{
CallServerFunc( "LU-FS/LUF.nut", "SetVehicleTank", lP, f.tointeger() );
}
else Message( "Error - The amount is null or must be a number", RED );
}
}
function CreateMenu()
{
if ( !MenuWindow.Visible ) MenuWindow.Visible = true;
if ( !FuelBox.Active ) FuelBox.Active = true;
if ( FuelBox.Text ) FuelBox.Text = null;
lP.Frozen = true;
if ( !IsMouseCursorShowing() ) ShowMouseCursor( true );
}
function DeleteMenu()
{
if ( MenuWindow.Visible ) MenuWindow.Visible = false;
if ( FuelBox.Active ) FuelBox.Active = false;
if ( FuelBox.Text ) FuelBox.Text = null;
lP.Frozen = false;
if ( IsMouseCursorShowing() ) ShowMouseCursor( false );
}
Script.xml
<script file=LUF.nut" client="0" />
<script file="LUFC.nut" client="1" />