[+REP] Saved Gangs System [+REP]
#1

Hello, I'm using MySQL phpmyadmin system. And I want to create a saved gangs system.
I've read MySQL tutorials, but didn't understand how to load the gangs, I know it's easy to script, This is what I want to be in the gangs table:
gangID, gangBank, totalMembers, zones, leader.

If you want to post the script, post the "forward Loadgang" and the public too, example:
Код:
forward LoadGangs(idk);
public LoadGangs(idk)
{
     for(new i = 5; i <= MAX_GANGS; i++)
     {
          Set_content...(i, "leader", gInfo[i][leader]);
     }
     return 1;
}
Reply
#2

B U M P
Reply
#3

A quick example of what such a script could look like (assuming you use BlueG's MySQL plugin R39+, ZCMD and sscanf:

PHP код:
#define MAX_GANGS    10 
enum E_GANG_DATA 
     
    
// Example of an enumerator: 
    
databaseID
     
    
// Session Data 
    
g_Exists // This variable is used to find a free gang slot when creating one 
}; 
new 
Gang[MAX_GANGS][E_GANG_DATA]; 
public 
OnGameModeInit() { 
    
// Replace 'connectionHandler' with your MySQL connection variable 
    
mysql_tquery(connectionHandler"SELECT * FROM gangs""OnGangsLoad""");     
    return 
1

forward OnGangsLoad(); 
public 
OnGangsLoad() { 
     
    for(new 
0cache_get_row_count(); != j++) { 
         
        if(!
Gang[i][g_Exists]) { 
             
            
Gang[i][g_Exists] = true
            
// Load the rest of the data 
        

    } 
    return 
1

CMD:removegang(playeridparams[]) { 
     
    if(!
IsPlayerAdmin(playerid)) { 
         
        return 
SendClientMessage(playerid, -1"You can't use this command"); 
    }
    new
        
gangid;
    
    if(
sscanf(params"i"gangid)) { 
         
        return 
SendClientMessage(playerid, -1"USAGE: /removegang <gangid>"); 
    } 
    if(!
Gang[gangid][g_Exists] || gangid == -1) { 
         
        return 
SendClientMessage(playeridn -1"This gang does not exists"); 
    } 
    
RemoveGang(gangid); 
    return 
1

RemoveGang(gangid) { 
     
    if(
Gang[gangid][g_Exists) { 
         
        
Gang[gangid][g_Exists] = false
        new
            
query[40];
        
mysql_format(mysqlquerysizeof(query), "DELETE FROM gangs WHERE ID = %d"Gang[gangid][databaseID]); 
        
mysql_tquery(mysqlquery"""");
    }

Your table could look something like:
PHP код:
CREATE TABLE IF NOT EXISTS `gangs` ( 
    `
ID`        int(10)            NOT NULL    AUTO_INCREMENT
    `
Name`        varchar(50)        NOT NULL,
    
PRIMARY KEY(`ID`) 
ENGINE InnoDB DEFAULT CHARSET latin1 AUTO_INCREMENT 1
A few things that require an explanation:
- Gang ID's start from 0, not from 1!
- The 'ID' in the database has a size of 10 characters. Now, I doubt you'll have a database ID above 9,999,999,999. So you can lower that if you wish to.
- When creating a gang, you should loop through MAX_GANGS and see which one doesn't exist.

Example of such a loop:
PHP код:
for(0MAX_GANGSj++) if(!Gang[i][g_Exists]) {
    
Gang[i][g_Exists] = true;
    
// Set all the variables
    // Send a query with the data to the database

- The name can consist out of 50 characters in size (varchar), you can lower that or increase that value if you wish to, but I highly doubt you'll ever have a gang with a name over 50 characters.

- PRIMARY KEY is unique, no gang can have the same DatabaseID (which is not likely with the AUTO_INCREMENT on).

- You could add a foreign key and make relations for the leaders (don't store the leader's name, but rather, store the leader's database ID in the leader field if you ever decide to do that). Read Vince's database normalization tutorials for more information regarding foreign keys and making relations between different tables.

Good luck!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)