[Tutorial] Tips & Tricks [Share Yours!]
#1

PLEASE ONLY SHARE/BROWSE TIPS/TRICKS!
Introduction:

Quote:

This thread was created for newbies to browse tips/tricks shared by experienced scripters.


Let's keep things organized with a simple format:


FORMAT:

* Please BOLD format fields.

Quote:

Tip/Trick Title:

Tip/Trick Description:

Tip/Trick Example(Use PAWN tags):

Reply
#2

Tip/Trick Title: Antispawn Kill

Tip/Trick Description: When someone dies and spawns, they'll have an anti-spawn-kill for 5 seconds, ideal for anything other than RPG.

Tip/Trick Example(Use PAWN tags):

pawn Code:
#include <a_samp>

forward SpawnKillTimer(playerid);

public OnPlayerSpawn(playerid)
{
   SetTimerEx("SpawnKillTimer", 5000, false, "i", playerid);
   GameTextForPlayer(playerid, "~r~anti-spawn-kill 5 seconds", 5000, 6);
   SetPlayerHealth(playerid, 9999999);
   return 1;
}

public SpawnKillTimer(playerid)
{
   SetPlayerHealth(playerid, 100);
   GivePlayerWeapon(playerid, 24, 500);
   GameTextForPlayer(playerid, "~r~anti-spawn-kill over", 5000, 6);
   return 1;
}


Note: Good topic .
Reply
#3

I am sure there is a topic like this made by Slice, if I am not wrong!
Reply
#4

Quote:
Originally Posted by Rajat_Pawar
View Post
I am sure there is a topic like this made by Slice, if I am not wrong!
Show me?

EDIT

@DanishHaq - Great first tip!
Reply
#5

Sorry for the replies in quick succession!
The link: https://sampforum.blast.hk/showthread.php?tid=216730
Reply
#6

Quote:
Originally Posted by Rajat_Pawar
View Post
Sorry for the replies in quick succession!
The link: https://sampforum.blast.hk/showthread.php?tid=216730
1. I did not see that topic after my search...
2. I think you have the wrong impression of what "succession" really means: www.******.com.au/#q=define+succession

EDIT

His/Hers topic does not encourage members to share their tips, and as far as I see only covers a limited/specific amount of information.
Reply
#7

Easy reset enums

pawn Code:
enum pEnum {
    bla, ble, bli, blo, blu
}
main() {

    new arr[pEnum];
   
    arr[bla] = 00;
    arr[bli] = 10;
    arr[blu] = 20;

    printf( "%d - %d - %d",
        arr[bla], arr[bli], arr[blu]
    );
   
    for( new i ; i != _: pEnum; i++) {
   
        arr[pEnum:i] = _: 0;
    }

    printf( "%d - %d - %d",
        arr[bla], arr[bli], arr[blu]
    );
}
or

pawn Code:
enum pEnum {
    bla, ble, bli, blo, blu
}
main() {

    new arr[pEnum];
   
    arr[bla] = 00;
    arr[bli] = 10;
    arr[blu] = 20;


    printf( "%d - %d - %d",
        arr[bla], arr[bli], arr[blu]
    );
   
   
   
    new reset[pEnum];
    arr = reset;
   

    printf( "%d - %d - %d",
        arr[bla], arr[bli], arr[blu]
    );
}

Easy loop string (not fastest)

PHP Code:
for(new xstr[x]; x++) {

Easy check zero values

pawn Code:
if( var1 == 0 && var2 == 0 && var3 == 0)
to

pawn Code:
if( var1 | var2 | var3 == 0)
More tips:
http://forum.sa-mp.com/showpost.php?...8&postcount=26
http://forum.sa-mp.com/showpost.php?...4&postcount=27
http://forum.sa-mp.com/showpost.php?...3&postcount=35
Reply
#8

Tip/Trick Title: Bypass losing money after the player's death.

Tip/Trick Description: To ignore the loss of the money after the death of the player by using SpawnPlayer(playerid). In this case, reset the animation.

pawn Code:
//enum to record the variables in
enum pInfo
{
    Float:pPosX,
    Float:pPosY,
    Float:pPosZ,
    Float:pPosR,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
//actually function
public OnPlayerDeath(playerid, killerid, reason)
{
    GetPlayerPos(playerid, PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ]);
    GetPlayerFacingAngle(playerid, PlayerInfo[playerid][pPosR]);
    //Respawn at the place of death
    SetSpawnInfo(playerid, 0, PlayerInfo[playerid][pSkin], PlayerInfo[playerid][pPosX], PlayerInfo[playerid][pPosY], PlayerInfo[playerid][pPosZ], PlayerInfo[playerid][pPosR], 0, 0, 0, 0, 0, 0);
    SpawnPlayer(playerid);
    return 1;
}
Some demonstration (available in English):
[ame="http://www.youtube.com/watch?v=mX_Q2-mRF9Q"]Bypass losing money after the player's death.[/ame]
Reply
#9

@ipsBruno

Please redo your tip in the format provided.

@sanya_gnoy

Great tip, thanks for submitting!
Reply
#10

Tip/Trick Title: Enumerator & Loop

Tip/Trick Description: Easy to loop an Enumerator, nothing much too explain.

Tip/Trick Example(Use PAWN tags):
pawn Code:
enum debug//Enumerator
{
    debug1, debug2, debug3, debug 4;
}
new debug[ MAX_PLAYERS ][ debug ];

CMD:setenumto1(playerid, params[]) // debug purposes
{
    debug1[playerid][debug1] = 1;
    debug1[playerid][debug2] = 1;
    debug1[playerid][debug3] = 1;
    debug1[playerid][debug4] = 1;
     printf("[DEBUG]: %i, %i, %i, %i", debug1, debug2, debug3, debug4);
    //DEBUG result ( [DEBUG]: 1, 1, 1, 1)
}


//new process | shorter version
CMD:resetenum(playerid, params[])
{
    for(new i; robbingshop:i < robbingshop; i++) { debug[ playerid ][ robbingshop:s ] = 0; } return 1;
    printf("[DEBUG]: %i, %i, %i, %i", debug1, debug2, debug3, debug4);
    //DEBUG result ( [DEBUG]: 0, 0, 0, 0 )
}

//instead of | longer version
CMD:resetenum1(playerid, params[])
{
    debug1[playerid][debug1] = 0;
    debug1[playerid][debug2] = 0;
    debug1[playerid][debug3] = 0;
    debug1[playerid][debug4] = 0;
    printf("[DEBUG]: %i, %i, %i, %i", debug1, debug2, debug3, debug4);
    //DEBUG result ( [DEBUG]: 0, 0, 0, 0 )
}
Reply
#11

@sanya_gnoy, what about making enums for pPosX and all those other enums being not defined? I'm sure it will cause an error without enum defines
Reply
#12

@Sublime, sorry, I forgot about it, fixed.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)