SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/02/2019, 02:33 PM   #4601
ComDuck
Big Clucker
 
ComDuck's Avatar
 
Join Date: Feb 2019
Posts: 81
Reputation: 12
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by justinnater View Post
Is there any json_decode function? Need to store a json array to an Array in pawn.
https://forum.sa-mp.com/showthread.php?t=543919

Quite straightforward to use for something as simple as your request to be fair.
ComDuck is offline   Reply With Quote
Old 10/02/2019, 03:32 AM   #4602
justinnater
Huge Clucker
 
justinnater's Avatar
 
Join Date: Jan 2011
Posts: 283
Reputation: 79
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by ComDuck View Post
https://forum.sa-mp.com/showthread.php?t=543919

Quite straightforward to use for something as simple as your request to be fair.
Thanks, I am using it now and it's been a big help.
I am using it to retrieve JSON data from the HTTP function.

Although there is one thing that is bothering me about this HTTP function... The response data is being send to a callback.

Would it be possible to create a function that will make the HTTP function return the response data to itself instead of a callback?


So you could use it like this for example:
HTML Code:
new response = HTTP(playerid, HTTP_GET, "random.com", "");
justinnater is offline   Reply With Quote
Old 10/02/2019, 04:17 AM   #4603
ComDuck
Big Clucker
 
ComDuck's Avatar
 
Join Date: Feb 2019
Posts: 81
Reputation: 12
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by justinnater View Post
Thanks, I am using it now and it's been a big help.
I am using it to retrieve JSON data from the HTTP function.

Although there is one thing that is bothering me about this HTTP function... The response data is being send to a callback.

Would it be possible to create a function that will make the HTTP function return the response data to itself instead of a callback?


So you could use it like this for example:
HTML Code:
new response = HTTP(playerid, HTTP_GET, "random.com", "");
I don't think it is possible, you or someone else are welcome to surprise me. Calling HTTP won't just return the response code, it will also show the output data based on the URL requested through the parameters if if the response code is a 200 (OK). I guess in the bigger picture, it is much more efficient to design it that way.

EDIT: A different JSON plugin follows the same design: https://forum.sa-mp.com/showthread.php?t=653362
ComDuck is offline   Reply With Quote
Old 17/02/2019, 11:36 PM   #4604
justinnater
Huge Clucker
 
justinnater's Avatar
 
Join Date: Jan 2011
Posts: 283
Reputation: 79
Default Re: Little coding questions - For general minor queries 5

I've just found another problem with the HTTP function.

I'm sending two HTTP requests (Those two functions have a different callback where the response has to go to) in one function, the problem is that it will only react to the first callback that gets a response first, the other one wont be called after. Is this behavior normal or could it be something else?
justinnater is offline   Reply With Quote
Old 17/02/2019, 11:45 PM   #4605
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,831
Reputation: 3244
Default Re: Little coding questions - For general minor queries 5

Just don't use the built-in HTTP function at all. There are better plugins, such as "requests".
Y_Less is online now   Reply With Quote
Old 18/02/2019, 09:29 AM   #4606
CherryMond
Little Clucker
 
CherryMond's Avatar
 
Join Date: Feb 2018
Posts: 28
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

What is the best way to store items attached to a player in the mysql database? What should be the columns?

I was thinking over:
PHP Code:
 _______________________________________
|   ...........items....................|
 ---------------------------------------
id       int(8), PRIMARY KEYA_I   |
pid      int(8FOREIGN KEY (pid)   | // player register id from `players`
modelid  int(8)                     |
slot     int(8)                     |
boneid   int(8)                     |
fOffsetX Float                      |
fOffsetY Float                      |
fOffsetZ Float                      |
fRotX    Float                      |
fRotY    Float                      |
fRotZ    Float                      |
fScaleX  Float                      |
fScaleY  Float                      |
fScaleZ  Float                      |
 --------------------------------------- 
This will be working, I think, but if player is using all slots (0-9), will be 10 rows per player, what do you think about this? maybe you have better ways?
CherryMond is offline   Reply With Quote
Old 18/02/2019, 05:03 PM   #4607
ComDuck
Big Clucker
 
ComDuck's Avatar
 
Join Date: Feb 2019
Posts: 81
Reputation: 12
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by CherryMond View Post
What is the best way to store items attached to a player in the mysql database? What should be the columns?

This will be working, I think, but if player is using all slots (0-9), will be 10 rows per player, what do you think about this? maybe you have better ways?
I don't think there's any other way.

I don't see any redundant rows, and all your data dependencies make sense (based on https://wiki.sa-mp.com/wiki/SetPlayerAttachedObject). Although, I was thinking of an idea where you can compress each XYZ coordinates into a single line and separate the X, Y and Z float values with a separator character (-, /, etc), but why do all that extra work for your case? I don't even think it's a good idea anyways. What if you only want to modify a single coordinate value only?
ComDuck is offline   Reply With Quote
Old 18/02/2019, 05:08 PM   #4608
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 559
Reputation: 90
Default Re: Little coding questions - For general minor queries 5

The design is OK. If you set pid+slot as UNIQUE key, you can use INSERT INTO .. ON DUPLICATE.

Quote:
Originally Posted by ComDuck View Post
Although, I was thinking of an idea where you can compress each XYZ coordinates into a single line and separate the X, Y and Z float values with a separator character (-, /, etc), but why do all that extra work for your case? I don't even think it's a good idea anyways. What if you only want to modify a single coordinate value only?
Exactly, it is a bad idea.
Calisthenics is offline   Reply With Quote
Old 18/02/2019, 07:06 PM   #4609
CherryMond
Little Clucker
 
CherryMond's Avatar
 
Join Date: Feb 2018
Posts: 28
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Thank you for your answer, in which case it will be as it is.
CherryMond is offline   Reply With Quote
Old 18/02/2019, 07:19 PM   #4610
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,831
Reputation: 3244
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by ComDuck View Post
Although, I was thinking of an idea where you can compress each XYZ coordinates into a single line and separate the X, Y and Z float values with a separator character (-, /, etc), but why do all that extra work for your case? I don't even think it's a good idea anyways. What if you only want to modify a single coordinate value only?
That isn't a compression. That isn't good in any way. SQL can store floats as numbers internally. Your method would convert it to a string first, losing all the optimizations available. What's more, storing bits of data together is exactly what SQL is already designed to do very very well. So you are badly replicating part of the features of a database in the database, instead of just using the native functionality.
Y_Less is online now   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
how to make a soldier aotumaticly be general when the general dies ? AlbanianGuy Scripting Help 35 13/05/2012 03:35 PM
Minor problem Desert Help Archive 4 17/03/2010 06:24 PM
Counting with mysql queries actiwe Help Archive 2 26/02/2010 02:36 PM
SQL queries using GROUP BY Dabombber Help Archive 2 05/10/2009 07:47 PM


All times are GMT. The time now is 08:27 AM.


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