Re: Little coding questions - For general minor queries 5 -
[HLF]Southclaw - 21.01.2019
Constants are generally preferred over definitions: `const something = 5;`. They provide an actual name for the value so any warnings or errors will provide more information at compile time. `#define` is effectively search-and-replace at compile-time which can lead to some non-obvious issues.
Re: Little coding questions - For general minor queries 5 -
SyS - 22.01.2019
Quote:
Originally Posted by Nathan94
Hello sampers, I was wondering what's the difference between "#define something 5" and "#define something (5)"?
|
If it's a single constant there is no difference.But if it was an expression for example
PHP Code:
#define EIGHT_PLUS_TWO 8+2
and
PHP Code:
#define EIGHT_PLUS_TWO (8+2)
are different.
lets see the first case
PHP Code:
#define EIGHT_PLUS_TWO 8+2
main(){
new result = 2 * EIGHT_PLUS_TWO;
ASSERT(20==result);//will fail as result is 18
}
the above one is expanded to
Code:
new result = 2 * EIGHT_PLUS_TWO = 2 * 8+2 = 16+2 = 18 as per operator precedence
But in the second case
PHP Code:
#define EIGHT_PLUS_TWO (8+2)
main(){
new result = 2 * EIGHT_PLUS_TWO;
ASSERT(20==result);//will pass as one in parentheses is evaluated first
}
is expanded to
Code:
result = 2 * EIGHT_PLUS_TWO = 2 * (8+2) = 2*(10) = 20 as per operator precedence
Re: Little coding questions - For general minor queries 5 -
Logic_ - 23.01.2019
Hi,
I've a few questions related to MySQL.
- What's the BEST way to store player records (IP, admins, bans, etc)
- And, what's the best way to store configuration data in the database? Such as:
PHP Code:
CREATE TABLE IF NOT EXISTS "#TABLE_SERVER_CFG" (\
`weather` INTEGER, \
`time` INTEGER, \
`double_score` INTEGER, \
`motd` VARCHAR(100), \
`amotd` VARCHAR(100)\
)
I don't think it's a good use of MySQL to store such information and I should use INI or CFG files. But, I wish to keep everything all-together in one database. And the data is supposed to be updated on server shutdown or during the runtime.
Re: Little coding questions - For general minor queries 5 -
Y_Less - 23.01.2019
You're right, SQL is not good for that. But if you are to, do one item per row, not column. So just a few generic `key` and `value` columns, then each config option separately. Similar for player records. An `admins` table with one per row; a `bans` table etc.
Re: Little coding questions - For general minor queries 5 -
CrypticSin - 24.01.2019
Hello,
I've been adding vehicles to my samp server by using the samp debug however i've discovered there was an easier way to add cars and objects to my server and that is from fusez's map editor.
Now, if i add objects and cars to my map using fusez's map editor and when i save it how would i add the objects and cars used from that filterscript into my main server? Also would it completely erase the vehicles i've added by using the samp debug?
Re: Little coding questions - For general minor queries 5 -
Y_Less - 25.01.2019
Just load the FS.
No.
Re: Little coding questions - For general minor queries 5 -
justinnater - 06.02.2019
Is there any json_decode function? Need to store a json array to an Array in pawn.
Re: Little coding questions - For general minor queries 5 -
ComDuck - 08.02.2019
Quote:
Originally Posted by justinnater
Is there any json_decode function? Need to store a json array to an Array in pawn.
|
https://sampforum.blast.hk/showthread.php?tid=543919
Quite straightforward to use for something as simple as your request to be fair.
Re: Little coding questions - For general minor queries 5 -
justinnater - 10.02.2019
Quote:
Originally Posted by ComDuck
|
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", "");
Re: Little coding questions - For general minor queries 5 -
ComDuck - 10.02.2019
Quote:
Originally Posted by justinnater
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://sampforum.blast.hk/showthread.php?tid=653362
Re: Little coding questions - For general minor queries 5 -
justinnater - 17.02.2019
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?
Re: Little coding questions - For general minor queries 5 -
Y_Less - 17.02.2019
Just don't use the built-in HTTP function at all. There are better plugins, such as "requests".
Re: Little coding questions - For general minor queries 5 -
CherryMond - 18.02.2019
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 KEY, A_I |
| pid | int(8) FOREIGN 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?
Re: Little coding questions - For general minor queries 5 -
ComDuck - 18.02.2019
Quote:
Originally Posted by CherryMond
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://sampwiki.blast.hk/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?
Re: Little coding questions - For general minor queries 5 -
Calisthenics - 18.02.2019
The design is OK. If you set pid+slot as UNIQUE key, you can use INSERT INTO .. ON DUPLICATE.
Quote:
Originally Posted by ComDuck
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.
Re: Little coding questions - For general minor queries 5 -
CherryMond - 18.02.2019
Thank you for your answer, in which case it will be as it is.
Re: Little coding questions - For general minor queries 5 -
Y_Less - 18.02.2019
Quote:
Originally Posted by ComDuck
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.
Re: Little coding questions - For general minor queries 5 -
v4yne1 - 26.02.2019
in which way do we make commands with multiple functions?
for example: /giveplayer [id]
[money/health/armor] [value]
thanks
Re: Little coding questions - For general minor queries 5 -
polygxn - 26.02.2019
Quote:
Originally Posted by v4yne1
in which way do we make commands with multiple functions?
for example: /giveplayer [id] [money/health/armor] [value]
thanks
|
HERE is a well-written tutorial about the whole thing. Good luck.
Re: Little coding questions - For general minor queries 5 -
v4yne1 - 26.02.2019
Quote:
Originally Posted by polygxn
HERE is a well-written tutorial about the whole thing. Good luck.
|
thanks man