Sunshine Autos: Creating a vehicle shop.

Started by JhonDude, Oct 17, 2022, 12:49 PM

Previous topic - Next topic

JhonDude

Hello Guys!
I'm trying to create a simple vehicle shop.
I don't wanna to use cmds, to call the functions.
I wanna to create something more especific.

So, there is my code:
function onPlayerEnteringVehicle(player, vehicle, door)
{
  if (vehicle.Model == 206)
    {
     if (player.Cash < 2500) MessagePlayer("[#00cc00] Need enough money!",player);
     else{
            player.Cash -= 2500;
            MessagePlayer("[#00cc00] You buy a Car! Congratz!",player);
            return true;
            }
    }
}

Works fine, but this functions are called every time i enter the car again.
I don't wanna this!

This function will only be called if the car is destroyed, blown up, or sunk!

The functions will be called once at the first time a player enter in a car!
If player exit and enter again, the system don't reduce your cash.
Cause this cars is already yours.

I want a function that makes the new  purchased car, free for all users!
Even for those who try to steal it!
We are in Vice City after all!
Cars are frequently stolen! 8)

Thanks in advance for your help!

JhonDude

Morning Guys!
So... I did it!
As I said before, I was trying to call a specific function, which would allow me to buy the vehicle only once.
After that, the vehicle will be free to use by any player.
And it would only be bought again if it was destroyed or sunk.
And as I expected, the script is quite simple!
Well, at least I found a simple solution. ;D

Here is the code:
function onPlayerEnteringVehicle( player, vehicle, door )
{
if (vehicle.Model == 132)
    {
     if (vehicle.IsGhost == false) return true;
     else if (player.Cash < 2500) MessagePlayer("[#00cc00] Need enough money!",player);
        else{
            player.Cash -= 2500;
            MessagePlayer("[#00cc00] You buy a Car! Congratz!",player);
            return true;           
            }
    }
if (vehicle.Model == 141)
    {
     if (vehicle.IsGhost == false) return true;
     else if (player.Cash < 5000) MessagePlayer("[#00cc00] Need enough money!",player);
        else{
            player.Cash -= 5000;
            MessagePlayer("[#00cc00] You buy a Car! Congratz!",player);
            return true;           
            }
    }
}
function onPlayerEnterVehicle( player, vehicle, door )
{
  vehicle.IsGhost = false;
}
function onVehicleRespawn( vehicle )
{
  vehicle.IsGhost = true;   
}

Note that I used "vehicle.IsGhost" instead of "vehicle.Locked".
The second function just didn't work in this case. I don't know wy. ???
But the first function works fine. With a small caveat:
All vehicles spawned are now "Ghost Vehicles".
This means that they lost the effect of collision with other vehicles.
However, once purchased, it returns to the collision effect, and everything goes back to normal.
At least with the vehicle you just bought.
Those that have not yet been purchased remains "Ghost Vehicles".

So, this is it!
That's my solution!
If anyone has a better idea, don't hesitate to let me know.
See u guys! 8)