CarOwner var problem;
#1

Hello guys, I did a system for my server, but he presents a problem...
Firstly I want to say sorry for my english, because I'm brazilian...
Okay, so let's start.

All the command works perfectly, but the player's name, instead of appearing in charge, appears only (....)

Command Code:
PHP код:
CMD:searchplate(playeridparams[])
{
    static
        
id 0;
    if (
GetFactionType(playerid) != FACTION_POLICE)
        return 
SendErrorMessage(playerid"You needs be a cop.");
    if (
sscanf(params"d"id))
        return 
SendSyntaxMessage(playerid"/serachplate [vehicleid]");
    if (!
IsValidVehicle(id) || Car_GetID(id) == -1)
        return 
SendErrorMessage(playerid"You specified an invalid ID.");
    
Dialog_Show(playeridInfoCarroDIALOG_STYLE_MSGBOX"LOS SANTOS POLICE DEPARTMENT""This vehicle is owned by %s. Thank you for making the query.\n\nLOS SANTOS POLICE DEPARTMENT""Ok"""CarData[id][carOwner]);
    return 
1;

CarData Enum:
PHP код:
enum carData {
    
carID,
    
carExists,
    
carModel,
    
carOwner,
    
Float:carPos[4],
    
carColor1,
    
carColor2,
    
carPaintjob,
    
carLocked,
    
carMods[14],
    
carImpounded,
    
carImpoundPrice,
    
carFaction,
    
carWeapons[5],
    
carAmmo[5],
    
carVehicle
}; 
Reply
#2

You need to format the string before placing it in the dialog, like so:
Код:
CMD:searchplate(playerid, params[]) 
{ 
    static 
        id = 0; 

    if (GetFactionType(playerid) != FACTION_POLICE) 
        return SendErrorMessage(playerid, "You needs be a cop."); 

    if (sscanf(params, "d", id)) 
        return SendSyntaxMessage(playerid, "/serachplate [vehicleid]"); 

    if (!IsValidVehicle(id) || Car_GetID(id) == -1) 
        return SendErrorMessage(playerid, "You specified an invalid ID."); 
	new szString[128];
	format(szString, sizeof(szString), "This vehicle is owned by %s. Thank you for making the query.\n\nLOS SANTOS POLICE DEPARTMENT", CarData[id][carOwner]);
    Dialog_Show(playerid, InfoCarro, DIALOG_STYLE_MSGBOX, "LOS SANTOS POLICE DEPARTMENT", szString, "Ok", ""); 
    return 1; 
}
Changes:
Код:
new szString[128]; // To store our string for later user in the dialog.
format(szString, sizeof(szString), "This vehicle is owned by %s. Thank you for making the query.\n\nLOS SANTOS POLICE DEPARTMENT", CarData[id][carOwner]); // Format the string here inserting our carOwner variable.
Dialog_Show(playerid, InfoCarro, DIALOG_STYLE_MSGBOX, "LOS SANTOS POLICE DEPARTMENT", szString, "Ok", ""); // Show the dialog using our string created above.
Also based on the enum you provided it doesn't seem like CarData[id][carOwner] stores the owner's name but instead their id, the method I have shown above is for inserting a string value, not an integer.
Reply
#3

You can give me the complete command? I tried to resolve, but doesn't work
Reply
#4

your current carowner var is integer not string, if you wanna story player name in it you have to define it as string:
PHP код:
enum carData 
    
carID
    
carExists
    
carModel
    
carOwner[MAX_PLAYER_NAME], 
    
Float:carPos[4], 
    
carColor1
    
carColor2
    
carPaintjob
    
carLocked
    
carMods[14], 
    
carImpounded
    
carImpoundPrice
    
carFaction
    
carWeapons[5], 
    
carAmmo[5], 
    
carVehicle 
}; 
also if you want it to show vehicle owner as null you can reset all on gamemodeinit
PHP код:
public OnGameModeInit()
{
    for(new 
iMAX_VEHICLESi++) CarData[i][carOwner] = "Null";

Reply
#5

It continues with the same error, even after I set the variable to MAX_PLAYER_NAME.
Prints:

http://imgur.com/a/a0O6Z
Reply
#6

Код:
try it this way, 

new carOwner - replace it at your enum or whatever is it.
remve max_player_name
after that go to place where you set the car owner and do
Код:
put this anywhere on script
stock myStrcpy(dest[], src[])
{
    new i = 0;
    while ((dest[i] = src[i])) i++;
}

and use it as

myStrcpy(carOwner, PlayerName(playerid) // players name howerver u define);
after that you can just use as
carOwner when u get the owner from that thing
Reply
#7

Quote:
Originally Posted by ThatFag
Посмотреть сообщение
Код:
try it this way, 

new carOwner - replace it at your enum or whatever is it.
remve max_player_name
after that go to place where you set the car owner and do
Код:
put this anywhere on script
stock myStrcpy(dest[], src[])
{
    new i = 0;
    while ((dest[i] = src[i])) i++;
}

and use it as

myStrcpy(carOwner, PlayerName(playerid) // players name howerver u define);
after that you can just use as
carOwner when u get the owner from that thing
I use the carOwner in others lines.
It's giving warnings on pawn compiler.
Doesn't working.
Reply
#8

Does CarData[id][carOwner] store the car owner's in-game playerid or their database/file ID?
Reply
#9

This ill help? ;-;

Quote:

forward Car_Load();
public Car_Load()
{
static
rows,
fields,
str[128];

cache_get_data(rows, fields, g_iHandle);

for (new i = 0; i < rows; i ++) if (i < MAX_DYNAMIC_CARS)
{
CarData[i][carExists] = true;
CarData[i][carID] = cache_get_field_int(i, "carID");
CarData[i][carModel] = cache_get_field_int(i, "carModel");
CarData[i][carOwner] = cache_get_field_int(i, "carOwner");
CarData[i][carPos][0] = cache_get_field_float(i, "carPosX");
CarData[i][carPos][1] = cache_get_field_float(i, "carPosY");
CarData[i][carPos][2] = cache_get_field_float(i, "carPosZ");
CarData[i][carPos][3] = cache_get_field_float(i, "carPosR");
CarData[i][carColor1] = cache_get_field_int(i, "carColor1");
CarData[i][carColor2] = cache_get_field_int(i, "carColor2");
CarData[i][carPaintjob] = cache_get_field_int(i, "carPaintjob");
CarData[i][carLocked] = cache_get_field_int(i, "carLocked");
CarData[i][carImpounded] = cache_get_field_int(i, "carImpounded");
CarData[i][carImpoundPrice] = cache_get_field_int(i, "carImpoundPrice");
CarData[i][carFaction] = cache_get_field_int(i, "carFaction");

for (new j = 0; j < 14; j ++)
{
if (j < 5)
{
format(str, sizeof(str), "carWeapon%d", j + 1);
CarData[i][carWeapons][j] = cache_get_field_int(i, str);

format(str, sizeof(str), "carAmmo%d", j + 1);
CarData[i][carAmmo][j] = cache_get_field_int(i, str);
}
format(str, sizeof(str), "carMod%d", j + 1);
CarData[i][carMods][j] = cache_get_field_int(i, str);
}
Car_Spawn(i);
}
for (new i = 0; i < MAX_DYNAMIC_CARS; i ++) if (CarData[i][carExists]) {
format(str, sizeof(str), "SELECT * FROM `carstorage` WHERE `ID` = '%d'", CarData[i][carID]);

mysql_tquery(g_iHandle, str, "OnLoadCarStorage", "d", i);
}
return 1;
}

Reply
#10

Are you using MySQL?

If yes, then store the player's SQL id and put it in the vehicle variable, then get the name by using the following SQL id from the table.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)