SA-MP Forums Archive
Little coding questions - For general minor queries 5 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Little coding questions - For general minor queries 5 (/showthread.php?tid=30938)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46


AW: Little coding questions - For general minor queries 5 - Nero_3D - 06.07.2014

Well that is the problem, you can't determine what kind of array it is (and how big) because you can't tell the difference between a letter and a pointer (they are both just numbers)

You could use a 1d array with looks like "hello|world|" or something like that or you use a format parameter which tells the function how to parse the argument like sscanf does it

But if your function only takes 2d arrays than you could make it without it, you just need to pass the array
You can determine the size by the first pointer (it jumps over all other pointers and therefor it represents the size of the first dimension)

Well there is another way to extract something like that
pawn Code:
funcProcess2D(playerid, ...) {
    new
        arg,
        args,
        addr,
        size
    ;
    #emit addr.pri 12
    #emit stor.s.pri arg
    #emit load.s.alt 8
    #emit add
    #emit stor.s.pri args

    while((arg += 4) < args) {
        static
            tmp[1][1]
        ;
        #emit lref.s.pri arg
        #emit stor.s.pri addr
        #emit load.i
        #emit shr.c.pri 2
        #emit stor.s.pri size

        funcPhrase2D(playerid, addr, tmp, size);
    }
}

funcPhrase2D(playerid, addr, array[][], size) {
    #emit load.s.pri addr
    #emit stor.s.pri array
    // normal code work fine after here
    while(--size >= 0) {
        print(array[size]);
    }
}



Re: Little coding questions - For general minor queries 5 - Kwashiorkor - 06.07.2014

Thank you very much for your answer but it I think I need to have a look at #emit stuff first because I have no idea what's going on in your code

And, as you seem like a very competent person to me, could you please have a look at my fgetchar problem? https://sampforum.blast.hk/showthread.php?tid=523781


AW: Little coding questions - For general minor queries 5 - mindfck - 18.07.2014

i want to show a drawtext, but only after hiding the one showing, if there is one. how can i do that?


Re: Little coding questions - For general minor queries 5 - iFarbod - 04.09.2014

Quote:
Originally Posted by fall3n
Посмотреть сообщение
You should have a look over this topic. And then use this include to retrieve them.
Found a way. Thanks.

pawn Код:
new
    gSpentTime[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    //gSpentTime[playerid] = 0;
    gSpentTime[playerid] = gettime();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    gSpentTime[playerid] = gettime() - gSpentTime[playerid];
    return 1;
}



Re: Little coding questions - For general minor queries 5 - SheikhC - 04.09.2014

hello i need a simple command for rcon admin like this:

/playsound [sound id]

and everyplayer will hear that song

if you know the script that lsrp used at earthquake event

like when it is an event a rcon admin can play a sound like a horn or aomething


Re: Little coding questions - For general minor queries 5 - Kimossab - 05.09.2014

pawn Код:
CMD:playsound(playerid,params[])
{
    if(!IsAdmin(playerid)) return 1;
    new soundid;
    if(sscanf(params,"d",soundid)) return SendClientMessage(playerid,Error,"Use /playsound <soundid>");
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        if(!IsPlayerConnected(i))
            continue;
        PlayerPlaySound(i, soundid, 0.0, 0.0, 0.0);
    }
}



Re: Little coding questions - For general minor queries 5 - LivingLikeYouDo - 05.09.2014

Is there any snippet/release of ALL the attachments rotations/axis for every skins?


Re: Little coding questions - For general minor queries 5 - IamPRO - 06.09.2014

Anyone know the object id of this disk like object? or any similar objects? Please tell, i would appreciate it.



Re: Little coding questions - For general minor queries 5 - iFarbod - 08.09.2014

@IamPRO: It's a magent (I Think)

To validating an email address, which one should i use? (sscanf, regex)

And tell me a pattern, Thanks.


Re: Little coding questions - For general minor queries 5 - [HLF]Southclaw - 08.09.2014

sscanf can do that, I can't remember the optimal pattern but it would be something like this: "p<@>s[64]s[189]" (I could be wrong). Regex can also do this but all you need to do really is check if the string contains an @ and send them a confirmation email with a validation key/URL etc.


Re: Little coding questions - For general minor queries 5 - iFarbod - 09.09.2014

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
sscanf can do that, I can't remember the optimal pattern but it would be something like this: "p<@>s[64]s[189]" (I could be wrong). Regex can also do this but all you need to do really is check if the string contains an @ and send them a confirmation email with a validation key/URL etc.
Yep, Thanks, these emails are valid:

master@localhost
master@127.0.0.1
email@domain.me
email@sub.domain.me
new.email@example.co
test_email@test.io


Re: Little coding questions - For general minor queries 5 - Rodney Francalim - 22.09.2014

There is some way to make it better?

pawn Код:
new
    bool:b = true
;

b = ~b; // This line



Re: Little coding questions - For general minor queries 5 - LivingLikeYouDo - 22.09.2014

Would someone give me a link towards a tutorial explaining how inventory system works (using MySQL).

Highly appreciated.


Re: Little coding questions - For general minor queries 5 - kristo - 01.10.2014

pawn Code:
stock GetAttachedObjectPos(Float:object_px, Float:object_py, Float:object_pz, Float:object_rx, Float:object_ry, Float:object_rz, Float:offset_x, Float:offset_y, Float:offset_z, &Float:x, &Float:y, &Float:z)
{
    new
        Float:cos_x = floatcos(object_rx, degrees),
        Float:cos_y = floatcos(object_ry, degrees),
        Float:cos_z = floatcos(object_rz, degrees),
        Float:sin_x = floatsin(object_rx, degrees),
        Float:sin_y = floatsin(object_ry, degrees),
        Float:sin_z = floatsin(object_rz, degrees);

    x = object_px +
    offset_x * cos_y * cos_z - offset_x * sin_x * sin_y * sin_z -
    offset_y * cos_x * sin_z + offset_z * sin_y * cos_z +
    offset_z * sin_x * cos_y * sin_z;
    y = object_py +
    offset_x * cos_y * sin_z + offset_x * sin_x * sin_y * cos_z +
    offset_y * cos_x * cos_z + offset_z * sin_y * sin_z -
    offset_z * sin_x * cos_y * cos_z;
    z = object_pz -
    offset_x * cos_x * sin_y -
    offset_y * sin_x +
    offset_z * cos_x * cos_y;
    return 1;
}
Could someone reverse this function so I could get the offset from a vehicle/another object/etc? Thanks!


Re: Little coding questions - For general minor queries 5 - Rudy_ - 01.10.2014

Nvm sry


Re: Little coding questions - For general minor queries 5 - Evocator - 02.10.2014

Actually in adding an ignore function under OnPlayerText, so rather than using "SendClientMessageToAll" ill be using the most efficient foreach loop to prevent an ignored person. I run a common server (80-200 players at a time). Would this cause any lag? Can i continue my work or shall i leave this as for the SendClientMessageToAll?


Re: Little coding questions - For general minor queries 5 - denNorske - 04.10.2014

Hi guys!

Can someone show me a short example how i can sort players in a list by checking a variable? Like, if the player has a score like 20 and the other one has score 10 - How can i use a cmd to sort them Descending after who the leader is?
Leader: 20
Second place: 10
Third place .... And so on.

An Example could be a list sorting the richest players in a list, after who the leader is:
Richest: 999999999
second slot: 9999999
And so on..

- What is required?

Is this possible, and how can i do it? Thanks!


Re: Little coding questions - For general minor queries 5 - kristo - 04.10.2014

Quote:
Originally Posted by Ralfie
View Post
Alright thanks; 1 more question:

MapAndreas include by RyDer (https://sampforum.blast.hk/showthread.php?tid=273263)
OR
MapAndreas plugin by Kalcor (https://sampforum.blast.hk/showthread.php?tid=120013) ?

I just want to find a Z coord.
RyDeR's include uses a lot less RAM but kalcor's plugin is a lot faster. The include didn't work properly on my linux server (It gave random results) but the plugin was fine.

I would use this plugin, Mauzen has improved it a lot: https://sampforum.blast.hk/showthread.php?tid=275492


Re: Little coding questions - For general minor queries 5 - Kimossab - 05.10.2014

Quote:
Originally Posted by airplanesimen
View Post
Hi guys!

Can someone show me a short example how i can sort players in a list by checking a variable? Like, if the player has a score like 20 and the other one has score 10 - How can i use a cmd to sort them Descending after who the leader is?
Leader: 20
Second place: 10
Third place .... And so on.

An Example could be a list sorting the richest players in a list, after who the leader is:
Richest: 999999999
second slot: 9999999
And so on..

- What is required?

Is this possible, and how can i do it? Thanks!
Well sorting an array is kinda complicated and extremelly confusing (at least for me) so I'll give you an example, the bubblesort which for me is the easiest sorting method, but not the best. You can ****** array sort methods to find more and better ones. Anyway here's an example:

pawn Code:
//somewhere else: this is basically to put the list of current players on an array (it's unorganized by thevariable you want, but it's organized by player ids...
new array[MAX_PLAYERS], num=0;
for(new i=0; i<MAX_PLAYERS; i++)
{
    if(!IsPlayerConnected(i))
        continue;
    array[num] = i;
    num++;
}
array=bubblesort(aray, num);


stock bubblesort(a[], num)
{
    new aux; //we'll need this auxiliar variable
    for(new i=0; i<num; i++) //basically we'll need to search the array this ammount of times
    {
        for(new j=0; j<num-i; j++) //we'll put the lowest number in the end of the array, so we'll need to check which one it is and push it back, this loop will do the trick
        {
            if(GetPlayerScore(a[j])<GetPlayerScore(a[j+1])) //if the variable of j is lower than the adjacent position, then we should swap them, so the higher comes first.
            {
                aux=a[j+1];//save the adjacent one in the auxiliar variabe
                a[j+1]=a[j];//reset the adjacent cell
                a[j]=aux;//reset the current cell
            }
        }
    }
}

/* An example of what might happen in the bubblesort stock function
ID  SCORE
1   12
5   25
6   0
12  200
13  10
15  300

i   j   j(score)    j+1 j+1(score)  a       a(scores)
-   -           -           1 5 6 12 13 15  12 25 0 200 10 300
0   0   12      -           "       "
0   0   12      1   25      5 1 6 12 13 15  25 12 0 200 10 300
0   1   12      2   0       5 1 6 12 13 15  25 12 0 200 10 300
0   2   0       3   200     5 1 12 6 13 15  25 12 200 0 10 300
0   3   0       4   10      5 1 12 13 6 15  25 12 200 10 0 300
0   4   0       5   300     5 1 12 13 15 6  25 12 200 10 300 0

1   0   25      1   12      5 1 12 13 15 6  25 12 200 10 300 0
1   1   12      2   200     5 12 1 13 15 6  25 200 12 10 300 0
1   2   12      3   10      5 12 1 13 15 6  25 200 12 10 300 0
1   3   10      4   300     5 12 1 15 13 6  25 200 12 300 10 0

2   0   25      1   200     12 5 1 15 13 6  200 25 12 300 10 0
2   1   25      2   12      12 5 1 15 13 6  200 25 12 300 10 0
2   2   12      3   300     12 5 15 1 13 6  200 25 300 12 10 0

3   0   200     1   25      12 5 15 1 13 6  200 25 300 12 10 0
3   1   25      2   300     12 15 5 1 13 6  200 300 25 12 10 0

4   0   200     1   300     15 12 5 1 13 6  300 200 25 12 10 0
*/
This example is for an array, but if you want sort players then I suggest using an array, but base yourself in this code to make your own. good luck


Re: Little coding questions - For general minor queries 5 - denNorske - 05.10.2014

A thanks, that looks interesting, i will test it.

Thanks