SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 07/12/2017, 12:11 PM   #1
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 608
Reputation: 68
Default Saving age from dialog to SQLite

Hey yall, im trying to save the age from an inputtext from an dialog.
I played around with it for around an hour or two but I cant get it to work.
I just want to store what ever number the player entered in dialogid 3 and save it to the SQLite database.

Code:

Code:
public OnPlayerSpawn(playerid)
{	
        new str[2500];
  	strcat(str,""chat" "COL_WHITE"Enter your age");
 	ShowPlayerDialog(playerid,3,DIALOG_STYLE_INPUT,""COL_WHITE"Alice",str,"Enter","");
        return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{

     if(dialogid == 3)
     {
	    if(response)
	    {
			new Query[1000];
			new amount[128] = inputtext;
			User[playerid][USER_AGE] = amount[playerid];
			format(Query, sizeof(Query), "UPDATE users SET age = %d", User[playerid][USER_AGE]);
			db_query(Database, Query);

	    }
     }
}
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2017, 12:29 PM   #2
Iszcegg
Gangsta
 
Iszcegg's Avatar
 
Join Date: Oct 2013
Location: Venezuela
Posts: 839
Reputation: 90
Default Re: Saving age from dialog to SQLite

PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];

            
User[playerid][USER_AGE] = strval(inputtext);

            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Iszcegg is online now   Reply With Quote
Old 07/12/2017, 12:42 PM   #3
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 608
Reputation: 68
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Iszcegg View Post
PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
     if(
dialogid == 3)
     {
        if(
response)
        {
            new 
Query[1000];

            
User[playerid][USER_AGE] = strval(inputtext);

            
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]);
            
db_query(DatabaseQuery);
        }
    }

Works! Thank you.
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 07/12/2017, 01:35 PM   #4
Dayrion
High-roller
 
Dayrion's Avatar
 
Join Date: Jan 2016
Location: France
Posts: 1,473
Reputation: 120
Default Re: Saving age from dialog to SQLite

PHP Code:
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]); 
Will update every users's age to the current value, no?
__________________
What matters isn't to going further, it's the way to get there
Dayrion is online now   Reply With Quote
Old 07/12/2017, 01:40 PM   #5
Calgon
Godfather
 
Calgon's Avatar
 
Join Date: Jan 2009
Posts: 6,435
Reputation: 1060
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Voxel View Post
Works! Thank you.
Make sure you reduce Query[1000] down to the amount of characters you actually need there, it looks like you're using under 30 characters. You will reduce memory usage in your AMX by making sure you don't have such large strings.

Query[30] will be fine.

Quote:
Originally Posted by Dayrion View Post
PHP Code:
format(Querysizeof(Query), "UPDATE users SET age = %d"User[playerid][USER_AGE]); 
Will update every users's age to the current value, no?
No. Read the code, the age variable is set BEFORE the query.
__________________
Calgon is offline   Reply With Quote
Old 07/12/2017, 02:21 PM   #6
Konstantinos
Spam Machine
 
Konstantinos's Avatar
 
Join Date: Dec 2011
Posts: 11,990
Reputation: 1378
Default Re: Saving age from dialog to SQLite

Quote:
Originally Posted by Calgon View Post
No. Read the code, the age variable is set BEFORE the query.
Dayrion does not refer to variable. It WILL update the age of all users in the table unless WHERE clause is used to identify the user (by registration id or name).
__________________
Life is like riding a bicycle. To keep your balance, you must keep moving.

[Tutorial] How to use SQLite
[FilterScript] Tune System
Konstantinos 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
SQLite and saving date FailerZ Scripting Help 0 09/06/2017 07:56 PM
Saving to SQLite Johnny_Robins Scripting Help 0 13/05/2014 12:57 PM
Saving into sqlite. Unri Scripting Help 6 27/09/2013 09:28 PM
[HELP] sqlite saving in FS bugs other FS's? <Weponz> Help Archive 0 31/12/2010 04:34 PM


All times are GMT. The time now is 08:55 PM.


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