[Help]ModelID returning as 0
#1

Hey,

I kinda need help with this function. With dcmd_addcar the modelid is returning as 0 in the database. I've tryed all I can to get it to work. Anyone know why it returns 0 and not the mdoelid?

pawn Code:
dcmd_addcar(playerid,params[])
{
    new
        name[128];

    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0x33CCFFFF,"[VT ERROR] You're not an admin.");
    new query[256],model,col1,col2;
    if(sscanf(params,"sii",name,col1,col2)) return SendClientMessage(playerid,0x33CCFFFF,"Usage: /addcar [name] [color1] [color2]");
    else
    {
      new vehicle = GetVehicleModelIDFromName(model);
      new Float:x,Float:y,Float:z,Float:angle;
      GetPlayerPos(playerid,x,y,z);
      GetPlayerFacingAngle(playerid,angle);
      new vehid = CreateVehicle(vehicle,x,y,z,angle,col1,col2,-1);
      format(query,sizeof(query),"INSERT INTO `vehicles` (model,x,y,z,a,col1,col2) VALUES (%d,%f,%f,%f,%f,%d,%d)",model,x,y,z,angle,col1,col2);
      mysql_query(query);
      vInfo[vehid][vSQLId] = mysql_insert_id();
      vInfo[vehid][vModelId] = model;
      vInfo[vehid][vPos_X] = x;
      vInfo[vehid][vPos_Y] = y;
      vInfo[vehid][vPos_Z] = z;
      vInfo[vehid][vPos_A] = angle;
      vInfo[vehid][vColor1] = col1;
      vInfo[vehid][vColor2] = col2;
      SaveVehicle(vehid);
      SendClientMessage(playerid,0x33CCFFFF,"Vehicle added; edit it with /carprice and /cartype.");
    }
    return 1;
}
pawn Code:
public GetVehicleModelIDFromName(vname[])
{
    for(new i = 0; i < 211; i++) //Loop starting at 0 and going to 211
    {
        if(strfind(aVehicleNames[i], vname, true) != -1)
        return i + 400; // starts searching "aVehicleNames" with it's returning variable + 400 for accurate result
        //Vehicle IDs start at 400
    }
    return -1;
}
thanks
Reply
#2

Code:
new model;
This is defined as integer not a string.

And here in your function your parameter is set to be a string.

Code:
GetVehicleModelIDFromName(vname[])
It should be like this I think:

new vehicle = GetVehicleModelIDFromName(name);

format(query,sizeof(query),"INSERT INTO `vehicles` (vehicle,x,y,z,a,col1,col2)....

And you can remove that model array because you won't be using it...

And try to use zcmd it is better than dcmd.

http://forum.sa-mp.com/index.php?topic=116240.0
Reply
#3

Seems not to be returning anything in the database now:
pawn Code:
dcmd_addcar(playerid,params[])
{
    new
        name[128];

    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid,0x33CCFFFF,"[VT ERROR] You're not an admin.");
    new query[256],col1,col2;
    if(sscanf(params,"sii",name,col1,col2)) return SendClientMessage(playerid,0x33CCFFFF,"Usage: /addcar [name] [color1] [color2]");
    else
    {
    new vehicle = GetVehicleModelIDFromName(name);
      new Float:x,Float:y,Float:z,Float:angle;
        GetPlayerPos(playerid,x,y,z);
        GetPlayerFacingAngle(playerid,angle);
      new vehid = CreateVehicle(vehicle,x,y,z,angle,col1,col2,-1);
        format(query,sizeof(query),"INSERT INTO `vehicles` (vehicle,x,y,z,a,col1,col2) VALUES (%d,%f,%f,%f,%f,%d,%d)",vehicle,x,y,z,angle,col1,col2);
        mysql_query(query);
        vInfo[vehid][vSQLId] = mysql_insert_id();
      vInfo[vehid][vModelId] = vehicle;
      vInfo[vehid][vPos_X] = x;
      vInfo[vehid][vPos_Y] = y;
      vInfo[vehid][vPos_Z] = z;
      vInfo[vehid][vPos_A] = angle;
      vInfo[vehid][vColor1] = col1;
      vInfo[vehid][vColor2] = col2;
      SaveVehicle(vehid);
      SendClientMessage(playerid,0x33CCFFFF,"Vehicle added; edit it with /carprice and /cartype.");
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)