ChangeCol cmd Fix

Started by InFIdeL, Nov 05, 2020, 02:06 PM

Previous topic - Next topic

InFIdeL

When I try to type like like this "/changecol", an error message occurres from scripts "/changecol <car id> <col1> <col2>", but if I try like this "/changecol 132 \or any id else" ,The server gives no response ,no message comes out like /changecol <id> <col> <col>

here is the command code:


 if (cmd=="changecol")
{
if( !text ) MessagePlayer("[#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !player.IsSpawned ) MessagePlayer("[#E0E0E0]You must be spawn first", player );
else {
local TextSplit = split( text, " " ),VehicleID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ];
if ( !IsNum(VehicleID)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !IsNum(ColID1)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !IsNum(ColID2)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !FindVehicle(VehicleID.tointeger())) MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player);
else {
local v=FindVehicle(VehicleID.tointeger())
v.Colour1=ColID1.tointeger();
v.Colour2=ColID2.tointeger();
QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+ColID1+"' WHERE ID='"+VehicleID+"'");
QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+ColID2+"' WHERE ID='"+VehicleID+"'");
Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
     }
     }
}
I'm Kai

MEGAMIND

/changecol <car id> <col1> <col2>Means
/changecol -> is a cmd
<car id> -> vehicle id
<col1> -> color 1
<col2> -> color 2

so it goes like this

/changecol 191 1 5

InFIdeL

Quote from: MEGAMIND on Nov 05, 2020, 02:28 PM/changecol <car id> <col1> <col2>Means
/changecol -> is a cmd
<car id> -> vehicle id
<col1> -> color 1
<col2> -> color 2

so it goes like this

/changecol 191 1 5

No,I my mean is that when i type the cmd like /changecol.and left the other text empty,it show the error message but if i type one text (i mean /changecol 191 )and left the third empty it dont show error message.help!
I'm Kai

Inferno

if (cmd=="changecol")
{
if( !text ) MessagePlayer("[#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !player.IsSpawned ) MessagePlayer("[#E0E0E0]You must be spawn first", player );
else {
local TextSplit = split( text, " " ),VehicleID=TextSplit[ 0 ],ColID1=TextSplit[ 1 ],ColID2=TextSplit[ 2 ];
if ( !IsNum(VehicleID)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !IsNum(ColID1)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !IsNum(ColID2)) MessagePlayer("[#95fcff]WARN > [#E0E0E0]Code /"+cmd+" <Veh/ID> <Col1/ID> <Col2/ID>", player);
else if ( !FindVehicle(VehicleID.tointeger())) MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); else if(!ColID1) return MessagePlayer(" Write Colour Id ",player); else if(!ColID2) return MessagePlayer(" Write Colour ID ",player);
else {
local v=FindVehicle(VehicleID.tointeger())
v.Colour1=ColID1.tointeger();
v.Colour2=ColID2.tointeger();
QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+ColID1+"' WHERE ID='"+VehicleID+"'");
QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+ColID2+"' WHERE ID='"+VehicleID+"'");
Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
     }
     }

Return 0;

}
Viva la VU
VFS Developer
VCCNR Administrator

Sonmez

You can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}
if (!perfect) createAgain();

Inferno

Quote from: Sonmez on Nov 16, 2020, 02:04 PMYou can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}


It will still throw the same console error when cmd is typed as /cmd carID and not whole cmd.
And it wont show ingame syntax for half cmd.

Also you can use :

if(!IsNum(ColID1)) return MessagePlayer(" Colour ID must be integer ",player); Instead of
if(!IsNum(ColID1)) {
MessagePlayer(" Write Integer ",player);
return false;
}

Viva la VU
VFS Developer
VCCNR Administrator

Sonmez

Quote from: Inferno on Nov 16, 2020, 02:16 PM
Quote from: Sonmez on Nov 16, 2020, 02:04 PMYou can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}


It will still throw the same console error when cmd is typed as /cmd carID and not whole cmd.
And it wont show ingame syntax for half cmd.

Also you can use :

if(!IsNum(ColID1)) return MessagePlayer(" Colour ID must be integer ",player); Instead of
if(!IsNum(ColID1)) {
MessagePlayer(" Write Integer ",player);
return false;
}



This line already solves the problem mentioned:
if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}

if (!perfect) createAgain();

InFIdeL

Quote from: Sonmez on Nov 16, 2020, 02:48 PM
Quote from: Inferno on Nov 16, 2020, 02:16 PM
Quote from: Sonmez on Nov 16, 2020, 02:04 PMYou can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}


It will still throw the same console error when cmd is typed as /cmd carID and not whole cmd.
And it wont show ingame syntax for half cmd.

Also you can use :

if(!IsNum(ColID1)) return MessagePlayer(" Colour ID must be integer ",player); Instead of
if(!IsNum(ColID1)) {
MessagePlayer(" Write Integer ",player);
return false;
}



This line already solves the problem mentioned:
if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}

Im I oly need to add the "Return"?
I'm Kai

Sonmez

Quote from: kalee_khan on Nov 17, 2020, 01:19 PM
Quote from: Sonmez on Nov 16, 2020, 02:48 PM
Quote from: Inferno on Nov 16, 2020, 02:16 PM
Quote from: Sonmez on Nov 16, 2020, 02:04 PMYou can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}


It will still throw the same console error when cmd is typed as /cmd carID and not whole cmd.
And it wont show ingame syntax for half cmd.

Also you can use :

if(!IsNum(ColID1)) return MessagePlayer(" Colour ID must be integer ",player); Instead of
if(!IsNum(ColID1)) {
MessagePlayer(" Write Integer ",player);
return false;
}



This line already solves the problem mentioned:
if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}

Im I oly need to add the "Return"?

Just try this:
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}
if (!perfect) createAgain();

InFIdeL

Quote from: Sonmez on Nov 18, 2020, 11:48 AM
Quote from: kalee_khan on Nov 17, 2020, 01:19 PM
Quote from: Sonmez on Nov 16, 2020, 02:48 PM
Quote from: Inferno on Nov 16, 2020, 02:16 PM
Quote from: Sonmez on Nov 16, 2020, 02:04 PMYou can use this.
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}


It will still throw the same console error when cmd is typed as /cmd carID and not whole cmd.
And it wont show ingame syntax for half cmd.

Also you can use :

if(!IsNum(ColID1)) return MessagePlayer(" Colour ID must be integer ",player); Instead of
if(!IsNum(ColID1)) {
MessagePlayer(" Write Integer ",player);
return false;
}



This line already solves the problem mentioned:
if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}

Im I oly need to add the "Return"?

Just try this:
if (cmd=="changecol")
{
    if( !text ){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    if (!GetTok( text, " ", 1 )||!GetTok( text, " ", 2 )||!GetTok( text, " ", 3 )||GetTok( text, " ", 4 )){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
     if (!IsNum(GetTok( text, " ", 1 ))||!IsNum(GetTok( text, " ", 2 ))||!IsNum(GetTok( text, " ", 3 ))){MessagePlayer("/changecol <Veh/ID> <Col1/ID> <Col2/ID>",player); return false;}
    local vehicle = FindVehicle(GetTok( text, " ", 1 ).tointeger())
    if (!vehicle){MessagePlayer("[#95fcff]WARN >[#E0E0E0]Wrong Vehicle ID",player); return false;}
    local col1 = GetTok( text, " ", 2 ).tointeger();
    local col2 = GetTok( text, " ", 3 ).tointeger();
    QuerySQL( Vehicles,"UPDATE Creation SET Col1='"+col1+"' WHERE ID='"+vehicle.ID+"'");
    QuerySQL( Vehicles,"UPDATE Creation SET Col2='"+col2+"' WHERE ID='"+vehicle.ID+"'");
    Message("[#990000]#[#E0E0E0]SERVER[#990000]# [#E0E0E0]ADMIN ["+player.Name+"] changed the car color, ID: "+VehicleID+" Color-1: "+ColID1+" Color-2: "+ColID2);
}

An error has Occured the index GetTock Does'nt exist.
I'm Kai

Sonmez


QuoteAn error has Occured the index GetTock Does'nt exist.

Add this functions.

function GetTok(string, separator, n, ...)
{
    local m = vargv.len() > 0 ? vargv[0] : n,
    tokenized = split(string, separator),
    text = "";
    if (n > tokenized.len() || n < 1) return null;
    for (; n <= m; n++)
    {
        text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
    }
    return text;
}

function NumTok( string, separator )
{
    local tokenized = split(string, separator);
    return tokenized.len();
}
if (!perfect) createAgain();

Altay

Quote from: Sonmez on Nov 26, 2020, 10:06 AM
QuoteAn error has Occured the index GetTock Does'nt exist.

Add this functions.

function GetTok(string, separator, n, ...)
{
    local m = vargv.len() > 0 ? vargv[0] : n,
    tokenized = split(string, separator),
    text = "";
    if (n > tokenized.len() || n < 1) return null;
    for (; n <= m; n++)
    {
        text += text == "" ? tokenized[n-1] : separator + tokenized[n-1];
    }
    return text;
}

function NumTok( string, separator )
{
    local tokenized = split(string, separator);
    return tokenized.len();
}

Yeah, these functions should be included in every script file.
Mustafa Kemal ATATURK, the man who changed the course of history. https://en.wikipedia.org/wiki/Mustafa_Kemal_Atat%C3%BCrk