31.12.2009, 13:52
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?
thanks
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;
}