SA-MP Forums Archive
string enum printing problem - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: string enum printing problem (/showthread.php?tid=605948)



string enum printing problem - TheSimpleGuy - 27.04.2016

Whenever I print an enum string variable, it does only show the first letter of the string.
This is my code.
Код:
	new rand = random(sizeof(mLocations[]));
	pInfo[playerid][LocIDName1] = mLocations[rand][Name];
    rand = random(sizeof(mLocations[]));
	pInfo[playerid][LocIDName2] = mLocations[rand][Name];
	format(string, sizeof(string), ""COL_YELLOW"WORK:"COL_WHITE" Deliver supplies from "COL_YELLOW"%s"COL_WHITE" to "COL_YELLOW"%s"COL_WHITE".",pInfo[playerid][LocIDName1],pInfo[playerid][LocIDName2]);
	SendClientMessage(playerid, -1, string);
	SendClientMessage(playerid, -1, ""COL_YELLOW"WORK:"COL_WHITE" You can always stop work using /stopwork.");



Re: string enum printing problem - SyS - 27.04.2016

how you declared variable string ?? show its size


Re: string enum printing problem - TheSimpleGuy - 27.04.2016

Код:
enum PlayerVariables
{
	LocIDName1[128],
	LocIDName2[128]
};
new pInfo[MAX_PLAYERS][PlayerVariables];
Код:
enum MissionLocations
{
	Name[128],
	Float:X,
	Float:Y,
	Float:Z
};
new mLocations[][MissionLocations] =
{
	{"LS Construction Site", 1859.0, -1314.0, 14.0},
   	{"SF Construction Site", -2083.0, 209.0, 35.5},
	{"LV Construction Site", 2708.0, 878.0, 10.0}
};



Re: string enum printing problem - biker122 - 27.04.2016

Show us the full code, not just a part of it. Tell us the size of "string", and pInfo[playerid][LocIDName1] and pInnfo[playerid][LocIDName2].

EDIT: Late post, but anyway - WHAT's the size of "string" variable?


Re: string enum printing problem - TheSimpleGuy - 27.04.2016

Код:
CMD:work(playerid, params[])
{
	new vid = GetPlayerVehicleID(playerid), string[128];
	if(pInfo[playerid][InWork] == true) return SendClientMessage(playerid, -1, ""COL_GRAY"You are still in the middle of a work!:");
	//if(GetVehicleModel(vid) != 403 || GetVehicleModel(vid) != 515 || GetVehicleModel(vid) != 514) return SendClientMessage(playerid, -1, ""COL_GRAY"You must be in a truck to start working!");
	if(!IsTrailerAttachedToVehicle(vid)) return SendClientMessage(playerid, -1, ""COL_GRAY"You need to have a trailer attached to your vehicle to start working!");
	new rand = random(sizeof(mLocations[]));
	format(pInfo[playerid][LocIDName1], sizeof(pInfo[playerid][LocIDName1]), "%s", mLocations[rand][Name]);
    pInfo[playerid][X1] = mLocations[rand][X];
    pInfo[playerid][Y1] = mLocations[rand][Y];
    pInfo[playerid][Z1] = mLocations[rand][Z];
    rand = random(sizeof(mLocations[]));
	format(pInfo[playerid][LocIDName2], sizeof(pInfo[playerid][LocIDName2]), "%s", mLocations[rand][Name]);
    pInfo[playerid][X2] = mLocations[rand][X];
    pInfo[playerid][Y2] = mLocations[rand][Y];
    pInfo[playerid][Z2] = mLocations[rand][Z];
	format(string, sizeof(string), ""COL_YELLOW"WORK:"COL_WHITE" Deliver supplies from "COL_YELLOW"%s"COL_WHITE" to "COL_YELLOW"%s"COL_WHITE".",pInfo[playerid][LocIDName1],pInfo[playerid][LocIDName2]);
	SendClientMessage(playerid, -1, string);
	SendClientMessage(playerid, -1, ""COL_YELLOW"WORK:"COL_WHITE" You can always stop work using /stopwork.");
	SetPlayerCheckpoint(playerid, pInfo[playerid][X1], pInfo[playerid][Y1], pInfo[playerid][Z1], 7);
	pInfo[playerid][VehicleID] = vid;
	pInfo[playerid][VehicleTrailerID] = GetVehicleTrailer(vid);
	pInfo[playerid][InWork] = true;
	return 1;
}
EDIT: String size is 128.


Re: string enum printing problem - biker122 - 27.04.2016

pawn Код:
CMD:work(playerid, params[])
{
    new vid = GetPlayerVehicleID(playerid), string[512];
    if(pInfo[playerid][InWork] == true) return SendClientMessage(playerid, -1, ""COL_GRAY"You are still in the middle of a work!:");
    //if(GetVehicleModel(vid) != 403 || GetVehicleModel(vid) != 515 || GetVehicleModel(vid) != 514) return SendClientMessage(playerid, -1, ""COL_GRAY"You must be in a truck to start working!");
    if(!IsTrailerAttachedToVehicle(vid)) return SendClientMessage(playerid, -1, ""COL_GRAY"You need to have a trailer attached to your vehicle to start working!");
    new rand = random(sizeof(mLocations[]));
    format(pInfo[playerid][LocIDName1], sizeof(pInfo[playerid][LocIDName1]), "%s", mLocations[rand][Name]);
        pInfo[playerid][X1] = mLocations[rand][X];
        pInfo[playerid][Y1] = mLocations[rand][Y];
        pInfo[playerid][Z1] = mLocations[rand][Z];
        rand = random(sizeof(mLocations[]));
    format(pInfo[playerid][LocIDName2], sizeof(pInfo[playerid][LocIDName2]), "%s", mLocations[rand][Name]);
    pInfo[playerid][X2] = mLocations[rand][X];
        pInfo[playerid][Y2] = mLocations[rand][Y];
        pInfo[playerid][Z2] = mLocations[rand][Z];
    format(string, sizeof(string), ""COL_YELLOW"WORK:"COL_WHITE" Deliver supplies from "COL_YELLOW"%s"COL_WHITE" to "COL_YELLOW"%s"COL_WHITE".",pInfo[playerid][LocIDName1],pInfo[playerid][LocIDName2]);
    SendClientMessage(playerid, -1, string);
    SendClientMessage(playerid, -1, ""COL_YELLOW"WORK:"COL_WHITE" You can always stop work using /stopwork.");
    SetPlayerCheckpoint(playerid, pInfo[playerid][X1], pInfo[playerid][Y1], pInfo[playerid][Z1], 7);
    pInfo[playerid][VehicleID] = vid;
    pInfo[playerid][VehicleTrailerID] = GetVehicleTrailer(vid);
    pInfo[playerid][InWork] = true;
    return 1;
}
Just increased the string size to 512.


Re: string enum printing problem - PrO.GameR - 27.04.2016

I'm not even sure if these people that try to help know pawn at all.
problem is here

pInfo[playerid][LocIDName2] = mLocations[rand][Name];
This doesn't copy strings into eachother, just the first letter, there are strcat, memcpy and strcpy for this job.


Re: string enum printing problem - TheSimpleGuy - 27.04.2016

After increasing the size, the output is still the same.

EDIT:Oh, yes, I forgot those functions. Let me update the thread after I've done those functions.


Re: string enum printing problem - biker122 - 27.04.2016

Quote:
Originally Posted by PrO.GameR
Посмотреть сообщение
I'm not even sure if these people that try to help know pawn at all.
problem is here

pInfo[playerid][LocIDName2] = mLocations[rand][Name];
This doesn't copy strings into eachother, just the first letter, there are strcat, memcpy and strcpy for this job.
Hey brother, the post he made before I asked the full code was probably a rough one. Look at the full command code he has posted. You seem to be a blind. Don't just jump into conclusion just be seeing the last post.


Re: string enum printing problem - TheSimpleGuy - 27.04.2016

UPDATE:
strcat - outcome: Deliver supplies from to .
Код:
CMD:work(playerid, params[])
{
	new vid = GetPlayerVehicleID(playerid), string[512];
	if(pInfo[playerid][InWork] == true) return SendClientMessage(playerid, -1, ""COL_GRAY"You are still in the middle of a work!:");
	//if(GetVehicleModel(vid) != 403 || GetVehicleModel(vid) != 515 || GetVehicleModel(vid) != 514) return SendClientMessage(playerid, -1, ""COL_GRAY"You must be in a truck to start working!");
	if(!IsTrailerAttachedToVehicle(vid)) return SendClientMessage(playerid, -1, ""COL_GRAY"You need to have a trailer attached to your vehicle to start working!");
	new rand = random(sizeof(mLocations[]));
	strcat(pInfo[playerid][LocIDName1], mLocations[rand][Name]);
    pInfo[playerid][X1] = mLocations[rand][X];
    pInfo[playerid][Y1] = mLocations[rand][Y];
    pInfo[playerid][Z1] = mLocations[rand][Z];
    rand = random(sizeof(mLocations[]));
	strcat(pInfo[playerid][LocIDName2], mLocations[rand][Name]);
    pInfo[playerid][X2] = mLocations[rand][X];
    pInfo[playerid][Y2] = mLocations[rand][Y];
    pInfo[playerid][Z2] = mLocations[rand][Z];
	format(string, sizeof(string), ""COL_YELLOW"WORK:"COL_WHITE" Deliver supplies from "COL_YELLOW"%s"COL_WHITE" to "COL_YELLOW"%s"COL_WHITE".",pInfo[playerid][LocIDName1],pInfo[playerid][LocIDName2]);
	SendClientMessage(playerid, -1, string);
	SendClientMessage(playerid, -1, ""COL_YELLOW"WORK:"COL_WHITE" You can always stop work using /stopwork.");
	SetPlayerCheckpoint(playerid, pInfo[playerid][X1], pInfo[playerid][Y1], pInfo[playerid][Z1], 7);
	pInfo[playerid][VehicleID] = vid;
	pInfo[playerid][VehicleTrailerID] = GetVehicleTrailer(vid);
	pInfo[playerid][InWork] = true;
	return 1;
}
strcpy - outcome: SERVER: Unknown command.
Код:
CMD:work(playerid, params[])
{
	new vid = GetPlayerVehicleID(playerid), string[512];
	if(pInfo[playerid][InWork] == true) return SendClientMessage(playerid, -1, ""COL_GRAY"You are still in the middle of a work!:");
	//if(GetVehicleModel(vid) != 403 || GetVehicleModel(vid) != 515 || GetVehicleModel(vid) != 514) return SendClientMessage(playerid, -1, ""COL_GRAY"You must be in a truck to start working!");
	if(!IsTrailerAttachedToVehicle(vid)) return SendClientMessage(playerid, -1, ""COL_GRAY"You need to have a trailer attached to your vehicle to start working!");
	new rand = random(sizeof(mLocations[]));
	strcpy(pInfo[playerid][LocIDName1], mLocations[rand][Name]);
    pInfo[playerid][X1] = mLocations[rand][X];
    pInfo[playerid][Y1] = mLocations[rand][Y];
    pInfo[playerid][Z1] = mLocations[rand][Z];
    rand = random(sizeof(mLocations[]));
	strcpy(pInfo[playerid][LocIDName2], mLocations[rand][Name]);
    pInfo[playerid][X2] = mLocations[rand][X];
    pInfo[playerid][Y2] = mLocations[rand][Y];
    pInfo[playerid][Z2] = mLocations[rand][Z];
	format(string, sizeof(string), ""COL_YELLOW"WORK:"COL_WHITE" Deliver supplies from "COL_YELLOW"%s"COL_WHITE" to "COL_YELLOW"%s"COL_WHITE".",pInfo[playerid][LocIDName1],pInfo[playerid][LocIDName2]);
	SendClientMessage(playerid, -1, string);
	SendClientMessage(playerid, -1, ""COL_YELLOW"WORK:"COL_WHITE" You can always stop work using /stopwork.");
	SetPlayerCheckpoint(playerid, pInfo[playerid][X1], pInfo[playerid][Y1], pInfo[playerid][Z1], 7);
	pInfo[playerid][VehicleID] = vid;
	pInfo[playerid][VehicleTrailerID] = GetVehicleTrailer(vid);
	pInfo[playerid][InWork] = true;
	return 1;
}