Useful Functions

Quote:
Originally Posted by <__Ǝthan__>
Yes, and that's wrong, this is how it is:

Код:
   north (0)
    |
(90)west- -east (270)
    |
   south (180)
wrong

Код:
    north (0)
     |
(270)west- -east (90)
     |
   south (180)
Reply

Quote:
Originally Posted by radi
wrong

Код:
   north (0)
    |
(270)west- -east (90)
    |
   south (180)
Please don't post if you don't know.
Reply

Quote:
Originally Posted by 0rb
Quote:
Originally Posted by radi
wrong

Код:
    north (0)
     |
(270)west- -east (90)
     |
   south (180)
Please don't post if you don't know.
No, he's right. It shouldn't be like that but it is in San Andreas - https://sampwiki.blast.hk/wiki/SetPlayerFacingAngle
Reply

Someone should really change that wiki page so newbs don't get mixed up...
Reply

[size=14px]GetPlayerPosInt(playerid, &Float, &Float:y, &Float:z, &interior);[/size]
playerid - id of the player you want to return values from.
&Float, &Float:y, &Float:z, &interior - variables for x-coord, y-coord, z-coord and interior


pawn Код:
stock GetPlayerPosInt(playerid, &Float:x, &Float:y, &Float:z, &interior)
{
  GetPlayerPos(playerid, x, y, z);
  interior = GetPlayerInterior(playerid);
}
Should work, lol xp

EDIT: Thanks Seif_ :P
Reply

Hi,

this is something everyone knows, but i HATE the usual implementation, so i made one, it is faster btw (takes about 2/3 of the original time)

Код:
stock strtok(const source[], &index, dest[], separator = ' ')
{
	new i = 0;
	while((dest[i] = source[index]))//while we've not reached the end of the string
	{
		if(source[index] != separator)//if the separator isn't reached yet
		{
			index++;//increment the variables
			i++;
		}
		else//on est rendu au sйparateur
		{
			index++;//we go to the next character (skip the separator)
			dest[i] = EOS;//in cas of troubles
			break;
		}
	}
}
have fun :P

use:
Код:
new input[] = "Hello, this is a testing!";
new begin = 5, destination[16];
strtok(input, begin, destination);
print(destination);
instead of:
Код:
new input[] = "Hello, this is a testing!";
new begin = 5, destination[16];
destination = strtok(input, begin);
print(destination);
note: this function is faster and safer, you don't need to worry about the length of an internal string, just care about yours.
edited function to make sure it is safe...

++Sim++
Reply

And you're 100% sure that this code is working fully as the original strtok code?
If so, good job!
Reply

Yes, i'm sure.

i've been using it for about 3 month now...
but the version i used had a little

Код:
dest[i] = EOS;
at the end to prevent problems with second use of a string, but after testing, the while loop is supposed to do it as-well (maybe not if your reach the separator, i'll check it)

++Sim++
Reply

It may be even better if we will use static variable to hold the start of the next word:

pawn Код:
stock strtok(const source[], dest[], separator = ' ', start = -1)
{
    if (!source[0])
    {
        return 0;
    }
    new
        i,
        ch;
    static
        j;
    if (start == 0)
    {
        j = 0;
    }
    else if (start > 0)
    {
        j = start;
    }
    while ((ch = source[j++]))
    {
        if (ch != separator)
        {
            dest[i] = ch;
            i++;
        }
        else
        {
            while (source[++j] == separator) {}
            break;
        }
    }
    dest[i] = '\0';
    return i;
}
So we don't need to create a separate variable somewhere outside of function each time to store the index...
Reply

What do you mean? Sorry I dont fully understand what you said (****** translator sucks).... But I still want to know. Could you give some code?
Reply

Thank you,problem fixed.
Reply

Quote:
Originally Posted by .:: ZeX ::.
Thank you,problem fixed.
No problem
Reply

pawn Код:
stock DisconnectNPC(npcname[]) {
    new
        n[MAX_PLAYER_NAME],x=0;
    while(x!=GetMaxPlayers()) {
        GetPlayerName(x,n,sizeof n);
        if(!strcmp(n,npcname,true)) break;
        x++;
    }
    if(x==GetMaxPlayers())return INVALID_PLAYER_ID;
    Kick(x);
    return 1;
}
other job: usefull function in include.
Reply

Quote:
Originally Posted by Luka™
SetPlayerHealth doesn't work with float in 0.3, but with integer
Don't give false informations.
Reply

Quote:
Originally Posted by 0rb
Quote:
Originally Posted by Luka™
SetPlayerHealth doesn't work with float in 0.3, but with integer
Don't give false informations.
First try code then post a message
Reply

Quote:
Originally Posted by .:: ZeX ::.
pawn Код:
#define KillPlayer(%1) if(IsPlayerConnected(%1)) SetPlayerHealth(%1,0.0000)
#define HealPlayer(%1) if(IsPlayerConnected(%1)) SetPlayerHealth(%1,100.0000)
I think there is no need to check the connection as it woudln't crash your server if the player isn't connected as it has built-in checking AFAIK.

Quote:
Originally Posted by Luka™
Quote:
Originally Posted by 0rb
Quote:
Originally Posted by Luka™
SetPlayerHealth doesn't work with float in 0.3, but with integer
Don't give false informations.
First try code then post a message
Quote:
Originally Posted by a_players.inc
native SetPlayerHealth(playerid, Float:health);
Reply

I made this one so you dont have to do

SetPlayerPos
As well as SetPlayerFacingAngle

pawn Код:
stock SetPlayerPosAndAngle(playerid,Float:x,Float:y,Float:z,Float:ang)
{
SetPlayerPos(playerid,x,y,z);
SetPlayerFacingAngle(playerid,ang);
}
Reply

Quote:
Originally Posted by KyleSmith
I made this one so you dont have to do

SetPlayerPos
As well as SetPlayerFacingAngle

pawn Код:
stock SetPlayerPosAndAngle(playerid,Float:x,Float:y,Float:z,Float:ang)
{
  SetPlayerPos(playerid,Float:x,Float:y,Float:z);
  SetPlayerFacingAngle(playerid,Float:ang);
}
nice but you dont need to declare each time you use the variable as a floating number again if you did it at the definition
and you could try to make that function as an macro (#define balba) because that would make it faster
Reply

Fixed it.
Reply

Quote:
Originally Posted by KyleSmith
pawn Код:
stock DisarmPlayer(playerid)
{
ResetPlayerWeapons(playerid);
}
LOL! That's like
pawn Код:
stock GetPlayerID(playerid) return playerid;
xD xD xD
Reply


Forum Jump:


Users browsing this thread: 28 Guest(s)