Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: Kewun on Dec 10, 2016, 08:03 PM

Title: returns true all the time
Post by: Kewun on Dec 10, 2016, 08:03 PM
function GetVehiclePrice(player)
{
  if ( player.Vehicle ) {
    return ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
  }
}

This code always returns "true" when it should display the price of vehicle
how do i fix that?
Title: Re: returns true all the time
Post by: Luis_Labarca on Dec 10, 2016, 08:14 PM
tried this with my role and I know well but not is you because you may have different the code if you like raisins all lcodigopara see as it is and fix it
function GetVehiclePrice(player)
{
local VehicleID2=ReadIniNumber( "vdb.ini", ""+player.Vehicle.ID+"", "Price");
if(VehicleID2 !=null)
{
return VehicleID2;
}
return 0;
}
Title: Re: returns true all the time
Post by: Kewun on Dec 10, 2016, 08:18 PM
not work( still returns true
Title: Re: returns true all the time
Post by: Luis_Labarca on Dec 10, 2016, 10:17 PM
Quote from: JiN_KaZaMa on Dec 10, 2016, 08:18 PMnot work( still returns true
I did a cost, owner, shared system of vehicle

http://forum.vc-mp.org/?topic=3499.new#new
Title: Re: returns true all the time
Post by: KAKAN on Dec 11, 2016, 05:18 AM
Check for another function with the same name. You've done that mistake many times though :p
Title: Re: returns true all the time
Post by: Mötley on Dec 11, 2016, 01:03 PM
Dont you hate it when that happens?
Well at-least try this code, This worked for me, So I modified the code to work for your script. I hope it works....
function GetVehiclePrice(player)
{
local Price;
        Price = ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
if ( Price != null )
return Price;

return 0;
}

And If not IDK I would just play with the bool
function GetVehiclePrice(player)
{
local Price;
        Price = ReadIniInteger("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");
if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}

return 0;
}

you could attempt to read it as a string first the change the value to be an integer.

local convert = ReadIniString("vdb.ini", "Vehicle" + player.Vehicle.ID, "Price");

convert.tointeger() etc etc

just saying, Try goofing around with it

sorry just woke up and heading to work
Title: Re: returns true all the time
Post by: Xmair on Dec 11, 2016, 01:28 PM
Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.
Title: Re: returns true all the time
Post by: . on Dec 11, 2016, 01:37 PM
Quote from: Xmair on Dec 11, 2016, 01:28 PM
Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.

You sure tho?

local Price;
        Price = ReadIniInteger(...);
Title: Re: returns true all the time
Post by: Mötley on Dec 11, 2016, 01:57 PM
Quote from: . on Dec 11, 2016, 01:37 PM
Quote from: Xmair on Dec 11, 2016, 01:28 PM
Quote from: Mötley on Dec 11, 2016, 01:03 PM if ( Price ) //It's true
        {
             if ( Price != null ) return Price;
}
}
I didn't really expected that from you.

You sure tho?

local Price;
        Price = ReadIniInteger(...);

Now both of you have me questioning this, This worked for me in the past as the file read something so it returned true instead, Then checking if that value is not null "Doesn't exist, an error whatever", It returns zero instead blah blah..

I will await for Kewuns Answer I suppose

Kewun, Could you add

print("The returned value: " + Price)
Title: Re: returns true all the time
Post by: Kewun on Dec 11, 2016, 02:08 PM
yes  it worked thanks @Motley
Title: Re: returns true all the time
Post by: KAKAN on Dec 11, 2016, 02:32 PM
Quote from: JiN_KaZaMa on Dec 11, 2016, 02:08 PMyes  it worked thanks @Motley

ROFL, this is the first time I'm seeing something like this lol
Title: Re: returns true all the time
Post by: Mötley on Dec 11, 2016, 09:25 PM
There are many reasons as to why this is correct. Do I need to elaborate just a little?
Title: Re: returns true all the time
Post by: KAKAN on Dec 12, 2016, 05:45 AM
Quote from: Mötley on Dec 11, 2016, 09:25 PMThere are many reasons as to why this is correct. Do I need to elaborate just a little?
No, you don't. Actually, when you use ReadIniInteger, you must expect a integer. If the file doesn't exist, it should throw an error instead of returning true or false. This will make all the newbies confused...( though no one uses the original INI plugin these days... )
Title: Re: returns true all the time
Post by: Kewun on Dec 12, 2016, 02:35 PM
stop spam