Useful Functions

Quote:
Originally Posted by Luka P.
Посмотреть сообщение
@Huzzy

wiki.sa-mp.com/wiki/GetPlayerPos
wiki.sa-mp.com/wiki/SetPlayerPos
Ty man

wiki.sa-mp.com/wiki/GetPlayerPos

Really helped but the

wiki.sa-mp.com/wiki/SetPlayerPos

didnt.As it says it will Tp the play to the middle of SA :S Whats the point of that :S
Reply

Cheaters got the ability to change their player state. So tbh the PVar method would be better, but of course the other one is the best one if you ignore the cheater part in my message :P
Reply

This are macros, not functions, but I'll post them anyway.
It's not "useful", it just keeps my script tidy.

pawn Код:
#define SECONDS(%1)             ((%1)*(1000))
#define MINUTES(%1)             ((%1)*(60*1000))
#define HOURS(%1)               ((%1)*(60*60*1000))
Reply

Nice but should this work ?

pawn Код:
SetTimer("anything",(HOURS(1)+MINUTES(30)),false);
?
Reply

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
You set the coordinates, it can teleport you to any part of the map.

SetPlayerPos(0.0, 0.0, 0.0), the '0.0' parts are coordinates, 3 sets of them separated by commas: ',' one for X axis [east and west] one for Y axis [north and south] and one for Z [Height], coordinates are always in the order XYZ.

'0.0, 0.0, 0.0' is the center of the map, no meters east, west, north or south.

so if your coordinate was south of the center of the map, it would be '0.0, -10.0, 0.0',
east [right if you're looking north] would be '10.0, 0.0, 0.0'
west would be '-10.0' not '10.0', because the center of the map is 0.0 so you use minus values for anywhere behind this.

Hope that cleared that up
That helps alot mate.But i wanted the players to be teleported to where they logged out.
Reply

We don't know how your account load/save system works, therefore we're only able to give you the functions you'll need. You need to get player coordinates OnPlayerDisconnect, then save it to a file/database and then after player login again load the coordinates from the file/database and set the player position.
Reply

It does save it on the data base as you can see it here:

Ip=94.123.100.163
Registered=1
RegisteredDate=22/10/2010
Loggedin=0
Banned=0
Level=0
AccountType=0
LastOn=22.10.2010
Money=0
Kills=0
Deaths=0
WantedLevel=0
Score=0
Hours=0
Minutes=2
Seconds=25
NoQuestion=0
Question=acun
QuestionR=A6F927F25D4E4CACA44728FCD3E9C9125735E479 39B5657C814FB4F87BF2875433B7B2707B7548A6C629B24D5F 37840D731DC0887E4E58AF5CBA6DF8B619FEB0
x1=1778
y1=1264
z1=7
interior1=0
Weapon1=0
Weapon1Ammo=0
Weapon2=0
Weapon2Ammo=0
Weapon3=0
Weapon3Ammo=0
Weapon4=0
Weapon4Ammo=0
Weapon5=0
Weapon5Ammo=0
Weapon6=0
Weapon6Ammo=0
Health=83
Armour=0
TimesOnServer=1


But i only need when player reconnects.
Reply

Any suggestions or request as function you guys want? Please tell me ^^
Reply

I was thinking of this the other day, and it's probably possible.

Get two sets of coordinates: xyz1 xyz2

detect if the player is one direction past the line between the two sets of co-ords.

something like that

Code:
     x < position 2
    /
   /
  /x < player position
 /
x < position 1
I had an idea of how it would be done but I forgot


It's a bit like IsPlayerInArea, but with a line, and it can be diagonal.

Just a brainstorm, someone can see if they can make it into a code.
Reply

Southclaw, this is very easy! I'll give you a GetDistanceFromPointToLine function. (fast one, no loop)

//EDIT: Here you go!

pawn Code:
#include <a_samp>

#if defined _gdfptl_included
    #endinput
#endif
#define _gdfptl_included

/*
native crossp(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:output);
native GetDistanceFromPointToLine(&Float:distance, Float:line_vector_x, Float:line_vector_y, Float:line_vector_z, Float:line_x, Float:line_y, Float:line_z, Float:point_x, Float:point_y, Float:point_z);
*/


stock crossp(Float:v1x, Float:v1y, Float:v1z, Float:v2x, Float:v2y, Float:v2z, &Float:output)
{
    new
        Float:c1 = (v1y * v2z) - (v1z * v2y),
        Float:c2 = (v1z * v2x) - (v1x * v2z),
        Float:c3 = (v1x * v2y) - (v1y * v2x);
    output = floatsqroot ((c1 * c1) + (c2 * c2) + (c3 * c3));
    return 0;
}

stock GetDistanceFromPointToLine(&Float:distance, Float:line_vector_x, Float:line_vector_y, Float:line_vector_z, Float:line_x, Float:line_y, Float:line_z, Float:point_x, Float:point_y, Float:point_z)
{
    //A line is defined by a point (which is on the line (line_x/y/z)) and a vector which defines the direction (line_vector_x/y/z).
    new Float:output;
    crossp(line_vector_x, line_vector_y, line_vector_z, point_x - line_x, point_y - line_y, point_z - line_z, output);//Cross product of 2 vectors.
    distance = output / floatsqroot ((line_vector_x * line_vector_x) + (line_vector_y * line_vector_y) + (line_vector_z * line_vector_z));
    return 0;
}
Save it as include to be able to use the native declaration for easier usage (display for arguments).
This function could be used for a very effective head shot script!

All headshots script I have seen in this forum were using loops to check if a player is aiming at the head of someone. This is not efficient.

Solution:
The cross product of the camera vector and the vector defined by the camera position and the position of the players head.
Reply

uhm Ryder just a suggestion, can you make something so like when someone types like this...

Heyyyy! (Beginning of the line starts with a space)
Heeeeyy! Whats up?!?! (Has more than one space)

Takes the spaces out or doesn't let them send the line? and so if they type ~ then it don't send the line either? If so that be great for me.
Reply

pawn Код:
public OnPlayerText( playerid, text[ ] )
{
    if ( text[ 0 ] == ' ' || text[ 0 ] == '~' )
        return 0;
   
    return 1;
}
Reply

@g_aSlice:
It's not complete.

pawn Код:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "~", true) != -1 || !text[0]) return 0;
    new
        i
    ;
    for( ; (text[i] != '\0' && text[i] <= ' ') ; ) ++i;
    strmid(text, text, i, strlen(text), 128);
    return 1;
}
This should work. Didn't test it yet.
Reply

oh, i didn't get what he meant yesterday.
Reply

Didn't work Ryder, it just auto spaces where the first letter should be. ( http://tinypic.com/r/r0eff9/7 )

EDIT: the ~ worked though thanks!
Reply

The forum did what he wanted, it removes useless spaces before and between words so we couldnt understand what he exactly wanted

With that it should be clear
Quote:
Originally Posted by willsuckformoney
View Post
Code:
 Heyyyy!                   (Beginning of the line starts with a space)
Heeeeyy!     Whats up?!?!  (Has more than one space)
Try that
pawn Code:
public OnPlayerText(playerid, text[])
{
    if(strfind(text, "~", true) != -1) return 0;
    for(new i, j; ; i++) {
        switch(text[i]) {
            case EOS: break;
            case ' ': {
                for(j = i; text[++j] == ' '; ) {}
                if(i == 0) {
                    strdel(text, 0, j); //Dont know if other string functions are better ^^"
                } else {
                    strdel(text, (i + 1), j);
                }
            }
        }
    }
}
Reply

There should be
SlapPlayer(playerid);
Reply

Can you just break that up for the spaces only? The ~~~~ one works already.
Reply

Quote:
Originally Posted by willsuckformoney
Посмотреть сообщение
Can you just break that up for the spaces only? The ~~~~ one works already.
You should just delete this line:
pawn Код:
if(strfind(text, "~", true) != -1) return 0;
or delete mine and use his completely
Reply

About to test, keeping the ~ that you made since I'm to lazy to delete it.

EDIT: The space still doesn't work.
Reply


Forum Jump:


Users browsing this thread: 15 Guest(s)