SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Discussion

Reply
 
Thread Tools Display Modes
Old 18/02/2018, 09:41 PM   #751
rfr
Banned
 
Join Date: Nov 2017
Posts: 306
Reputation: 43
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Eoussama View Post
Today I learned about a simple BATCH instruction that serves as a cool hack when testing/debugging.

1- First, open any text editor, and paste the following instructions
PHP Code:
@echo off

:s
samp
-server.exe
goto 
2- Save the file as something.bat
3- Run the .bat file

Now, whenever you change your code source and compile, no need to exit and re-execute your samp-server.exe, just type the exit command in the console, and it will automatically close and re-open it for you.
can't you write gmx on the console?
rfr is offline   Reply With Quote
Old 19/02/2018, 02:00 PM   #752
Gforcez1337
High-roller
 
Gforcez1337's Avatar
 
Join Date: Jul 2010
Location: The Netherlands.
Posts: 1,076
Reputation: 367
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by rfr View Post
can't you write gmx on the console?
That restarts the gamemode, not the entire server.
__________________

Gforcez1337 is offline   Reply With Quote
Old 02/03/2018, 01:29 PM   #753
Mobtiesgangsa
Big Clucker
 
Mobtiesgangsa's Avatar
 
Join Date: Oct 2016
Location: Skopje, Macedonia
Posts: 86
Reputation: 9
Default Re: Today I learned - Share your newly found knowledge!

today i learned.... what means strtok

basicly strtok means

str - is a string == 1
tok - is a token == 2

strtok(const string[], &index)

1. its porpuse is to fetch textual declaration like the callback know as 'OnPlayerCommandText' with the parameters (playerid, cmdtext[])

2. tokes porpuse is to check indexe's or the given parameter of 'playerid'

here on the given example will show you how its done

example code:

Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
        new cmd[256+1], index;

        cmd = strtok(cmdtext, index);

        if(strcmp(cmd, "/info", true : false, 5)) < bool either its true or false
        {
                return true, false; < either it returns true or false
        }
        return false;
}
__________________
YSI User

Code:
public e_COMMAND_ERRORS:OnPlayerCommandReceived(playerid, cmdtext[], e_COMMAND_ERRORS:success)
{
	switch(success)
	{
	    case COMMAND_UNDEFINED:
	    {
		    TextDrawShowForPlayer(playerid, cmdinfo[playerid]);
		    SetTimerEx("UnknownCommand", 3000, false, "d", playerid);
	    }
	}
	return COMMAND_OK;
}
Mobtiesgangsa is offline   Reply With Quote
Old 06/03/2018, 05:01 PM   #754
GaByM
Big Clucker
 
GaByM's Avatar
 
Join Date: Jan 2014
Location: Romania
Posts: 111
Reputation: 7
Default Re: Today I learned - Share your newly found knowledge!

TIL that you can split a macro on multiple lines with '\'

PHP Code:
#define add(%0,%1) ((%0)+(%1))

main()
{
    
printf("%i",
        
        
add(\
            
5\
            ,\
            
6\
            )

        );

GaByM is offline   Reply With Quote
Old 06/03/2018, 06:15 PM   #755
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,265
Reputation: 227
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by GaByM View Post
TIL that you can split a macro on multiple lines with '\'

PHP Code:
#define add(%0,%1) ((%0)+(%1))

main()
{
    
printf("%i",
        
        
add(\
            
5\
            ,\
            
6\
            )

        );

not only macros but literally anything, as far as I know, correct me if I'm wrong!
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning


Eoussama is offline   Reply With Quote
Old 01/04/2018, 10:46 PM   #756
Freaksken
Gangsta
 
Freaksken's Avatar
 
Join Date: Mar 2009
Location: Belgium
Posts: 577
Reputation: 239
Default Re: Today I learned - Share your newly found knowledge!

TIL you can specify a variable width or precision by using an asterisk.

Code:
Width:
printf("%5d", 10);			//prints '   10'
printf("%*d", 5, 10);			//prints '   10'

printf("%5f", 3.1415926535);		//prints '    3.141592'
printf("%*f", 5, 3.1415926535);		//prints '    3.141592'

Precision:
printf("%.5f", 3.1415926535);		//prints '3.14159'
printf("%.*f", 5, 3.1415926535);	//prints '3.14159'

printf("%.5s", "abcdefghi");		//prints 'abcde'
printf("%.*s", 5, "abcdefghi");		//prints 'abcde'
This is useful in situations where you don't want to hardcode those values.
__________________
Always keep in mind that a lot of people are active on this forum in their spare time.
They are sacrificing time they could easily spend on things they would rather do, to help you instead.


[Include] FCNPC A.I. - [Tutorial] Speedometer - [WIP] Single-player-like co-op mission - [Other] List of all my work
Freaksken is online now   Reply With Quote
Old 02/04/2018, 10:09 AM   #757
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,717
Reputation: 3070
Default Re: Today I learned - Share your newly found knowledge!

YIL the internal buffer for formatting floating point numbers is 64 characters:

PHP Code:
    new str[256];
    
format(strsizeof (str), "%7.0100f"4.4);
    print(
str);
    
printf("%7.0100f"4.4); 
Should give numbers with 100 decimal places (mostly all zeros), but doesn't:

Code:
      4.40000009536743164062500000000000000000000000000000000000
      4.40000009536743164062500000000000000000000000000000000000
Edit:

I'll also expand on what Freaksken said (I didn't learn this today, I wrote the original code for it). You can combine variable width and precision, plus zero prefixes:

PHP Code:
printf("%0*.*f"354.4); // Gives "004.40000" 
Even better, this can totally replace "substring" code:

PHP Code:
new str[] = "How are you?"
printf("%.3s"str[4]); // Gives "are" 
Y_Less is offline   Reply With Quote
Old 02/04/2018, 10:32 AM   #758
kurta999
High-roller
 
kurta999's Avatar
 
Join Date: Apr 2009
Location: Slovakia (HU)
Posts: 1,423
Reputation: 626
Default Re: Today I learned - Share your newly found knowledge!

Quote:
Originally Posted by Y_Less View Post
YIL the internal buffer for formatting floating point numbers is 64 characters:

PHP Code:
    new str[256];
    
format(strsizeof (str), "%7.0100f"4.4);
    print(
str);
    
printf("%7.0100f"4.4); 
Should give numbers with 100 decimal places (mostly all zeros), but doesn't:

Code:
      4.40000009536743164062500000000000000000000000000000000000
      4.40000009536743164062500000000000000000000000000000000000
Edit:

I'll also expand on what Freaksken said (I didn't learn this today, I wrote the original code for it). You can combine variable width and precision, plus zero prefixes:

PHP Code:
printf("%0*.*f"354.4); // Gives "004.40000" 
Even better, this can totally replace "substring" code:

PHP Code:
new str[] = "How are you?"
printf("%.3s"str[4]); // Gives "are" 
The latest example does work with sprintf in C?
__________________
I don't play and have ANY interest in SA:MP anymore! Please do not ask for help, because I'm not going to reply.
kurta999 is offline   Reply With Quote
Old 02/04/2018, 10:39 AM   #759
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,717
Reputation: 3070
Default Re: Today I learned - Share your newly found knowledge!

I have no idea sorry. As I said, the "*" functionality is something I added to SA:MP's format when I was a dev. Test it and make your own TIL post!
Y_Less 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
Things you learned from GTA SA Toni Everything and Nothing 212 20/08/2011 07:07 AM
How you learned to script Bam23 Help Archive 9 11/04/2011 10:21 AM
What did u learned today ? rafay Everything and Nothing 170 30/03/2010 04:06 PM


All times are GMT. The time now is 07:28 AM.


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