[Help Needed] Class Selection
#1

Hey Guys,

I used a part of a other gamemode "grandlarc", but when i press the fire key (left mouse button) i get kicked from the server closed connection. While i made a return and force another class selection so it re-runs the if statement but for some reason sa-mp kicks me and temp bans me so i have to restart the server this is my code.

Код:
/* Class Selection */
public OnPlayerRequestClass(playerid, classid) {
    if(playersInfo[playerid][pFaction] == 0) {
	   	PlayerFactionSelected[playerid] = -1;
		PlayerFactionSelection[playerid] = 0;
		PlayerFactionSelectedtick[playerid] = GetTickCount();
		TogglePlayerSpectating(playerid, 1);
    	TextDrawShowForPlayer(playerid, txtClassSelHelper);
    	Class_FactionHandle(playerid);
    	playersInfo[playerid][pStatus] = PLAYER_STATUS_LOGGED_IN;
	} else {
		TogglePlayerSpectating(playerid, 0);
		SelectSkin(playerid, classid);
	}
	return 1;
}

forward SelectSkin(playerid, classid);
public SelectSkin(playerid, classid) {
	SetPlayerPos(playerid,1984.4445,157.9501,55.9384);
    SetPlayerCameraPos(playerid,1984.4445,160.9501,55.9384);
	SetPlayerCameraLookAt(playerid,1984.4445,157.9501,55.9384);
	SetPlayerFacingAngle(playerid,0.0);
	return 1;
}



/* Class Selection */
Class_FactionHandle(playerid) {
	new Keys,ud,lr;
    GetPlayerKeys(playerid,Keys,ud,lr);

    if(PlayerFactionSelection[playerid] == 0) {
		Class_SwitchToNextFaction(playerid);
		return;
	}

	// only allow new selection every ~500 ms
	if( (GetTickCount() -	PlayerFactionSelectedtick[playerid]) < 500 ) return;

	if(Keys & KEY_FIRE) {
		playersInfo[playerid][pFaction] = PlayerFactionSelection[playerid];
		new query[250];
		format(query, sizeof(query), "UPDATE `users` SET `user_faction` = '%d' WHERE `user_id` = '%d';", playersInfo[playerid][pFaction], playersInfo[playerid][pID]);
		mysql_query(mysql, query, QUERY_THREADED);
	    TextDrawHideForPlayer(playerid,txtClassSelHelper);
		TextDrawHideForPlayer(playerid,txtRepublicans);
		TextDrawHideForPlayer(playerid,txtLiberators);
		playersInfo[playerid][pStatus] = PLAYER_STATUS_LOGGED_IN;
        TogglePlayerSpectating(playerid, 0);
        ForceClassSelection(playerid);
	    return;
	}

	if(lr > 0) {
	   Class_SwitchToNextFaction(playerid);
	}
	else if(lr < 0) {
	   Class_SwitchToPreviousFaction(playerid);
	}
}

Class_SwitchToPreviousFaction(playerid) {
    PlayerFactionSelection[playerid]--;
	if(PlayerFactionSelection[playerid] < Team_Liberators) {
	    PlayerFactionSelection[playerid] = Team_Republicans;
	}
	PlayerPlaySound(playerid,1053,0.0,0.0,0.0);
	PlayerFactionSelectedtick[playerid] = GetTickCount();
	Class_SetupSelectedFaction(playerid);
}

Class_SwitchToNextFaction(playerid) {
    PlayerFactionSelection[playerid]++;
	if(PlayerFactionSelection[playerid] > Team_Republicans) {
	    PlayerFactionSelection[playerid] = Team_Liberators;
	}
	PlayerPlaySound(playerid,1052,0.0,0.0,0.0);
	PlayerFactionSelectedtick[playerid] = GetTickCount();
	Class_SetupSelectedFaction(playerid);
}

Class_SetupSelectedFaction(playerid) {
	if(PlayerFactionSelection[playerid] == 1) {
		PlayerFactionSelection[playerid] = Team_Liberators;
	}

	if(PlayerFactionSelection[playerid] == Team_Liberators) {
		SetPlayerInterior(playerid,0);
   		SetPlayerCameraPos(playerid,1630.6136,-2286.0298,110.0);
		SetPlayerCameraLookAt(playerid,1887.6034,-1682.1442,47.6167);

		TextDrawShowForPlayer(playerid,txtRepublicans);
		TextDrawHideForPlayer(playerid,txtLiberators);
	}
	else if(PlayerFactionSelection[playerid] == Team_Republicans) {
		SetPlayerInterior(playerid,0);
   		SetPlayerCameraPos(playerid,-1300.8754,68.0546,129.4823);
		SetPlayerCameraLookAt(playerid,-1817.9412,769.3878,132.6589);

		TextDrawHideForPlayer(playerid,txtRepublicans);
		TextDrawShowForPlayer(playerid,txtLiberators);
	}
}

Class_InitTextDraws() {
    // Init our observer helper text display
	txtRepublicans = TextDrawCreate(10.0, 380.0, "Republicans");
	Class_InitFactionNameText(txtRepublicans);
	txtLiberators = TextDrawCreate(10.0, 380.0, "Liberators");
	Class_InitFactionNameText(txtLiberators);

    // Init our observer helper text display
	txtClassSelHelper = TextDrawCreate(150.0, 15.0,
	   " Press ~b~~k~~GO_LEFT~ ~w~or ~b~~k~~GO_RIGHT~ ~w~to choose Faction.~n~ Press ~r~~k~~PED_FIREWEAPON~ ~w~to select.");
	TextDrawLetterSize(txtClassSelHelper,0.3,1.0);
	TextDrawTextSize(txtClassSelHelper,160.0,15.0);
	TextDrawFont(txtClassSelHelper, 2);
	TextDrawSetShadow(txtClassSelHelper,0);
    TextDrawSetOutline(txtClassSelHelper,1);
    TextDrawBackgroundColor(txtClassSelHelper,0x000000FF);
    TextDrawColor(txtClassSelHelper,0xFFFFFFFF);
}

Class_InitFactionNameText(Text:txtInit) {
  	TextDrawUseBox(txtInit, 0);
	TextDrawLetterSize(txtInit,1.25,3.0);
	TextDrawFont(txtInit, 0);
	TextDrawSetShadow(txtInit,0);
    TextDrawSetOutline(txtInit,1);
    TextDrawColor(txtInit,0xEEEEEEFF);
    TextDrawBackgroundColor(txtClassSelHelper,0x000000FF);
}
Thanks in advance!
Reply
#2

add
pawn Код:
public OnPlayerRequestClass(playerid,classid)
{
  SetSpawnInfo(playerid,1,0,0,0,0,0,0,0,0,0,0,0);
  return 1;
}
this should fix the kick problem
Reply
#3

Thank you for your reply, the only problem with this solution is that i use this system in combination with a class selection. So when they first join they have to select a faction (with the left and right arrow keys) and after they fired the button, they must get the class selection menu. The only problem is that when you press the fire key you get spawned instead it force the class selection menu (so you get kicked). So it temp bans yourself.
Reply
#4

I don't know much about the code you're working with and I don't really want to go through the hassle of troubleshooting my code, so I'll give you a sure fire fix. Create a new bool called PlayerSelectedClass. The way bools work this value will be automatically set to false. So under OnPlayerSpawn, check if that bool is false, and if it is then show the player the classes. Once the player selects a class, you can set that bool to true.
Reply
#5

Quote:
Originally Posted by RevolutionaryGaming
Посмотреть сообщение
I don't know much about the code you're working with and I don't really want to go through the hassle of troubleshooting my code, so I'll give you a sure fire fix. Create a new bool called PlayerSelectedClass. The way bools work this value will be automatically set to false. So under OnPlayerSpawn, check if that bool is false, and if it is then show the player the classes. Once the player selects a class, you can set that bool to true.
Thanks, i am gonna try it this way.
Reply
#6

Quote:
Originally Posted by nielsbon1
Посмотреть сообщение
Thank you for your reply, the only problem with this solution is that i use this system in combination with a class selection. So when they first join they have to select a faction (with the left and right arrow keys) and after they fired the button, they must get the class selection menu. The only problem is that when you press the fire key you get spawned instead it force the class selection menu (so you get kicked). So it temp bans yourself.
you get spawned coz all your code in OnPlayerRequestClass(playerid,classid)
i think it's a bug
Reply
#7

Quote:
Originally Posted by DaTa[X]
Посмотреть сообщение
you get spawned coz all your code in OnPlayerRequestClass(playerid,classid)
i think it's a bug
So what you say is that i need to split my code up from the OnPlayerRequestClass(playerid, classid) and put it in seperate functions.

Quote:
Originally Posted by RevolutionaryGaming
Посмотреть сообщение
I don't know much about the code you're working with and I don't really want to go through the hassle of troubleshooting my code, so I'll give you a sure fire fix. Create a new bool called PlayerSelectedClass. The way bools work this value will be automatically set to false. So under OnPlayerSpawn, check if that bool is false, and if it is then show the player the classes. Once the player selects a class, you can set that bool to true.
I tried your way i added

Код:
new bool:PlayerSelectedClass;

public OnPlayerSpawn(playerid) {
	if(PlayerSelectedClass == false) {
	     ForceClassSelection(playerid);
	}
}
But regardless i still get spawned & kicked.
Reply
#8

Quote:
Originally Posted by nielsbon1
Посмотреть сообщение
So what you say is that i need to split my code up from the OnPlayerRequestClass(playerid, classid) and put it in seperate functions.



I tried your way i added

Код:
new bool:PlayerSelectedClass;

public OnPlayerSpawn(playerid) {
	if(PlayerSelectedClass == false) {
	     ForceClassSelection(playerid);
	}
}
But regardless i still get spawned & kicked.
You get kicked? I didn't see you mention that. Can you post your OnPlayerSpawn code? How quickly are you kicked?
Reply
#9

Quote:
Originally Posted by RevolutionaryGaming
Посмотреть сообщение
You get kicked? I didn't see you mention that. Can you post your OnPlayerSpawn code? How quickly are you kicked?
Yes i get like instantly kicked when i press the fire key (so when i choose a faction), then it spawns me and it says server closed connection in like instant. When i try to rejoin it says "You are banned from the server" when it does not generates a ban file.

Here is the onplayerspawn:

Код:
public OnPlayerSpawn(playerid) {
 	if(PlayerSelectedClass == false) {
	     ForceClassSelection(playerid);
	     return 1;
	}

	/*if(playersInfo[playerid][pStatus] != PLAYER_STATUS_LOGGED_IN) {
		SendClientMessage(playerid, COLOR_RED, "Hier gaat het mis!");
        SetTimerEx("KickPlayer",500,false,"i", playerid);
	    return 0;
	}
	Set Skin to Database */

	SetPlayerScore(playerid, playersInfo[playerid][pScore]);
	SetPlayerSkin(playerid, playersInfo[playerid][pSkin]);
	return 1;
}
It's kinda strange i checked for the anti cheat etc. disabled everything that kicks a player but still it kicks me. And does not even give me the change to show the player classes. So when your faction is not set yet and you choose one you get kicked and when you rejoin it will show the player class selection menu but when you want to do it all at once it kicks you.
Reply
#10

I found the solution thank you guys, it was a combination from both of your solutions. I have just one question left is it possible to make a bool for every player so like bool:PlayerSelectedClass[MAX_PLAYERS];
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)