How to load the clan onplayerrequestclass
#1

Hello, how do i load the clan when the player requests his class, here's my code:

PHP код:
CMD:createclan(cmdidplayeridparams[])
{
    if(
UserStats[playerid][Kills] < 1000) return SendClientMessage(playeridCOLOR_RED"[ERROR]: You must have 1000+ kills to create a clan.");
    new 
clanname[32], string[300], query[600], rows;
    if(
sscanf(params"s[32]"clanname)) return SendClientMessage(playeridCOLOR_RED"[USAGE]: /createclan [clanname]");
    
mysql_format(Databasequerysizeof(query), "SELECT * FROM `clans` WHERE `ClanName` = '%e' LIMIT 0, 1"clanname);
    new 
Cache:result mysql_query(Databasequery);
    
cache_get_row_count(rows);
    
    if(
rows)
    {
        
SendClientMessage(playeridCOLOR_RED"[SERVER]: That clan name is already registered by someone else.");
        return 
0;
    }
    
    for (new 
0rows++)
    {
        
mysql_format(Databasequerysizeof(query), "INSERT INTO `clans` (`ClanName`, `Leader`, `Official`) VALUES ('%e', '%e', '0')"clannameGetName(playerid));
        
mysql_tquery(Databasequery);
        
format(stringsizeof(string), "[SERVER]: You have created a unofficial clan named %s."clanname);
        
SendClientMessage(playeridCOLOR_REDstring);
        
format(stringsizeof(string), "Clan Name: %s, Official: No"clanname);
        
SendClientMessage(playeridCOLOR_REDstring);
        
UserStats[playerid][Clan] = cache_insert_id();
    }
    
cache_delete(result);
    return 
1;

PHP код:
public OnPlayerRequestClass(playeridclassid)
{
    
SetPlayerPos(playerid1869.176269, -1362.81665019.140625);
    
SetPlayerFacingAngle(playerid233.139862);
    
SetPlayerCameraLookAt(playerid1869.176269, -1362.81665019.140625);
    
SetPlayerCameraPos(playerid1869.176269 + (10 floatsin(-233.139862degrees)), -1362.816650 + (10 floatcos(-233.139862degrees)), 19.140625);
    switch(
classid)
    {
        case 
0:
        {
            
GameTextForPlayer(playerid"~y~La Raza"10004);
            
Team[playerid] = TEAM_LARAZA;
            
SetPlayerTeam(playeridTEAM_LARAZA);
        }
        case 
1:
        {
            
GameTextForPlayer(playerid"~y~Wah Ching"10004);
            
Team[playerid] = TEAM_WAHCHING;
            
SetPlayerTeam(playeridTEAM_WAHCHING);
        }
        case 
2:
        {
            
GameTextForPlayer(playerid"~y~La Cosa Nostra"10004);
            
Team[playerid] = TEAM_LACOSANOSTRA;
            
SetPlayerTeam(playeridTEAM_LACOSANOSTRA);
        }
        case 
3:
        {
            
GameTextForPlayer(playerid"~y~Special Forces"10004);
            
Team[playerid] = TEAM_SPECIALFORCES;
            
SetPlayerTeam(playeridTEAM_SPECIALFORCES);
        }
        case 
4:
        {
            if(
UserStats[playerid][Clan])
            {
                new 
string[250], cidquery[250];
                
mysql_format(Databasequerysizeof(query), "SELECT * FROM `clans` WHERE `ClanID` = '%i' LIMIT 0, 1"cid);
                new 
Cache:result mysql_query(Databasequery);
                
                for (new 
0MAX_CLANS++)
                {
                    
format(stringsizeof(string), "%s"ClanInfo[i][ClanName]);
                    
GameTextForPlayer(playeridstring10004);
                }
                
cache_delete(result);
            }
            else
            {
                
GameTextForPlayer(playerid"~r~YOU ARE NOT IN A CLAN"10004);
                
Team[playerid] = NOTINCLAN;
            }
        }
    }
    return 
true;

Reply
#2

Quote:
Originally Posted by willbedie
Посмотреть сообщение
Hello, how do i load the clan when the player requests his class
If you're logging them in, if it's a player saved stat, then you load them before they even request the class.

Also, be clear on where infact you want this, as request class, is when they are going through the skin selection, not requesting spawn.

If you allow this, someone could sit in the spawn window, and change classes, seeing all the teams chats.




Alright, now I've come back to looking at your code.... (because the spawn window has so much capability, no-one actually uses it, and when they do changes to it, they BREAK it, and it causes problems elsewhere in the script, and to be sure of this, I took your code out, to look at after I had made the above)



No... Just no, you should revise this, as really, if it is after them logging in, then when they are logging in, is where you should be loading their clan into their enum.

You should only set the team associations on spawn in a class selection screen, and when they are in that window, they should be not getting any of those messages anyway, or anything, as they aren't 'in the game'.
Reply
#3

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
If you're logging them in, if it's a player saved stat, then you load them before they even request the class.

Also, be clear on where infact you want this, as request class, is when they are going through the skin selection, not requesting spawn.

If you allow this, someone could sit in the spawn window, and change classes, seeing all the teams chats.




Alright, now I've come back to looking at your code.... (because the spawn window has so much capability, no-one actually uses it, and when they do changes to it, they BREAK it, and it causes problems elsewhere in the script, and to be sure of this, I took your code out, to look at after I had made the above)



No... Just no, you should revise this, as really, if it is after them logging in, then when they are logging in, is where you should be loading their clan into their enum.

You should only set the team associations on spawn in a class selection screen, and when they are in that window, they should be not getting any of those messages anyway, or anything, as they aren't 'in the game'.
The skin is going to be shown to the player only if he's on a clan, but the clan doesnt even load. Can you give me a code example , i would really appreciate it

EDIT:
Just to make things clear, clans do load from the database, but it won't load on the player when i'm checking if he's on a clan (if i'm doing it right..)and actually they can't view the clan chat while they're requesting their class, i know, i'm aware that OnPlayerRequestClass doesn't have to do with spawning the player, it's just the skin selection but still, if the player is not in a clan it should not show them the skin. If anyone could give me a code-example on that i would appreciate it.
Reply
#4

You could put all skins into the class selection, and restrict their spawn based on the clan ID on the skin compared to their membership, or you could simply have a claude skin, which is a placeholder to allow them to get past the screen, and when they select the spawn, then have them set to their clan setup.


And in respects of the claude placeholder, have NPCs in an area, with different skins for each clan on, and make the camera look at whatever their clan NPC is.


There will be many different ways to do this sort of thing. But I'm sure that the idea of changing the skin of a class whilst in the class selection screen, isn't likely to be possible.

I may be wrong, but the throw-outs above of ideas, could help you in thinking from another angle, and checking out other things.
Reply
#5

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
You could put all skins into the class selection, and restrict their spawn based on the clan ID on the skin compared to their membership, or you could simply have a claude skin, which is a placeholder to allow them to get past the screen, and when they select the spawn, then have them set to their clan setup.


And in respects of the claude placeholder, have NPCs in an area, with different skins for each clan on, and make the camera look at whatever their clan NPC is.


There will be many different ways to do this sort of thing. But I'm sure that the idea of changing the skin of a class whilst in the class selection screen, isn't likely to be possible.

I may be wrong, but the throw-outs above of ideas, could help you in thinking from another angle, and checking out other things.
I mean only skin id 0 will be available if they are in a clan, if they're not in a clan the game text "You are not in a clan" will pop on the screen when they try to spawn as a clan member. But i'm not sure if my ClanID insert code is correct, can you check that once again, it's in the /createclan command somewhere
Reply
#6

First thing i will say, you must set UserStats[playerid][Clan] by default value to -1 because 0 can be a valid clan id, then in your code:

PHP код:
case 4
        { 
            if(
UserStats[playerid][Clan]=>0
            { 
                new 
string[100]; 
                    
format(stringsizeof(string), "%s"ClanInfo[UserStats[playerid][Clan]][ClanName]); 
                    
GameTextForPlayer(playeridstring10004); 
                
//you must have loaded all clan names before somewhere
            

            else
            { 
                
GameTextForPlayer(playerid"~r~YOU ARE NOT IN A CLAN"10004); 
                return 
0//prevents the player from spawning
            

        } 
Reply
#7

Quote:
Originally Posted by Shinja
Посмотреть сообщение
First thing i will say, you must set UserStats[playerid][Clan] by default value to -1 because 0 can be a valid clan id, then in your code:

PHP код:
case 4
        { 
            if(
UserStats[playerid][Clan]=>0
            { 
                new 
string[100]; 
                    
format(stringsizeof(string), "%s"ClanInfo[UserStats[playerid][Clan]][ClanName]); 
                    
GameTextForPlayer(playeridstring10004); 
                
//you must have loaded all clan names before somewhere
            

            else
            { 
                
GameTextForPlayer(playerid"~r~YOU ARE NOT IN A CLAN"10004); 
                return 
0//prevents the player from spawning
            

        } 
Now that doesn't even tell the clan name & it's just the skin and no text at all, blank..
Reply
#8

Quote:
Originally Posted by Shinja
Посмотреть сообщение
PHP код:
                //you must have loaded all clan names before somewhere 
Did you notice this part?
Try to debug the string
PHP код:
                    new string[100];  
                    
format(stringsizeof(string), "%s"ClanInfo[UserStats[playerid][Clan]][ClanName]);  
                    
GameTextForPlayer(playeridstring10004);
                    
format(stringsizeof(string), "Clan name: %s"ClanInfo[UserStats[playerid][Clan]][ClanName]);  
                    
SendClientMessage(playerid, -1string); 
Reply
#9

Quote:
Originally Posted by Shinja
Посмотреть сообщение
Did you notice this part?
Try to debug the string
PHP код:
                    new string[100];  
                    
format(stringsizeof(string), "%s"ClanInfo[UserStats[playerid][Clan]][ClanName]);  
                    
GameTextForPlayer(playeridstring10004);
                    
format(stringsizeof(string), "Clan name: %s"ClanInfo[UserStats[playerid][Clan]][ClanName]);  
                    
SendClientMessage(playerid, -1string); 
Yeah i have a stock LoadClans() under OnPlayerRequestClan which loads the clan, but that is used OnGameModeInit, so yeah the clans are loaded before the player requests his class, p.s i'll just try to debug it and tell you if it works.

EDIT: It doesn't work still, the debug is just blank, it's:

Clan name: (no clan name or any text here)
Reply
#10

Debug the clan id
PHP код:
                    new string[100];  
                    
format(stringsizeof(string), "%s"ClanInfo[UserStats[playerid][Clan]][ClanName]);  
                    
GameTextForPlayer(playeridstring10004);
                    
format(stringsizeof(string), "Clan ID: %d"UserStats[playerid][Clan]);  
                    
SendClientMessage(playerid, -1string); 
And check in your database if its the right clan id
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)