Samp clans won't save / load
#5

Quote:
Originally Posted by willbedie
Посмотреть сообщение
PHP код:
    cache_get_row_count(rows);
    if(
cache_num_rows() == 0)
    {
        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "INSERT INTO `clans` (`ClanName`, `Leader`, `Official`) VALUES ('%e', '%e', '0')"clannameGetName(playerid));
        
mysql_tquery(DatabaseDB_Query);
        
        
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] = 1;
    }
    else
    {
        
SendClientMessage(playeridCOLOR_RED"[SERVER]: That clan name is already registered by someone else.");
    } 
1) No active cache. You did not execute any query and just try to get the amount of rows out of nowhere.
2) If any error occurs for whatever reason, it will not insert to database but you will notify the player that his clan was created successfully.

Quote:
Originally Posted by willbedie
Посмотреть сообщение
PHP код:
CMD:createclan(cmdidplayeridparams[])
{
    ....
    
SaveClans();
    return 
1;

PHP код:
stock SaveClans()
{
    for (new 
1MAX_CLANS++)
    {
        
SaveClan(i);
    }
    return 
1;
}
stock SaveClan(id)
{
    new 
query[800];
    
mysql_format(Databasequerysizeof(query), "UPDATE `clans` SET `ClanName` = '%e', `ClanColor` = '%e', `ClanSpawn` = '%e', `Leader` = '%e', `Official` = '%e', `Rank1` = '%e', `Rank2' = %e', `Rank3` = '%e', `Rank4` = '%e', `Rank5` = '%e' WHERE ClanID = '%i'",
    
ClanInfo[id][ClanName], ClanInfo[id][ClanColor], ClanInfo[id][ClanSpawn], ClanInfo[id][Leader], ClanInfo[id][Official], ClanInfo[id][Rank1], ClanInfo[id][Rank2], ClanInfo[id][Rank3], ClanInfo[id][Rank4], ClanInfo[id][Rank5], ClanInfo[id][ClanID]);
    
mysql_tquery(Databasequery);
    return 
1;

Absolutely no reason for this.
1) You update every clan whenever a clan is created. What do other clans have to do with the one being created? Nothing at all.
2) Your loop starts from value 1. Why? Arrays start from index 0. This is utterly something very old scripts used and most new members do the same nowadays.
3) Your INSERT query is there to set any value you want. Executing an UPDATE query afterwards is meaningless.
4) Why do you have another table `ClanID`? The first column of the table `clans` should have been the `clanid`.
5) Again, in LoadClans. Why do you call cache functions when no active cache? It must be either AFTER mysql_query or in a callback set by mysql_tquery/mysql_pquery. Not before, not in random places. Also `clanid` will always be 0 and it won't retrieve all the rows but the first from the database. You need a loop there.
Reply


Messages In This Thread
Samp clans won't save / load - by solstice_ - 22.08.2018, 23:29
Re: Samp clans won't save / load - by victory88 - 23.08.2018, 01:13
Re: Samp clans won't save / load - by solstice_ - 23.08.2018, 01:39
Re: Samp clans won't save / load - by Sew_Sumi - 23.08.2018, 03:23
Re: Samp clans won't save / load - by Calisthenics - 23.08.2018, 10:59
Re: Samp clans won't save / load - by solstice_ - 23.08.2018, 14:58
Re: Samp clans won't save / load - by Sew_Sumi - 23.08.2018, 15:10
Re: Samp clans won't save / load - by solstice_ - 23.08.2018, 15:11
Re: Samp clans won't save / load - by Sew_Sumi - 23.08.2018, 15:13
Re: Samp clans won't save / load - by solstice_ - 23.08.2018, 15:14

Forum Jump:


Users browsing this thread: 1 Guest(s)