SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 08/12/2009, 08:46 PM   #571
StrickenKid
Gangsta
 
Join Date: Feb 2009
Posts: 762
Reputation: 44
Default Re: Useful Functions

Someone should really change that wiki page so newbs don't get mixed up...
__________________
StrickenKid is offline   Reply With Quote
Old 09/12/2009, 11:19 AM   #572
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 2,628
Reputation: 136
Default Re: Useful Functions

[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 Code:
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
__________________


NEW: [FS] Simple Cellphones

if( strfind( title, "REP", true ) != -1 )
{________________________________________
Sigh();__________________________
}________________________________________


LarzI is offline   Reply With Quote
Old 15/12/2009, 02:43 PM   #573
thegoliathmaster
Little Clucker
 
thegoliathmaster's Avatar
 
Join Date: Aug 2008
Posts: 20
Reputation: 0
Default Re: Useful Functions

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)

Code:
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:
Code:
new input[] = "Hello, this is a testing!";
new begin = 5, destination[16];
strtok(input, begin, destination);
print(destination);
instead of:
Code:
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++
thegoliathmaster is offline   Reply With Quote
Old 15/12/2009, 03:13 PM   #574
LarzI
High-roller
 
LarzI's Avatar
 
Join Date: Apr 2007
Location: Norway
Posts: 2,628
Reputation: 136
Default Re: Useful Functions

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


NEW: [FS] Simple Cellphones

if( strfind( title, "REP", true ) != -1 )
{________________________________________
Sigh();__________________________
}________________________________________


LarzI is offline   Reply With Quote
Old 15/12/2009, 03:24 PM   #575
thegoliathmaster
Little Clucker
 
thegoliathmaster's Avatar
 
Join Date: Aug 2008
Posts: 20
Reputation: 0
Default Re: Useful Functions

Yes, i'm sure.

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

Code:
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++
thegoliathmaster is offline   Reply With Quote
Old 15/12/2009, 03:33 PM   #576
Zeex
Guest
 
Posts: n/a
Default Re: Useful Functions

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

pawn Code:
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 With Quote
Old 15/12/2009, 05:14 PM   #577
Zeex
Guest
 
Posts: n/a
Default Re: Useful Functions

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 With Quote
Old 19/12/2009, 05:17 PM   #578
[HUN]Gamestar
Big Clucker
 
Join Date: Aug 2009
Posts: 138
Reputation: 3
Default Re: Useful Functions

pawn Code:
stock IsFindIp(str[]) {
  new x=0,n=0,p=0;
  while(str[x]!=strlen(str)) {
    if((str[x]>='0') && (str[x]<='9'))n++;
    if(str[x]=='.')p++;
    x++;
  }
  return ((n>=4)&&(p>=3)) ? true : false;
}
Example:
pawn Code:
public OnPlayerText(playerid,text[])if(IsFindIp(text))return 0;

pawn Code:
stock GivePlayerHealth(playerid,Float:h) {
  new Float:x,Float:j;
  GetPlayerHealth(playerid,x);

  j=(x+h);

  if(j>100.0000) j=100.0000;
  SetPlayerHealth(playerid,j);
  return 1;
}

V2 (?: operator):
pawn Code:
stock GivePlayerHealth(playerid,Float:h) {
  new Float:x,Float:j;
  GetPlayerHealth(playerid,x);

  j=(x+h);

  SetPlayerHealth(playerid,( j>100.0000 ? 100.0000 : j ));
  return 1;
}
[HUN]Gamestar is offline   Reply With Quote
Old 19/12/2009, 05:44 PM   #579
pagie1111
Huge Clucker
 
Join Date: Dec 2008
Posts: 463
Reputation: 20
Default Re: Useful Functions

Just a little time saver for me:

pawn Code:
stock ReturnName(playerid, var[MAX_PLAYER_NAME])
{
    GetPlayerName(playerid,var,sizeof(var));
    return var;
}

Example:
pawn Code:
new name[MAX_PLAYER_NAME];
ReturnName(playerid,name);
SendClientMessageEx(playerid,0xFFFFFFF,"%s is your name",name);

Name = Awaran
Returns:
Code:
Awaran is your name
__________________
Have just returned to SA:MP as of 21/07/2015
Will be reviewing one of my old scripts and releasing a new version!
+1 rep

________________________________________________
pagie1111 is offline   Reply With Quote
Old 19/12/2009, 05:48 PM   #580
Remi-X
Huge Clucker
 
Join Date: Dec 2008
Posts: 296
Reputation: 0
Default Re: Useful Functions

Why not
pawn Code:
stock PlayerName(playerid){
  new pname[24];
  GetPlayerName( playerid, pname,24 );
  return pname;
}
pawn Code:
SendClientMessageEx( playerid, 0xFFFFFFF, "%s is your name", PlayerName(playerid) );
Much easier..

@Below me: Yes, I am :P
Remi-X 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
[Include] [INC] LSF - Lorenc's Simple Functions (w/ gang/clan functions) Lorenc_ Includes 14 21/04/2018 04:06 AM
Functions? sciman001 Help Archive 7 19/03/2011 03:03 PM
How to get functions? Twain32 Help Archive 4 08/10/2010 07:37 PM
[Include] [INC] SA:MP New Functions 0.4a DKN ipsBruno Lançamentos/Releases 22 17/06/2010 08:38 AM
What this functions do? harrold Help Archive 2 08/05/2009 11:30 PM


All times are GMT. The time now is 12:33 PM.


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