/* 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);
}
public OnPlayerRequestClass(playerid,classid)
{
SetSpawnInfo(playerid,1,0,0,0,0,0,0,0,0,0,0,0);
return 1;
}
|
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.
|
|
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 |
|
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.
|
new bool:PlayerSelectedClass;
public OnPlayerSpawn(playerid) {
if(PlayerSelectedClass == false) {
ForceClassSelection(playerid);
}
}
|
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);
}
}
|
|
You get kicked? I didn't see you mention that. Can you post your OnPlayerSpawn code? How quickly are you kicked?
|
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;
}