PDA

View Full Version : Faction ID problem


TwinkiDaBoss
05/01/2016, 05:40 PM
Alright so the problem is simple.

It displays & reads from Type based on your own faction ID

For example my faction ID

new xx = AccInfo[playerid][PlayerFaction];
printf("Faction type: %i",FactionInfo[xx][FactionType]);
printf("Faction ID: %i",FactionInfo[xx][FactionID]);

/* test 2 with GetPlayerFactionID */
printf("Faction 2 ID: %i",GetPlayerFactionID(playerid));
printf("Faction 2 Type: %i",FactionInfo[GetPlayerFactionID(playerid)][FactionType]);


Now If I set my own faction ID to 2 it will and I pritn out this will happen

[19:38:00] Faction type: 3
[19:38:00] Faction ID: 3


[19:38:00] Faction 2 ID: 2
[19:38:00] Faction 2 Type: 3

Altho OnFactionLoad works properly

[19:35:48] Faction ID: 1 || Faction Type: 1
[19:35:48] Faction ID: 2 || Faction Type: 2
[19:35:48] Faction ID: 3 || Faction Type: 3


Get player faction
GetPlayerFactionID(playerid) return AccInfo[playerid][PlayerFaction];


EDIT: Problem is basicaly, with GetPlayerFactionID it reads the correct faction ID but shows Faction ID:3 type.

Jefff
05/01/2016, 05:46 PM
FactionInfo[GetPlayerFactionID(playerid)][FactionID] xd

TwinkiDaBoss
05/01/2016, 05:53 PM
FactionInfo[GetPlayerFactionID(playerid)][FactionID] xd

Doesnt help mate :(

I tried using this too
GetPlayerFactionID(playerid) return FactionInfo[AccInfo[playerid][PlayerFaction]][FactionID];

But with that it displays faction ID: 3 and faction type 0 ...

public OnFactionLoad() {
new rows, fields;
cache_get_data(rows, fields, mysql);
if(rows) {
for(new i = 0; i < rows && i < MAX_FACTIONS; i++) {
new string[512];

cache_get_field_content(i, "Name", string);
strreplace(string, '_', ' ');
format(FactionInfo[i][FactionName], sizeof(string), string);
FactionInfo[i][FactionID] = cache_get_field_content_int(i,"ID");
FactionInfo[i][FactionEnterX] = cache_get_field_content_float(i,"EnterX");
FactionInfo[i][FactionEnterY] = cache_get_field_content_float(i,"EnterY");
FactionInfo[i][FactionEnterZ] = cache_get_field_content_float(i,"EnterZ");
FactionInfo[i][FactionExitX] = cache_get_field_content_float(i,"ExitX");
FactionInfo[i][FactionExitY] = cache_get_field_content_float(i,"ExitY");
FactionInfo[i][FactionExitZ] = cache_get_field_content_float(i,"ExitZ");
FactionInfo[i][FactionWorld] = cache_get_field_content_int(i,"World");
FactionInfo[i][FactionInterior] = cache_get_field_content_int(i,"Interior");
FactionInfo[i][FactionBank] = cache_get_field_content_int(i,"FactionBank");
FactionInfo[i][FactionDeagleAmmo] = cache_get_field_content_int(i,"DeagleAmmo");
FactionInfo[i][FactionM4Ammo] = cache_get_field_content_int(i,"M4Ammo");
FactionInfo[i][FactionShotgunAmmo] = cache_get_field_content_int(i,"ShotgunAmmo");
FactionInfo[i][FactionSniperAmmo] = cache_get_field_content_int(i,"SniperAmmo");
FactionInfo[i][FactionSmuggledCocaine] = cache_get_field_content_int(i,"CocaineSmuggledWhen");
FactionInfo[i][FactionType] = cache_get_field_content_int(i,"Type");
FactionInfo[i][FactionCocaineAmount] = cache_get_field_content_int(i,"CocaAmount");
FactionInfo[i][FactionPickup] = CreateDynamicPickup(1275, 1, cache_get_field_content_float(i,"EnterX"),cache_get_field_content_float(i,"EnterY"),cache_get_field_content_float(i,"EnterZ"));
format(string,sizeof(string),"Faction Name: %s\nFaction ID:%i",FactionInfo[i][FactionName],FactionInfo[i][FactionID]);
FactionInfo[i][FactionText] = CreateDynamic3DTextLabel(string, 0x008080FF, FactionInfo[i][FactionEnterX],FactionInfo[i][FactionEnterY],FactionInfo[i][FactionEnterZ], 5.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0);
printf("Faction ID: %i || Faction Type: %i",FactionInfo[i][FactionID],FactionInfo[i][FactionType]);
}
}
return true;
}

justinnater
05/01/2016, 06:16 PM
What should the type be from faction id 2?

How much is MAX_FACTIONS defined as?

TwinkiDaBoss
05/01/2016, 06:37 PM
What should the type be from faction id 2?

How much is MAX_FACTIONS defined as?

Faction ID 2 type should be 2

#define MAX_FACTIONS 10

justinnater
05/01/2016, 06:44 PM
Are you 100% percent sure? Check the table just incase.

Could you show me how you set someone in a faction?

Could you please show the current function to get a player's faction

TwinkiDaBoss
05/01/2016, 08:08 PM
Are you 100% percent sure? Check the table just incase.

Could you show me how you set someone in a faction?

Could you please show the current function to get a player's faction

1. Yeah 100% sure, even checked the table to see if its Int lmfao

2. GetPlayerFactionID
GetPlayerFactionID(playerid) return AccInfo[playerid][PlayerFaction];

3. Setting player faction is good, it even loads the correct faction ID.
Under OnPlayerLogin
printf("Player faction: %i",AccInfo[playerid][PlayerFaction]);
It displays the correct FactionID as its set in the SQL

justinnater
05/01/2016, 08:16 PM
Can you provide us a image of your table?

TwinkiDaBoss
05/01/2016, 08:20 PM
Dont mind the non alligment, I had to crop pictures & put them together since the table is quite big
http://imgur.com/SrDz4Ui

Also if this makes any sense


CREATE TABLE `factions` (
`ID` INT(10) NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(128) NULL DEFAULT '0',
`EnterX` FLOAT NULL DEFAULT '0',
`EnterY` FLOAT NULL DEFAULT '0',
`EnterZ` FLOAT NULL DEFAULT '0',
`ExitX` FLOAT NULL DEFAULT '0',
`ExitY` FLOAT NULL DEFAULT '0',
`ExitZ` FLOAT NULL DEFAULT '0',
`Interior` INT(10) NULL DEFAULT '0',
`World` INT(10) NULL DEFAULT '0',
`Rank1` VARCHAR(24) NULL DEFAULT '0',
`Rank2` VARCHAR(24) NULL DEFAULT '0',
`Rank3` VARCHAR(24) NULL DEFAULT '0',
`Rank4` VARCHAR(24) NULL DEFAULT '0',
`Rank5` VARCHAR(24) NULL DEFAULT '0',
`Rank6` VARCHAR(24) NULL DEFAULT '0',
`Rank7` VARCHAR(24) NULL DEFAULT '0',
`Rank8` VARCHAR(24) NULL DEFAULT '0',
`Rank9` VARCHAR(24) NULL DEFAULT '0',
`Rank10` VARCHAR(24) NULL DEFAULT '0',
`FactionBank` INT(10) NULL DEFAULT '0',
`DeagleAmmo` INT(10) NULL DEFAULT '0',
`M4Ammo` INT(10) NULL DEFAULT '0',
`ShotgunAmmo` INT(10) NULL DEFAULT '0',
`SniperAmmo` INT(10) NULL DEFAULT '0',
`CocaineSmuggledWhen` INT(15) NULL DEFAULT '0',
`Type` INT(2) NULL DEFAULT '0',
`CocaAmount` INT(10) NULL DEFAULT '0',
PRIMARY KEY (`ID`)
)
COLLATE='latin1_swedish_ci'
ENGINE=InnoDB
;

justinnater
05/01/2016, 08:25 PM
is it only wrong for faction id 2 or also others?

TwinkiDaBoss
05/01/2016, 08:30 PM
is it only wrong for faction id 2 or also others?

lets say you are part of faction ID: 2 and that is Type 2 (example)

When you type /check it will print out

"ID: 3
Type: 1 //Because 1 is type of ID: 3"

Basically it will tell you info about faction ID:3 instead of 2.

justinnater
05/01/2016, 08:34 PM
So if you are in faction 1 it will show faction id 2 along with the type from faction 2?

TwinkiDaBoss
05/01/2016, 08:35 PM
So if you are in faction 1 it will show faction id 2 along with the type from faction 2?

Correct! It will always add up to your current faction.

Player A Faction 1, it will show them faction 2 informations & Type

justinnater
05/01/2016, 08:37 PM
Just going to throw some guesses alright...

Maybe becouse faction `ID` 0 does not exists?
Try adding faction 0 or changing the current ids one lower and check the results.

TwinkiDaBoss
05/01/2016, 08:48 PM
Just going to throw some guesses alright...

Maybe becouse faction `ID` 0 does not exists?
Try adding faction 0 or changing the current ids one lower and check the results.

Doesnt really help to be honest, even adding ID: 0 doesnt

This is how I insert them tho

mysql_format(mysql, query, sizeof(query),"INSERT INTO `factions` (`Name`,`EnterX`,`EnterY`,`EnterZ`,`ExitX`,`ExitY` ,`ExitZ`,`Interior`,`World`,`Type`) VALUES ('%s','%f','%f','%f','%f','%f','%f','%i','%i','%i' )",\
fName,myPos[0],myPos[1],myPos[2],ePos[0],ePos[1],ePos[2],intx,world,fType);
mysql_tquery(mysql, query, "OnFactionCreation", "i", "");

public OnFactionCreation() {
FactionInfo[factionid][FactionID] = cache_insert_id(mysql);
return 1;
}

forward OnFactionCreation();

justinnater
05/01/2016, 08:57 PM
Can you show me the loop you use for the "OnFactionCreation", "i"

Jefff
05/01/2016, 08:58 PM
In OnPlayerLogin you must change to AccInfo[playerid][PlayerFaction] = factionid - 1; because your loop in loading factions starts from 0 not 1

justinnater
05/01/2016, 09:00 PM
In OnPlayerLogin you must change to AccInfo[playerid][PlayerFaction] = factionid - 1; because your loop in loading factions starts from 0 not 1

If this works its becouse the first row it retrieves in the loop is 0 but the first faction starts from 1 right?
Adding the faction 0 would than have fixed this problem as I suggested, which it did not... Kinda clueless

TwinkiDaBoss
05/01/2016, 09:17 PM
Yeah adding faction ID: 0 seems to work, thanks mate! +rep to all