SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 09/09/2018, 04:35 AM   #4571
coool
Gangsta
 
coool's Avatar
 
Join Date: Feb 2013
Location: Republic of Pakistan
Posts: 587
Reputation: 34
Default Re: Little coding questions - For general minor queries 5

use a 'where' clause
PHP Code:
SELECT `nameFROM `accountsWHERE `account id` = 0
//accounts is the name of table where you store your Users' data. 
__________________
coool is offline   Reply With Quote
Old 09/09/2018, 08:33 AM   #4572
KinderClans
Gangsta
 
KinderClans's Avatar
 
Join Date: May 2018
Location: Italy
Posts: 532
Reputation: 32
Default Re: Little coding questions - For general minor queries 5

And to show it in a message?
__________________
LSS RP Discord: https://discord.gg/M9c9PjN

Against everyone and everything.

I'll have two number 9s, a number 9 large, a number 6 with extra dip, a number 7, two number 45s, one with cheese... and a large soda.

Quote:
Originally Posted by UFF View Post
Donated my eyes after seeing this thread.
KinderClans is offline   Reply With Quote
Old 20/09/2018, 08:00 AM   #4573
0xAAAAAA
Little Clucker
 
Join Date: Aug 2018
Posts: 5
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Hello. In a house system, when player stands near the entrance pickup of a house, and types /buyhouse, he gets a dialog, which he should either submit or cancel, if player submits it, then on response of this dialog there should be all the stuff with money and mysql queries. The problem is that when player types /buyhouse, server loops through all houses (which might be over 2000 on a server), to find at which house's entrance the player is at, then on respone of the dialog there is the same loop, to get id of the house again. So this is kind of ineficcient to do those 2 loops, a solution that comes to my mind is to store the id of the house in a special variable in player's enum when he types /buyhouse, then use the value in it in the ondialogresponse function, but is this a bad practice?
P.S. by id of house i mean the index of it in the array of houses, and i obviously need to change variables in it after it's purchased.
0xAAAAAA is offline   Reply With Quote
Old 20/09/2018, 08:50 AM   #4574
Calisthenics
Huge Clucker
 
Join Date: May 2018
Posts: 276
Reputation: 48
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by 0xAAAAAA View Post
Hello. In a house system, when player stands near the entrance pickup of a house, and types /buyhouse, he gets a dialog, which he should either submit or cancel, if player submits it, then on response of this dialog there should be all the stuff with money and mysql queries. The problem is that when player types /buyhouse, server loops through all houses (which might be over 2000 on a server), to find at which house's entrance the player is at, then on respone of the dialog there is the same loop, to get id of the house again. So this is kind of ineficcient to do those 2 loops, a solution that comes to my mind is to store the id of the house in a special variable in player's enum when he types /buyhouse, then use the value in it in the ondialogresponse function, but is this a bad practice?
P.S. by id of house i mean the index of it in the array of houses, and i obviously need to change variables in it after it's purchased.
You can avoid the 2 loops if you use streamer. In data manipulation, there is an item in enumerator called E_STREAMER_EXTRA_ID. When you create the pickup for the first time, set the array index to it. I'll give an example:
Code:
// looping through all rows
// create a global variable and set value equal to the houses loaded. 
// Let's call it "HousesLoaded". Say you have loaded 1500 houses so "HousesLoaded" is equal to 1500
House[i][Pickup] = CreateDynamicPickup(...);
Streamer_SetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID, i + 2000);
// native Streamer_SetIntData(type, id, data, value);
Streamer_SetIntData returns 0 if none is set, I think. This is one of the reason I did not use "i" as value but used "i + 2000" instead. You may use it in other systems so you need a way to recognize what type of pickup it is. You can use values to identify. In this case, 2000 + MAX_HOUSES, 4000 + MAX_SOMETHING_ELSE etc.

There is entrance pickup, when OnPlayerPickUpDynamicPickup is called you check for the type.
Code:
// native Streamer_GetIntData(type, id, data);
new extra_id = Streamer_GetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID);

// now we want to check if subtracting 2000 from it will give us a range of 0-HousesLoaded.
if (0 <= (extra_id - 2000) <= HousesLoaded)
{
    // okay, the type of pickup is house. alternative way might be to check the pickup modelid.
    // now we'll store to another global variable the last house.
    Player[playerid][Last_House] = extra_id - 2000;

    // whenever you want to check now if the player is near a house, you can check if the player is in range with the last house
    // you know the house index and you know the position

    // show dialog to submit or cancel
}
Now on dialog response, you apply the same method. You know the last house the player pickup.
Calisthenics is offline   Reply With Quote
Old 20/09/2018, 09:28 AM   #4575
0xAAAAAA
Little Clucker
 
Join Date: Aug 2018
Posts: 5
Reputation: 0
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by Calisthenics View Post
You can avoid the 2 loops if you use streamer. In data manipulation, there is an item in enumerator called E_STREAMER_EXTRA_ID. When you create the pickup for the first time, set the array index to it. I'll give an example:
Code:
// looping through all rows
// create a global variable and set value equal to the houses loaded. 
// Let's call it "HousesLoaded". Say you have loaded 1500 houses so "HousesLoaded" is equal to 1500
House[i][Pickup] = CreateDynamicPickup(...);
Streamer_SetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID, i + 2000);
// native Streamer_SetIntData(type, id, data, value);
Streamer_SetIntData returns 0 if none is set, I think. This is one of the reason I did not use "i" as value but used "i + 2000" instead. You may use it in other systems so you need a way to recognize what type of pickup it is. You can use values to identify. In this case, 2000 + MAX_HOUSES, 4000 + MAX_SOMETHING_ELSE etc.

There is entrance pickup, when OnPlayerPickUpDynamicPickup is called you check for the type.
Code:
// native Streamer_GetIntData(type, id, data);
new extra_id = Streamer_GetIntData(STREAMER_TYPE_PICKUP, House[i][Pickup], E_STREAMER_EXTRA_ID);

// now we want to check if subtracting 2000 from it will give us a range of 0-HousesLoaded.
if (0 <= (extra_id - 2000) <= HousesLoaded)
{
    // okay, the type of pickup is house. alternative way might be to check the pickup modelid.
    // now we'll store to another global variable the last house.
    Player[playerid][Last_House] = extra_id - 2000;

    // whenever you want to check now if the player is near a house, you can check if the player is in range with the last house
    // you know the house index and you know the position

    // show dialog to submit or cancel
}
Now on dialog response, you apply the same method. You know the last house the player pickup.


I actually used a similar system before (i was checking if the pickup id was between the first loaded pickup of house #1 and the last loaded pickup of the last loaded house #n, and then i did something like pickupid modulus 2, since i have 2 pickups at each house, to determine whether the player is at the entrance or at the exit of the house), but i was told by someone on the forum that pickups might not always be consistent with their ids, for example when a house is purchased it must change its pickup icon (so i delete the old one and create new), and players might be purchasing houses at the same time, so houses might mess up their pickup ids. Is this still a thing with the streamer method? Can i really trust the pickup ids? And thank you for answer!

Edit: As i understood now, Streamer_SetIntData can change ids of dynamic pickups?
0xAAAAAA is offline   Reply With Quote
Old 20/09/2018, 09:51 AM   #4576
Calisthenics
Huge Clucker
 
Join Date: May 2018
Posts: 276
Reputation: 48
Default Re: Little coding questions - For general minor queries 5

Quote:
Originally Posted by 0xAAAAAA View Post
I actually used a similar system before (i was checking if the pickup id was between the first loaded pickup of house #1 and the last loaded pickup of the last loaded house #n, and then i did something like pickupid modulus 2, since i have 2 pickups at each house, to determine whether the player is at the entrance or at the exit of the house), but i was told by someone on the forum that pickups might not always be consistent with their ids, for example when a house is purchased it must change its pickup icon (so i delete the old one and create new), and players might be purchasing houses at the same time, so houses might mess up their pickup ids. Is this still a thing with the streamer method? Can i really trust the pickup ids? And thank you for answer!
On second thought, it might not be consistent if a new house is created during run time.

I also mentioned an alternative way, you can combine pickup modelid + extra id. You may keep the exterior pickup only and change to a checkpoint inside interiors to avoid complication. This way, you can easily retrieve the house index using the combination of the two.

As for the re-creation of the pickup when it is sold/bought, use the data manipulation and just alter the pickup modelid. Do not destroy and create again.
Code:
Streamer_SetIntData(STREAMER_TYPE_PICKUP, House[house_index_here][Pickup], E_STREAMER_MODEL_ID, new_pickup_modelid_here);
Calisthenics 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
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 11:16 PM.


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