Author Topic: LUFuel Script  (Read 5330 times)

[EG]~[S]aha~

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +1/-9
  • Liberty Unleashed!
    • View Profile
LUFuel Script
« on: October 02, 2012, 08:19:16 am »
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" />

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: LUFuel Script
« Reply #1 on: October 02, 2012, 09:05:17 am »
X_94 already posted this.  ???
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: LUFuel Script
« Reply #2 on: October 03, 2012, 02:15:55 am »
Good! I was looking for it, but wait...
It dosen't work, "Error expected ')' line=186 column=41


Code: [Select]
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 );

X_94 already posted this.  ???
He erased it, that's why I'm looking for it
« Last Edit: October 03, 2012, 02:48:36 am by IdkanYavuk »

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: LUFuel Script
« Reply #3 on: October 03, 2012, 12:46:05 pm »
If you can script just a tiny bit you can see it needs +'s around the Max_Gas variable..

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: LUFuel Script
« Reply #4 on: October 03, 2012, 05:35:56 pm »
If you can script just a tiny bit you can see it needs +'s around the Max_Gas variable..
Actually, that's not the problem, could somebody help me?

Thijn

  • Tester
  • Sr. Member
  • ****
  • Posts: 531
  • Karma: +27/-16
    • View Profile
Re: LUFuel Script
« Reply #5 on: October 03, 2012, 08:00:14 pm »
If the line the error is coming from is the one you posted, it is.
Otherwise we can't help until that's posted.

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: LUFuel Script
« Reply #6 on: October 03, 2012, 08:42:13 pm »
If the line the error is coming from is the one you posted, it is.
Otherwise we can't help until that's posted.

Code: [Select]
/*
     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;
}

First Problem:
Code: [Select]
Scripts/LU-FS/LUF.nut line = (170) column = (52) : error end of statement expected (; or lf)
Second Problem:
Code: [Select]
Scripts/LU-FS/LUF.nut line = (171) column = (42) : error end of statement expected (; or lf)
Third Problem:
Code: [Select]
Scripts/LU-FS/LUF.nut line=(186) column=(41) : error expected ')'
« Last Edit: October 03, 2012, 08:47:31 pm by IdkanYavuk »

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: LUFuel Script
« Reply #7 on: October 04, 2012, 09:27:37 am »
He erased it.

Then this shouldn't have been posted without his permissions.

Here is the code anyway,


Code: [Select]
/*
     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();
    local a = rand() % ( max - 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( "Your car has been refuelled with " + tank + " liters of fuel, Cost: $" + cost + " good luck ", player, GREEN );
                fuel[ veh.ID ]  = tank;           
                player.Cash -= cost;
            }
else MessagePlayer( "Error - Excesive amount, you cannot have more than " + Max_Gas + " liters in your car", player, RED );
        }         
    }
}   
   
   //---- 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;
}

Just required some minor fixes.
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: LUFuel Script
« Reply #8 on: October 04, 2012, 07:30:23 pm »
Code: [Select]
else if ( ( fuel[ veh.ID ]  tank ) < Max_Gas )
The problem persists
Something has to be between [veh.ID] and tank, what is that?
I'm a newbie at scripting, I know some things, but I don't have any idea there

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: LUFuel Script
« Reply #9 on: October 05, 2012, 02:41:49 pm »
Code: [Select]
else if ( ( fuel[ veh.ID ]  tank ) < Max_Gas )
The problem persists
Something has to be between [veh.ID] and tank, what is that?
I'm a newbie at scripting, I know some things, but I don't have any idea there

What error?
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

Shadow.

  • Tester
  • Full Member
  • ****
  • Posts: 144
  • Karma: +16/-35
    • View Profile
Re: LUFuel Script
« Reply #10 on: October 05, 2012, 02:47:25 pm »
Code: [Select]
else if ( ( fuel[ veh.ID ]  tank ) < Max_Gas )
The problem persists
Something has to be between [veh.ID] and tank, what is that?
I'm a newbie at scripting, I know some things, but I don't have any idea there

What error?


Code: [Select]
else if ( ( fuel[ veh.ID ]  tank ) < Max_Gas )

What is fuel[ veh.ID ] tank supposed to mean ?

IdkanYavuk X

  • Jr. Member
  • **
  • Posts: 91
  • Karma: +37/-36
  • Developer for The Newport Experience
    • View Profile
Re: LUFuel Script
« Reply #11 on: October 05, 2012, 06:34:50 pm »
What error?

Code: [Select]
Scripts/LU-FS/LUF.nut line=(186) column=(41) : error expected ')'

Rocky

  • Full Member
  • ***
  • Posts: 105
  • Karma: +5/-3
    • View Profile
Re: LUFuel Script
« Reply #12 on: October 06, 2012, 08:05:05 am »
Code: [Select]
/*
     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();
    local a = rand() % ( max - 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( "Your car has been refuelled with " + tank + " liters of fuel, Cost: $" + cost + " good luck ", player, GREEN );
                fuel[ veh.ID ]  = tank;           
                player.Cash -= cost;
            }
else MessagePlayer( "Error - Excesive amount, you cannot have more than " + Max_Gas + " liters in your car", player, RED );
}
        }         
    }
}   
   
   //---- 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;
}
Look for lu server testers, Requirements are:
English good enough to communicate.
Good knowledge about gaming.

PM me those who are interested.

 

© Liberty Unleashed Team.