SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 28/06/2020, 05:02 PM   #1
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 188
Reputation: 2
Default what is wrong with create faction command

Hello ,i create this command :
PHP Code:
CMD:fcreate(playeridparams[])
{
    new 
string[128], query[400], fname[32];
    if(
sscanf(params"s[32]"fname)) return SendClientMessage(playerid, -1"USAGE: /fcreate factionname");
    
// GETTING ALL THE FACTIONS CREATED, THEN ADDING 1 TO MAKE THE NEW ONE
    
Total_Factions_Created++;
    
//=====================================================================
    
    // THIS SETS THE FACTIONS NAME TO WHATEVER YOU JUST NAMED IT, PLUS SETS THE ID FOR THE FACTION
    
format(Factions[Total_Factions_Created][FactionName], 64"%s"fname);
    
Factions[Total_Factions_Created][ID] = Total_Factions_Created;
    
//==============================================================================================
    
    // THIS IS JUST TELLING YOU CREATED A FACTION, WITH THE NAME
    
format(stringsizeof(string), "You have created a faction named: %s(ID:%d).",Factions[Total_Factions_Created][FactionName], Factions[Total_Factions_Created][ID]);
    
SendClientMessage(playerid, -1string);
    
//================================================================================================
    
    // THIS IS SETTING ALL THE FACTION NAMES, WILL BE USED LATER FOR EDITTING AROUND
    
format(Factions[Total_Factions_Created][Rank1], 32"Rank 1 - Lowest");
    
format(Factions[Total_Factions_Created][Rank2], 32"Rank 2");
    
format(Factions[Total_Factions_Created][Rank3], 32"Rank 3");
    
format(Factions[Total_Factions_Created][Rank4], 32"Rank 4");
    
format(Factions[Total_Factions_Created][Rank5], 32"Rank 5");
    
//================================================================================
    
    // THIS IS FOR SAVING ALL THE DATA INTO THE MYSQL DATABASE
    
mysql_format(MySQL:Databasequerysizeof(query), "INSERT INTO 'factions' ('ID', 'FactionName', 'FactionLeader', 'Rank1name', 'Rank2name', 'Rank3name', 'Rank4name', 'Rank5name'"
        
Factions[Total_Factions_Created][ID],Factions[Total_Factions_Created][FactionName],Factions[Total_Factions_Created][FactionLeader],Factions[Total_Factions_Created][Rank1],
        
Factions[Total_Factions_Created][Rank2],Factions[Total_Factions_Created][Rank3],Factions[Total_Factions_Created][Rank4],Factions[Total_Factions_Created][Rank5]);
    
mysql_query(MySQL:Databasequery);
    
//=================================================================================
    
return 1;

But when i create a faction , my database is still blank...
Mysql: https://imgur.com/LFB0zJC.png
xAlecsu is offline   Reply With Quote
Old 28/06/2020, 05:07 PM   #2
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,740
Reputation: 1686
Default Re: what is wrong with create faction command

I only looked at the query:
Code:
INSERT INTO 'factions' ('ID', 'FactionName', 'FactionLeader', 'Rank1name', 'Rank2name', 'Rank3name', 'Rank4name', 'Rank5name'
1- For table names, you either have to use no tips or backtips (``). So:
Code:
INSERT INTO factions
//or
INSERT INTO `factions`
Backtips are only required if it interferes with a MySQL keyword.

2- After using INSER INTO table_name you tell the query what columns a value should be inserted to, then you add the values:
Code:
INSERT INTO table_name (some_column, another_column, this_column) VALUES ('value_some_column', 'value_another_column', 'value_this_column');
If you insert data to all columns available
Code:
INSERT INTO table_name VALUES (...)
3- Check your mysql errors (SAMP_ROOT/logs/plugins/mysql.log) -You'll see there that the query failed.

I haven't looked at the rest of the script, more might be wrong. For now, focus on that query.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009

Last edited by Kwarde; 28/06/2020 at 05:08 PM. Reason: BBCode markup
Kwarde is offline   Reply With Quote
Old 28/06/2020, 05:15 PM   #3
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 188
Reputation: 2
Default Re: what is wrong with create faction command

I solve first problem
But i have a question ,i create 3 factions ,with 1, 2,3 ID .
If i delete faction with id 2 from database , and i create again another faction , new faction id is 4.
When i delete faction with id 2 ,and i create a new faction i want to be ID 2 , and next faction id 4 ...5...6
And if i make restart to server , and i try to create another faction . It start from 1 again. how i can solve this?
xAlecsu is offline   Reply With Quote
Old 28/06/2020, 05:36 PM   #4
Kwarde
High-roller
 
Kwarde's Avatar
 
Join Date: Nov 2009
Location: The Netherlands
Posts: 2,740
Reputation: 1686
Default Re: what is wrong with create faction command

Using AUTO_INCREMENT, the only way to do that (as far as I know) is by manually setting the ID after inserting a row.
If you want to start all over you'd have to clear the entire table
Code:
TRUNCATE factions;
This will delete all rows and also reset the AUTO_INCREMENT value.
__________________
When the opportunity presents itself to flip-a da table, uh, you flip-a da table.

Discord: Kwarde#8009
Kwarde is offline   Reply With Quote
Old 28/06/2020, 05:37 PM   #5
xAlecsu
Big Clucker
 
Join Date: Aug 2013
Posts: 188
Reputation: 2
Default Re: what is wrong with create faction command

yea i use auto-increment.it's ok on database.
but i want see the corect id when i use command (in game).


EDIT: I delete all factions from database ,and now when i create a faction ,in game id is 1 and in database is 4 not 1....
xAlecsu is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to create a faction for a command. Thanks Scripting Help 12 24/08/2017 07:31 AM
Please Help with create [Faction] Reebok1 Scripting Help 3 09/05/2014 10:00 AM
How to create RP's Faction? dieuhanhphuc Scripting Help 2 09/03/2013 02:57 AM
How to create a faction? MrBorsh Scripting Help 9 15/09/2012 04:35 PM
How do I create faction...? Gaby29 Scripting Help 5 18/01/2012 03:32 PM


All times are GMT. The time now is 05:10 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.