Wrong coords
#1

Hey guys i have a cmd that will add a faction spawn where i am but it give's wrong coords like the Z is +0.5 instead of beeing right where i am.

PIC: http://imgur.com/a/dgu71

HTML Code:
CMD:addfac(playerid, params[])
{
	new fac[40], var100[60];
	if(!IsManager(playerid)) return SCM(playerid, COLOR_ERROR, "Nu ai gradul necesar ca sa folosesti aceasta comanda!");
    if(sscanf(params,"s[40]", fac)) return SCM(playerid, COLOR_SYN, "Sintaxa:{FFFFFF} /addfac [Nume Factiune]");
	{
	    new Float:POSX, Float:POSY, Float:POSZ;
		GetPlayerPos(playerid, POSX, POSY, POSZ);
		
       	gQuery[0] = (EOS);
     	mysql_format(handle, gQuery, sizeof(gQuery), "INSERT INTO `factions` (`Name`,`ExitX`,`ExitY`,`ExitZ`,`Slots`,`MinLevel`,`Application`,`News`) VALUES ('%s','%f','%f','%f','10','5','0','Bun venit in %s')", fac, POSX, POSY, POSZ, fac);
     	mysql_query(handle, gQuery);
     	
     	format(var100, sizeof(var100), "Ai adaugat factiunea [%s].", fac);
     	SCM(playerid, COLOR_WHITE, var100);
     	
     	defer EditFaction(playerid);
 	}
	return 1;
}
When i load the factions they read the coords from structure where factions are so i didn't add +0.5 or else to the load.
Reply
#2

Nothing in this code creates the pickup, so the next thing to look at EditFaction if that updates the location of the pickup/3dtext/etc.
Reply
#3

Quote:
Originally Posted by Sew_Sumi
View Post
Nothing in this code creates the pickup, so the next thing to look at EditFaction if that updates the location of the pickup/3dtext/etc.
this is under EditFaction

HTML Code:
gQuery[0] = (EOS);
	mysql_format(handle, gQuery, sizeof(gQuery), "SELECT * FROM `factions`");
	mysql_tquery(handle, gQuery, "LoadFactions", "");
And reload the factions

HTML Code:
function LoadFactions()
{
	factionss = cache_num_rows();
	new string[64], tmp[128], id;
	for(new i = 0; i < factionss; i++)
	{
		cache_get_field_content(i, "ID", tmp);			id = strval(tmp);
		cache_get_field_content(i, "ID", tmp);			FactionInfo[id][fID] = strval(tmp);
		cache_get_field_content(i, "Name", tmp);		strmid(FactionInfo[id][fName], tmp, false, strlen(tmp), 32);
		cache_get_field_content(i, "SpawnX", tmp);		FactionInfo[id][fSpawnX] = strval(tmp);
		cache_get_field_content(i, "SpawnY", tmp);		FactionInfo[id][fSpawnY] = strval(tmp);
		cache_get_field_content(i, "SpawnZ", tmp);		FactionInfo[id][fSpawnZ] = strval(tmp);
		cache_get_field_content(i, "ExitX", tmp);		FactionInfo[id][fExitX] = strval(tmp);
		cache_get_field_content(i, "ExitY", tmp);		FactionInfo[id][fExitY] = strval(tmp);
		cache_get_field_content(i, "ExitZ", tmp);		FactionInfo[id][fExitZ] = strval(tmp);
		cache_get_field_content(i, "Interior", tmp);	FactionInfo[id][fInterior] = strval(tmp);
		cache_get_field_content(i, "VirtualW", tmp);	FactionInfo[id][fVirtualW] = strval(tmp);
		cache_get_field_content(i, "MinLevel", tmp);	FactionInfo[id][fMinLevel] = strval(tmp);
		cache_get_field_content(i, "Slots", tmp);		FactionInfo[id][fSlots] = strval(tmp);
		cache_get_field_content(i, "Application", tmp);	FactionInfo[id][fApplication] = strval(tmp);
		cache_get_field_content(i, "News", tmp);		strmid(FactionInfo[id][fNews], tmp, false, strlen(tmp), 128);

        FactionInfo[id][fPickupIDIesire] = CreateDynamicPickup(19132, 1, FactionInfo[id][fSpawnX], FactionInfo[id][fSpawnY], FactionInfo[id][fSpawnZ], -1, -1, -1, 30.0);
		FactionInfo[id][fPickupIDIntrare] = CreateDynamicPickup(19132, 1, FactionInfo[id][fExitX], FactionInfo[id][fExitY], FactionInfo[id][fExitZ], -1, -1, -1, 30.0);

        format(string, sizeof(string), "%s\nIesire", FactionInfo[id][fName]);
		FactionInfo[id][fLabelIDIesire] = CreateDynamic3DTextLabel(string, COLOR_WHITE, FactionInfo[id][fSpawnX], FactionInfo[id][fSpawnY], FactionInfo[id][fSpawnZ], 30, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 30.0);
		format(string, sizeof(string), "%s\nIntrare", FactionInfo[id][fName]);
		FactionInfo[id][fLabelIDIntrare] = CreateDynamic3DTextLabel(string, COLOR_WHITE, FactionInfo[id][fExitX], FactionInfo[id][fExitY], FactionInfo[id][fExitZ], 30, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, -1, -1, -1, 30.0);
	}
	printf("S-au incarcat %d factiuni.", factionss);
	return 1;
}
Reply
#4

Look closely at this snippet from your code
PHP Code:
     cache_get_field_content(i"SpawnX"tmp);    FactionInfo[id][fSpawnX] = strval(tmp);
     
cache_get_field_content(i"SpawnY"tmp);    FactionInfo[id][fSpawnY] = strval(tmp);
     
cache_get_field_content(i"SpawnZ"tmp);    FactionInfo[id][fSpawnZ] = strval(tmp);
     
cache_get_field_content(i"ExitX"tmp);        FactionInfo[id][fExitX] = strval(tmp);
     
cache_get_field_content(i"ExitY"tmp);        FactionInfo[id][fExitY] = strval(tmp);
     
cache_get_field_content(i"ExitZ"tmp);        FactionInfo[id][fExitZ] = strval(tmp); 
you are using strval function which converts strings to integers,
this is how strval works
PHP Code:
     new floatNumber[7] = "15.623";
     
printf("%f"strval(floatNumber)); 
This would print 15 not 15.623, because it's converted to an integer (the float part is removed)
more exemples
Code:
     strval("6.23")           ==> 6
     strval("96494.544")   ==> 96494
     strval("1.0")             ==> 1
following this logic, when your current position has been calculated GetPlayerPos(...), let's say the positions are
Code:
X = 1663.2345
Y = -4959.2783
Z = 3.296
when you sue strval function on them they will be integers meaning
Code:
strval(X) = 1663
strval(Y) = -4959
strval(Z) = 3
see? All the float part is removed, and when dealing with positions, the float part matters, that's why the pickup isn't created in your exact position but offset a little bit

the correct way to go around this, is to use floatstr function instead of strval, which converts strings to
floats

*A correct snippet
PHP Code:
     cache_get_field_content(i"SpawnX"tmp);    FactionInfo[id][fSpawnX] = floatstr(tmp);
     
cache_get_field_content(i"SpawnY"tmp);    FactionInfo[id][fSpawnY] = floatstr(tmp);
     
cache_get_field_content(i"SpawnZ"tmp);    FactionInfo[id][fSpawnZ] = floatstr(tmp);
     
cache_get_field_content(i"ExitX"tmp);        FactionInfo[id][fExitX] = floatstr(tmp);
     
cache_get_field_content(i"ExitY"tmp);        FactionInfo[id][fExitY] = floatstr(tmp);
     
cache_get_field_content(i"ExitZ"tmp);        FactionInfo[id][fExitZ] = floatstr(tmp); 
reference: https://sampwiki.blast.hk/wiki/Floatstr
Reply
#5

On command /addfac

Code:
mysql_query(handle, gQuery);

Replace with:

mysql_tquery(handle, qQuery, "", "");

And

FactionInfo[id][fExitY] = floatstr(tmp);

Replace with:

FactionInfo[id][fExitY] = floatstr(tmp);
etc
Reply
#6

The most efficient way of doing this is as follows:

pawn Code:
FactionInfo[id][fSpawnX] = cache_get_field_content_float(i, "SpawnX");
... ETC.
Reply
#7

Thx @Eoussama and @skuller12 both of your response helped me , ofc i saw @Eoussama first and i gived him +1 rep.

SOLVED

EDIT: u2 @CrossUSAAF that works too
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)