SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 29/12/2019, 08:30 AM   #1
ServerFiles
Big Clucker
 
Join Date: Dec 2017
Posts: 53
Reputation: 4
Default SendMSG to all using sql query? (+REP)

Hi,

I'm new to SQL and I want to send messages to all keys owner that online but I don't know how to do that in SQL, if anyone can help me, I appreciate that. I don't have enum cuz it direct from SQL.

PHP Code:
mysql_format(sqluserpQuerysizeof pQuery"SELECT `keyowner` FROM `businesskey` WHERE businessid = %d"bizid); 
ServerFiles is offline   Reply With Quote
Old 29/12/2019, 09:12 AM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: SendMSG to all using sql query? (+REP)

You need a column to determinate if the player is online or not. If `keyowner` is a text, you should really change it and link the user ID in `businesskey` table. Then you can JOIN the table and retrieve player name for the online players that have some records in `businesskey`.

If you want to keep the owner name, you must set it as UNIQUE KEY if a player can have only 1 house or an INDEX KEY if they can have multiple to speed up the query.

For start, post the table structures of `businesskey` and main player table.
__________________

Last edited by Calisthenics; 30/12/2019 at 09:39 AM. Reason: Removed sscanf part which is wrong
Calisthenics is offline   Reply With Quote
Old 29/12/2019, 01:04 PM   #3
ServerFiles
Big Clucker
 
Join Date: Dec 2017
Posts: 53
Reputation: 4
Default Re: SendMSG to all using sql query? (+REP)

Sorry, but I don't understand.

Here my structures of `businesskey`.
Code:
--
-- Table structure for table `businesskey`
--

CREATE TABLE `bizkeys` (
  `businessid` int(11) NOT NULL,
  `keyowner` varchar(128) NOT NULL,
  `emptytill` int(11) NOT NULL DEFAULT '0',
  `restock` int(11) NOT NULL DEFAULT '0',
  `setentrance` int(11) NOT NULL DEFAULT '0'
)

--
-- Dumping data for table `businesskey`
--

INSERT INTO `businesskey` (`businessid`, `keyowner`, `emptytill`, `restock`, `setentrance`) VALUES
(1, 'Server_Files', 1, 0, 0),
(1, 'Server_Filess', 1, 1, 1)
ServerFiles is offline   Reply With Quote
Old 30/12/2019, 08:12 AM   #4
Mugala
High-roller
 
Mugala's Avatar
 
Join Date: Nov 2012
Location: Georgia, Tbilisi
Posts: 1,161
Reputation: 73
Default Re: SendMSG to all using sql query? (+REP)

you can't send a message through SQL.
SQL is a database management system (detailed to wiki - https://en.wikipedia.org/wiki/MySQL)
you can't manipulate this as a 'message sending server', but, there is a one way to insert the messages for users, so it can be automatically checked overtime and display on a server as a message.
__________________
Coding in 8 languages including Pawn, C#, C++ and SQL.
Available for hiring.

If you have a coding question or need an assistance in a code, just PM me.
If you want me to create something for you, here is a Discord Mugala#5651

Currently helping Community members in a coding.
Mugala is offline   Reply With Quote
Old 30/12/2019, 09:48 AM   #5
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: SendMSG to all using sql query? (+REP)

Joining tables using owner name will be slow. You have to store user ID in `businesskey` and make it a foreign key to the main users table.

Create a column `Online` in main users table and update it to 1 every time the player is logged in or to 0 when they disconnect. You will have to create an index key for `Online` column.

Now with a simple JOIN query you can fetch all user IDs that are online and have records in `businesskey` table.

Alternative way might be a query with IN clause but I cannot test at the moment.

I understand that you are new to SQL and it might sound complicated but we cannot do much other than explaining how to make it.
__________________
Calisthenics is offline   Reply With Quote
Old 30/12/2019, 10:36 PM   #6
Beckett
High-roller
 
Beckett's Avatar
 
Join Date: Feb 2012
Location: www.finalnights-rp.com
Posts: 1,770
Reputation: 100
Default Re: SendMSG to all using sql query? (+REP)

Store the variable as the user id, rather than the name. Retrieve the ID from the database, loop through all online players; if their user ID is equal to that of the vehicle, send them a message.

You can still do this by comparing strings (if your keyowner is being saved as a name, rather than a user ID); use strcmp for that; compare the player's name to the variable `keyowner` and make sure `keyowner` is not NULL because strcmp will give a positive result. If the strings are identical, send them a message.

Think logically.
Beckett is offline   Reply With Quote
Old 31/12/2019, 12:02 PM   #7
ServerFiles
Big Clucker
 
Join Date: Dec 2017
Posts: 53
Reputation: 4
Default Re: SendMSG to all using sql query? (+REP)

I see, thanks for the help/info guys!
ServerFiles 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
Is it safe to include an un-escaped query into SQLite's query? Meller Scripting Help 2 09/10/2017 07:28 PM
Query K0P Scripting Help 4 09/02/2016 05:35 PM
Failed to exeute query. Lost connection to MySQL server during query. *IsBack Help Archive 10 06/01/2011 09:50 AM
[UNSOLVED] SendMSG Again... FreddeN Help Archive 14 18/03/2010 06:31 PM
[SOLVED] SendMSG FreddeN Help Archive 3 18/03/2010 02:47 PM


All times are GMT. The time now is 04:07 AM.


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