Little coding questions - For general minor queries 5

Quote:
Originally Posted by 0xAAAAAA
Посмотреть сообщение
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:
pawn Код:
// 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.
pawn Код:
// 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.
Reply

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
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:
pawn Код:
// 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.
pawn Код:
// 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?
Reply

Quote:
Originally Posted by 0xAAAAAA
Посмотреть сообщение
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.
pawn Код:
Streamer_SetIntData(STREAMER_TYPE_PICKUP, House[house_index_here][Pickup], E_STREAMER_MODEL_ID, new_pickup_modelid_here);
Reply

I'm trying to use
pawn Код:
enum (--) { // or enum (-= 1)
  VAR_ONE = -1,
  VAR_TWO,
  VAR_THREE
};
But i'm getting a syntax error:
Код:
error 001: expected token: ")", but found "--"
Am i doing it wrong or this is impossible?
Reply

Try (-=1), I know it's possible but I forgot the exact constraints for that syntax. It may need an enum name.
Reply

Quote:
Originally Posted by Ermanhaut
View Post
I’m trying to use

Code:
enum (--) { // or enum (-= 1)
  VAR_ONE = -1,
  VAR_TWO,
  VAR_THREE
};
But i’m getting a syntax error:
Code:
 error 001: expected token: “)”, but found “–”
Am i doing it wrong or this is impossible?
I don’t know why that doesn’t work. I can’t think of a good reason to not allow it. However, for now this does work:

Code:
enum (+= -1)
{
    A, B, C
}
Reply

Quote:
Originally Posted by Y_Less
Посмотреть сообщение
I don’t know why that doesn’t work. I can’t think of a good reason to not allow it. However, for now this does work:

Код:
enum (+= -1)
{
    A, B, C
}
Now it works!

I don't know either.
Maybe it's a bug of the pawn-lang community compiler.
Reply

Actually, I checked pawn-lang.pdf and it explicity says that only `+=`, `*=`, and `<<=` are valid. Why others aren't, I don't know, but I guess the logic was the default start is 0 and negative array indexes aren't valid. Also, you could just start at the other end and increment instead of decrement.
Reply

Not sure if this is the right place or not, but what is the best method to convert time stamps to human-readable date. Are there any alternatives to TimeStamp2Date include?
Reply

https://sampforum.blast.hk/showthread.php?tid=654663
Reply

I've been out of the loop for a while. What's currently the best way to hash a password? I always used Whirlpool on my older gamemodes, but I'm not sure if that's still the best choice.
Reply

Quote:
Originally Posted by Gforcez
View Post
I've been out of the loop for a while. What's currently the best way to hash a password? I always used Whirlpool on my older gamemodes, but I'm not sure if that's still the best choice.
The best way to hash a password is to use a strong hashing algorithm like Whirlpool and use it the following method:
Hash=(Password+Salt)

Although it is just easier to use the bcrypt plugin as it also does hashing and iterations for you.
Reply

Quote:
Originally Posted by Jeroen52
View Post
The best way to hash a password is to use a strong hashing algorithm like Whirlpool and use it the following method:
Hash=(Password+Salt)

Although it is just easier to use the bcrypt plugin as it also does hashing and iterations for you.
I'm working with hashing, I'm just not sure if Whirlpool is still decent or if there's some new algorithm that's more secure or better. I'll check out bcrypt thanks!
Reply

PHP Code:
new Float:pos[3];
pos = {-888.6017,1515.5992,26.2831}; // like this? no
pos[3] = {-888.6017,1515.5992,26.2831}; // like this? hmm... no
pos[] = {-888.6017,1515.5992,26.2831}; // maybe this? hell no 
How in oblivion do I assign values to an array in this way?
Reply

I believe that's only valid during initialisation and as arguments to functions.
Reply

Like Southclaw said but that doesn't stop you from using it
pawn Code:
new Float:pos[3];
static const Float: _pos[sizeof pos] = {-888.6017,1515.5992,26.2831}; // static is you use it locally
pos = _pos;
Reply

how can i check the ground under me using ColAndreas? I am trying to make a horse system using setplayervelocity and i don't want the player flying around when he's on a clif and moves over it.. i'm looking in the include but i don't find a solution to it
Reply

Hello sampers, I was wondering what's the difference between "#define something 5" and "#define something (5)"?
Reply

One has brackets, the other doesn't.
Reply

Having the bracket makes the number definition more "strict", if i remember right if you define them without bracket, you can put it between strings as a constant, or probably also "mix" it with another numbers/defines especially in calculation, the bracket helps you give an error at compile time when you improperly uses it/accidentally mistyped it. It is just a practice...

(Sry replying from phone)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)