OnPlayerConnect
#1

hey there

well everything works fine but onplayerconnect isnt working i mean when player connect mysql doesnt check accounts no query even i checked mysql logs and also no gang zones show for player nothing works in onplayerconnect and also when i connect to me server it says request connection cookie i never had anything like this before

OnPlayerConnect
PHP код:
//Checking player's account if they are registered or not.
function OnPlayerConnect(playerid)
{
        new 
query[228], str[64], joinMsg[128], name[MAX_PLAYER_NAME], pName[MAX_PLAYER_NAME];
        for(new 
PDATA:ePDATA; ++e)
        {
                
pInfo[playerid][e] = 0;
        }
        for(new 
BANINFO:eBANINFO; ++e)
        {
                
bInfo[playerid][e] = 0;
        }
       
        
inJail[playerid] = 0;
        
//
        
LoginAttempt[playerid] = 0;
        
//
        
Muted[playerid] = false;
 
        
//
        
AutoRepair[playerid] = 1;
        
//
        
pMG_Minigame[playerid] = false;
        
//
        
BadWeaponsAllowed[playerid] = false;
        
//
        
PlayerProps[playerid] = 0;
        
//
    
EarningsForPlayer[playerid] = 0;
        
//
        
gNameTags[playerid] = 1;
        
//
        
AimbotWarnings[playerid] = 0;
        
//
        
g_MysqlRaceCheck[playerid]++;
        
//
        
ShowGlobalTextdraws(playerid);
        
//
        
CreatePlayerTextdraw(playerid);
        
//
        
pInfo[playerid][Money] = 0;
 
 
        for( new 
,slots GetMaxPlayers(); slotsi++ )
        {
                if(
IsPlayerConnected(i))
                {
                    
pcounters[playerid]++;
                }
                if(
pcounters[i])
                {
                    new 
strd[8];
                    
format(strdsizeof(strd), "%d/%d"pcountersGetMaxPlayers());
                    
TextDrawSetString(TDEditor_TD[2], strd);
                }
                else
                {
                        
TextDrawSetString(TDEditor_TD[2], "0/30");
                }
         }
 
        
mysql_format(mysqlquerysizeof(query), "SELECT * FROM `bans` WHERE `Username` = '%e'"GetName(playerid));
        
mysql_tquery(mysqlquery"OnPlayerCheckBan""d"playerid);
 
        
mysql_format(mysqlquerysizeof(query),"INSERT INTO `ip` (`IP`, `Username`) VALUES ('%s','%s')",GetPlIP(playerid),GetName(playerid));
        
mysql_tquery(mysqlquery,"","");
        
ShowPlayerTextdraw(playerid);
 
    new 
mysqlquery[200];
    
mysql_format(mysqlmysqlquerysizeof(mysqlquery), "SELECT c.country_name FROM list_ipv4 i JOIN list_countries c ON i.country_code = c.country_code WHERE INET_ATON('%e') BETWEEN range_start AND range_end;"IP[playerid]);
    
mysql_tquery(mysqlmysqlquery"GetCountryName""d"playerid);
 
        
GetPlayerName(playeridName[playerid], 24); //Getting player's name   
        
GetPlayerIp(playeridIP[playerid], 16); //Getting layer's IP forgot this part, now it shoul save
       
        
format(str,sizeof(str),""HostURL"%s",IP[playerid]);
        
HTTP(playeridHTTP_GETstr"""IRCOnHostResponse");
       
        
pInfo[playerid][ConnectTime] = gettime(); //gettime (); = is the amount of seconds since 1970
        //LoadPlayerTextDraws(playerid);
 
        
RemoveBuildingForPlayer(playerid13020.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid12090.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid9550.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid9560.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid17750.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid17760.00.00.06000.0);
        
RemoveBuildingForPlayer(playerid19770.00.00.06000.0);
//      ShowGloablTextdraws(playerid);
        
printf("IP on connect: %s"IP[playerid]); //check this. brb in 15-20 mins ok
 
        
mysql_format(mysqlquerysizeof(query),"SELECT * FROM `players` WHERE `Username` = '%e' LIMIT 1"Name[playerid]);
        
mysql_tquery(mysqlquery"OnAccountCheck""dd"playerid,g_MysqlRaceCheck[playerid]);
 
        
GetPlayerName(playeridnamesizeof(name));
 
        
format(joinMsgsizeof(joinMsg), "02[%d] 03*** %s has joined the server."playeridname);
        
IRC_GroupSay(groupIDIRC_CHANNELjoinMsg);
 
        
SendClientMessage(playeridCOLOR_WHITE"Welcome to "COL_RED"eXtreme Multi Stunts server "COL_WHITE"(/help)");
        
SendClientMessage(playeridCOLOR_WHITE"Please read "COL_RED"/rules /commands "COL_WHITE"to explore our server");
        
GangZoneShowForAll(GZ_ZONE20xFE5F6366);
        
GangZoneShowForAll(GZ_ZONE10xFE5F6366);
        
GangZoneShowForAll(GZ_ZONE30xFE5F6366);
        
SendDeathMessage(INVALID_PLAYER_IDplayerid200); // connect
        
GetPlayerName(playeridpNameMAX_PLAYER_NAME);
 
        for(new 
propidpropid PropertiesAmountpropid++)
        {
                if(
PropInfo[propid][PropIsBought] == 1)
                {
                    if(
strcmp(PropInfo[propid][PropOwner], pNametrue)==0)
                        {
                            
EarningsForPlayer[playerid] += PropInfo[propid][PropEarning];
                            
PlayerProps[playerid]++;
                        }
                }
        }
 
    
/*for(new i; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i) && gNameTags[i] == 0)
        ShowPlayerNameTagForPlayer(i, playerid, 0);
        }*/
        
return 1;

Reply
#2

Hey,
Are you using mysql_connect on ongamemodeinit ? If not you need to connect to your database before the other things.

Michael
Reply
#3

It is probably cause you have public OnPlayerConnect and function OnPlayerConnect. Rename the function to OnPlayerConnected.
Reply
#4

bgedition yes im using mysql_connect in ongamemodeinit and

slotomic : actully its OnPlayerConnect public and i also changed it to public nothing happens
Reply
#5

You might be having an infinite loop.

Show your ALS Hooks on OnPlayerConnect.

Add prints in random locations in your OnPlayerConnect and let us know where the last print was.
Reply
#6

AFAIK, you can't get country on connect callback.
Between, did you try to add a debug on OnPlayerConnect?
Reply
#7

well thanks to yashas! so i found where it stops
in this loop
it means after this loop ends then onplayerconnect isnt getting called
PHP код:

        
for( new islots GetMaxPlayers(); slotsi++ )
        {
                if(
IsPlayerConnected(i))
                {
                    
pcounters[playerid]++;
                }
                if(
pcounters[i])
                {
                    new 
strd[8];
                    
format(strdsizeof(strd), "%d/%d"pcountersGetMaxPlayers());
                    
TextDrawSetString(TDEditor_TD[2], strd);
                }
                else
                {
                        
TextDrawSetString(TDEditor_TD[2], "0/30");
                }
         } 
Reply
#8

This loop is stupid...

new strd[8];
format(strd, sizeof(strd), "%d/%d", GetCurrentPlayers(), GetMaxPlayers());
TextDrawSetString(TDEditor_TD[2], strd);

Isn't that easier? Also use foreach, its way better for counting, looping and much more useful info.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)