#1

Hello, there is mysql bug wich i can't understand this filterscript keep giving me error code
PHP код:
[17:11:03]   Loading filterscript 'wph.amx'...
[
17:11:03Failed to connect to 127.0.0.1.
[
17:11:03]   Loaded 1 filterscripts
And i'm sure that the configuration is good cuz i'm using it with my GM here is the Filterscirpt + DB
PHP код:
#define FILTERSCRIPT
#include <a_samp>
#include <a_mysql>
#undef MAX_PLAYERS
#define MAX_PLAYERS 100
#define DIALOG_EDIT_BONE 5000
#define isnull(%1) ((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#define MYSQL_HOST "127.0.0.1"
#define MYSQL_USER "root"
#define MYSQL_PASSWORD ""
#define MYSQL_DATABASE "wph"
new database;
enum weaponSettings
{
    
Float:Position[6],
    
Bone,
    
Hidden
}
new 
WeaponSettings[MAX_PLAYERS][17][weaponSettings], WeaponTick[MAX_PLAYERS], EditingWeapon[MAX_PLAYERS];
GetWeaponObjectSlot(weaponid)
{
    new 
objectslot;
    switch (
weaponid)
    {
        case 
22..24objectslot 0;
        case 
25..27objectslot 1;
        case 
282932objectslot 2;
        case 
3031objectslot 3;
        case 
3334objectslot 4;
        case 
35..38objectslot 5;
    }
    return 
objectslot;
}
GetWeaponModel(weaponid//Will only return the model of wearable weapons (22-38)
{
    new 
model;
    switch(
weaponid)
    {
        case 
22..29model 324 weaponid;
        case 
30model 355;
        case 
31model 356;
        case 
32model 372;
        case 
33..38model 324 weaponid;
    }
    return 
model;
}
PlayerHasWeapon(playeridweaponid)
{
    new 
weaponammo;
    for (new 
i13i++)
    {
        
GetPlayerWeaponData(playeridiweaponammo);
        if (
weapon == weaponid && ammo) return 1;
    }
    return 
0;
}
IsWeaponWearable(weaponid)
    return (
weaponid >= 22 && weaponid <= 38);
IsWeaponHideable(weaponid)
    return (
weaponid >= 22 && weaponid <= 24 || weaponid == 28 || weaponid == 32);
forward OnWeaponsLoaded(playerid);
public 
OnWeaponsLoaded(playerid)
{
    new 
rowsweaponidindex;
    
cache_get_row_count(rows);
    for (new 
irowsi++)
    {
        
cache_get_field_content_int(i"WeaponID"weaponid);
        
index weaponid 22;
        
WeaponSettings[playerid][index][Position][0] = cache_get_field_content_float(i"PosX");
        
WeaponSettings[playerid][index][Position][1] = cache_get_field_content_float(i"PosY");
        
WeaponSettings[playerid][index][Position][2] = cache_get_field_content_float(i"PosZ");
        
WeaponSettings[playerid][index][Position][3] = cache_get_field_content_float(i"RotX");
        
WeaponSettings[playerid][index][Position][4] = cache_get_field_content_float(i"RotY");
        
WeaponSettings[playerid][index][Position][5] = cache_get_field_content_float(i"RotZ");
        
WeaponSettings[playerid][index][Bone] = cache_get_field_content_int(i"Bone");
        
WeaponSettings[playerid][index][Hidden] = cache_get_field_content_int(i"Hidden");
    }
}
public 
OnFilterScriptInit()
{
    
database mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSWORDMYSQL_DATABASE);
    if (
mysql_errno()) printf("Failed to connect to %s."MYSQL_HOST);
    else 
printf("Successfully connected to %s."MYSQL_HOST);
    return 
1;
}
public 
OnFilterScriptExit()
{
    return 
1;
}
public 
OnPlayerUpdate(playerid)
{
    if (
NetStats_GetConnectedTime(playerid) - WeaponTick[playerid] >= 250)
    {
        new 
weaponidammoobjectslotcountindex;
        for (new 
2<= 7i++) //Loop only through the slots that may contain the wearable weapons
        
{
            
GetPlayerWeaponData(playeridiweaponidammo);
            
index weaponid 22;
            if (
weaponid && ammo && !WeaponSettings[playerid][index][Hidden] && IsWeaponWearable(weaponid) && EditingWeapon[playerid] != weaponid)
            {
                
objectslot GetWeaponObjectSlot(weaponid);
                if (
GetPlayerWeapon(playerid) != weaponid)
                    
SetPlayerAttachedObject(playeridobjectslotGetWeaponModel(weaponid), WeaponSettings[playerid][index][Bone], WeaponSettings[playerid][index][Position][0], WeaponSettings[playerid][index][Position][1], WeaponSettings[playerid][index][Position][2], WeaponSettings[playerid][index][Position][3], WeaponSettings[playerid][index][Position][4], WeaponSettings[playerid][index][Position][5], 1.01.01.0);
                else if (
IsPlayerAttachedObjectSlotUsed(playeridobjectslot)) RemovePlayerAttachedObject(playeridobjectslot);
            }
        }
        for (new 
i<= 5i++) if (IsPlayerAttachedObjectSlotUsed(playeridi))
        {
            
count 0;
            for (new 
22<= 38j++) if (PlayerHasWeapon(playeridj) && GetWeaponObjectSlot(j) == i)
                
count++;
            if (!
countRemovePlayerAttachedObject(playeridi);
        }
        
WeaponTick[playerid] = NetStats_GetConnectedTime(playerid);
    }
    return 
1;
}
public 
OnPlayerConnect(playerid)
{
    new 
string[70], name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnameMAX_PLAYER_NAME);
    for (new 
i17i++)
    {
        
WeaponSettings[playerid][i][Position][0] = -0.116;
        
WeaponSettings[playerid][i][Position][1] = 0.189;
        
WeaponSettings[playerid][i][Position][2] = 0.088;
        
WeaponSettings[playerid][i][Position][3] = 0.0;
        
WeaponSettings[playerid][i][Position][4] = 44.5;
        
WeaponSettings[playerid][i][Position][5] = 0.0;
        
WeaponSettings[playerid][i][Bone] = 1;
        
WeaponSettings[playerid][i][Hidden] = false;
    }
    
WeaponTick[playerid] = 0;
    
EditingWeapon[playerid] = 0;
    
mysql_format(databasestringsizeof(string), "SELECT * FROM weaponsettings WHERE Name = '%s'"name);
    
mysql_tquery(databasestring"OnWeaponsLoaded""d"playerid);
    return 
1;
}
public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if (
dialogid == DIALOG_EDIT_BONE)
    {
        if (
response)
        {
            new 
weaponid EditingWeapon[playerid], weaponname[18], name[MAX_PLAYER_NAME], string[150];
            
GetWeaponName(weaponidweaponnamesizeof(weaponname));
            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
            
WeaponSettings[playerid][weaponid 22][Bone] = listitem 1;
            
format(stringsizeof(string), "You have successfully changed the bone of your %s."weaponname);
            
SendClientMessage(playerid, -1string);
            
mysql_format(databasestringsizeof(string), "INSERT INTO weaponsettings (Name, WeaponID, Bone) VALUES ('%s', %d, %d) ON DUPLICATE KEY UPDATE Bone = VALUES(Bone)"nameweaponidlistitem 1);
            
mysql_tquery(databasestring);
        }
        
EditingWeapon[playerid] = 0;
        return 
1;
    }
    return 
0;
}
public 
OnPlayerEditAttachedObject(playeridresponseindexmodelidboneidFloat:fOffsetXFloat:fOffsetYFloat:fOffsetZFloat:fRotXFloat:fRotYFloat:fRotZFloat:fScaleXFloat:fScaleYFloat:fScaleZ)
{
    new 
weaponid EditingWeapon[playerid];
    if (
weaponid)
    {
        if (
response)
        {
            new 
enum_index weaponid 22weaponname[18], name[MAX_PLAYER_NAME], string[340];
            
GetWeaponName(weaponidweaponnamesizeof(weaponname));
            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
            
WeaponSettings[playerid][enum_index][Position][0] = fOffsetX;
            
WeaponSettings[playerid][enum_index][Position][1] = fOffsetY;
            
WeaponSettings[playerid][enum_index][Position][2] = fOffsetZ;
            
WeaponSettings[playerid][enum_index][Position][3] = fRotX;
            
WeaponSettings[playerid][enum_index][Position][4] = fRotY;
            
WeaponSettings[playerid][enum_index][Position][5] = fRotZ;
            
RemovePlayerAttachedObject(playeridGetWeaponObjectSlot(weaponid));
            
SetPlayerAttachedObject(playeridGetWeaponObjectSlot(weaponid), GetWeaponModel(weaponid), WeaponSettings[playerid][enum_index][Bone], fOffsetXfOffsetYfOffsetZfRotXfRotYfRotZ1.01.01.0);
            
format(stringsizeof(string), "You have successfully adjusted the position of your %s."weaponname);
            
SendClientMessage(playerid, -1string);
            
mysql_format(databasestringsizeof(string), "INSERT INTO weaponsettings (Name, WeaponID, PosX, PosY, PosZ, RotX, RotY, RotZ) VALUES ('%s', %d, %.3f, %.3f, %.3f, %.3f, %.3f, %.3f) ON DUPLICATE KEY UPDATE PosX = VALUES(PosX), PosY = VALUES(PosY), PosZ = VALUES(PosZ), RotX = VALUES(RotX), RotY = VALUES(RotY), RotZ = VALUES(RotZ)"nameweaponidfOffsetXfOffsetYfOffsetZfRotXfRotYfRotZ);
            
mysql_tquery(databasestring);
        }
        
EditingWeapon[playerid] = 0;
    }
    return 
1;
}
public 
OnPlayerCommandText(playeridcmdtext[])
{
    new 
cmd[24], params[64], len strlen(cmdtext);
    for (new 
ileni++) if (cmdtext[i] == ' ')
    {
        
strmid(cmdcmdtext0i);
        
strcat(paramscmdtext[1]);
        break;
    }
    if (
isnull(cmd)) strcat(cmdcmdtext);
    if (!
strcmp(cmd"/weapon"true))
    {
        new 
weaponid GetPlayerWeapon(playerid);
        if (!
weaponid)
            return 
SendClientMessage(playerid, -1"You are not holding a weapon.");
        if (!
IsWeaponWearable(weaponid))
            return 
SendClientMessage(playerid, -1"This weapon cannot be edited.");
        if (
isnull(params))
            return 
SendClientMessage(playerid, -1"USAGE: /weapon [adjustpos/bone/hide]");
        if (!
strcmp(params"adjustpos"true))
        {
            if (
EditingWeapon[playerid])
                return 
SendClientMessage(playerid, -1"You are already editing a weapon.");
            if (
WeaponSettings[playerid][weaponid 22][Hidden])
                return 
SendClientMessage(playerid, -1"You cannot adjust a hidden weapon.");
            new 
index weaponid 22;
            
SetPlayerArmedWeapon(playerid0);
            
SetPlayerAttachedObject(playeridGetWeaponObjectSlot(weaponid), GetWeaponModel(weaponid), WeaponSettings[playerid][index][Bone], WeaponSettings[playerid][index][Position][0], WeaponSettings[playerid][index][Position][1], WeaponSettings[playerid][index][Position][2], WeaponSettings[playerid][index][Position][3], WeaponSettings[playerid][index][Position][4], WeaponSettings[playerid][index][Position][5], 1.01.01.0);
            
EditAttachedObject(playeridGetWeaponObjectSlot(weaponid));
            
EditingWeapon[playerid] = weaponid;
        }
        else if (!
strcmp(params"bone"true))
        {
            if (
EditingWeapon[playerid])
                return 
SendClientMessage(playerid, -1"You are already editing a weapon.");
            
ShowPlayerDialog(playeridDIALOG_EDIT_BONEDIALOG_STYLE_LIST"Bone""Spine\nHead\nLeft upper arm\nRight upper arm\nLeft hand\nRight hand\nLeft thigh\nRight thigh\nLeft foot\nRight foot\nRight calf\nLeft calf\nLeft forearm\nRight forearm\nLeft shoulder\nRight shoulder\nNeck\nJaw""Choose""Cancel");
            
EditingWeapon[playerid] = weaponid;
        }
        else if (!
strcmp(params"hide"true))
        {
            if (
EditingWeapon[playerid])
                return 
SendClientMessage(playerid, -1"You cannot hide a weapon while you are editing it.");
            if (!
IsWeaponHideable(weaponid))
                return 
SendClientMessage(playerid, -1"This weapon cannot be hidden.");
            new 
index weaponid 22weaponname[18], name[MAX_PLAYER_NAME], string[150];
            
GetWeaponName(weaponidweaponnamesizeof(weaponname));
            
GetPlayerName(playeridnameMAX_PLAYER_NAME);
            if (
WeaponSettings[playerid][index][Hidden])
            {
                
format(stringsizeof(string), "You have set your %s to show."weaponname);
                
WeaponSettings[playerid][index][Hidden] = false;
            }
            else
            {
                if (
IsPlayerAttachedObjectSlotUsed(playeridGetWeaponObjectSlot(weaponid)))
                    
RemovePlayerAttachedObject(playeridGetWeaponObjectSlot(weaponid));
                
format(stringsizeof(string), "You have set your %s not to show."weaponname);
                
WeaponSettings[playerid][index][Hidden] = true;
            }
            
SendClientMessage(playerid, -1string);
            
mysql_format(databasestringsizeof(string), "INSERT INTO weaponsettings (Name, WeaponID, Hidden) VALUES ('%s', %d, %d) ON DUPLICATE KEY UPDATE Hidden = VALUES(Hidden)"nameweaponidWeaponSettings[playerid][index][Hidden]);
            
mysql_tquery(databasestring);
        }
        else 
SendClientMessage(playerid, -1"You have specified an invalid option.");
        return 
1;
    }
    return 
0;

DataBase
PHP код:
CREATE TABLE IF NOT EXISTS `weaponsettings` (
  `
Namevarchar(24NOT NULL,
  `
WeaponIDtinyint(4NOT NULL,
  `
PosXfloat DEFAULT '-0.116',
  `
PosYfloat DEFAULT '0.189',
  `
PosZfloat DEFAULT '0.088',
  `
RotXfloat DEFAULT '0.0',
  `
RotYfloat DEFAULT '44.5',
  `
RotZfloat DEFAULT '0.0',
  `
Bonetinyint(4NOT NULL DEFAULT '1',
  `
Hiddentinyint(4NOT NULL DEFAULT '0',
  
UNIQUE `weapon`(`Name`, `WeaponID`)
) DEFAULT 
CHARSET=utf8
Reply
#2

Are you sure that the localhost is running?
Reply
#3

Quote:
Originally Posted by MohanedZzZ
Посмотреть сообщение
Are you sure that the localhost is running?
Yes, he's runing
Reply
#4

Bump.... Any solution?
Reply
#5

Try like this:



Код:
database = mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE);
     
mysql_pquery(database, "SET NAMES 'utf8'", "" , "");
mysql_pquery(database, "SET CHARACTER SET 'utf8'", "" , "");
mysql_set_charset("utf8", database);

if(mysql_errno(database) != 0) print("Failed to connect to %s.");
else print("Successfully connected to %s.");
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)