[Tutorial] iExtras - A way to easier scripting, how to use it!
#1

iExtras - A easier way to scripting.

Introduction

I have seen many people struggling with options like giving players a certain amount of health or struggling with strings in SendClientMessage, that's the reason I wrote this tutorial.

I am also promoting iExtras a bit as it has a lot of great features saving you a lot of time.

SendClientMessage & Strings

in iExtras there is an easy possibility of bringing 3 lines back to 1, here's a look:

pawn Код:
new astring[128]; // "new" for the string
format(astring,sizeof(astring),"Bad %s! Administrator %s has frozen you",tname,pname); // Adding the Format
SendClientMessage(playerid, COLOR_LIGHTBLUE,astring); // Sending the message.
simply becomes

pawn Код:
SCM(playerid, COLOR_LIGHTBLUE, "Bad %s! Administrator %s has frozen you",tname,pname); // Message with strings
But how? Let me explain it.
The parameters are: SCM(playerid/killerid, color, text, string);
The Playerid/Killerid is to which person we have to send it, if I kill somebody and I have:
"SCM(killerid, COLOR_WHITE, "Killed somebody, good job %s!", string);"

At this part "%s" keeps %s as there is no "string" defined, lets define one.

pawn Код:
new name[MAX_PLAYER_NAME+1], string[24+MAX_PLAYER_NAME+1]; // creating the parameter "name"
    GetPlayerName(playerid, name, sizeof(name)); // Getting the player name and giving the new above a function.
Now, the string is defined and called "name", so we have to change:
pawn Код:
SCM(killerid, COLOR_WHITE, "Killed somebody, good job %s!", string);
to:
pawn Код:
SCM(killerid, COLOR_WHITE, "Killed somebody, good job %s!", name);
the string is now defined, if my name is iRonan in-game and I kill somebody it outputs this. (has to be placed at OnPlayerDeath)
Код:
 Killed somebody, good job iRonan!
As you can see we made 5 lines 3, which is shorter and easier to read.

Check the include for credits to SCM and other options mentioned in the thread.
Additional items:
If you do not want to install the complete include, here is the code for SCM:
pawn Код:
stock SCM(playerid, color, form[], {Float, _}: ...) // Parameters
{
    #pragma unused form // Do not remove.
    static
        tmp[144]
    ;
    new
        t1 = playerid,
        t2 = color // text Color
    ;
    const
        n16 = -16,
        size = sizeof tmp << 2
    ;
    #emit const.pri size
    #emit stor.s.pri 16
    #emit const.pri tmp
    #emit stor.s.pri 12
    #emit stack 16
    #emit sysreq.c format
    #emit stack n16
    return SendClientMessage(t1, t2, tmp);
}
Parachuting Options


Introduction


iExtras is very good for a parachuting script, so I wrote this addon to the tutorial.

Tutorial


pawn Код:
stock IsPlayerParachuting(playerid)
{
    new index = GetPlayerAnimationIndex(playerid)
    return (index >= 958 && index <= 962);
}

stock IsPlayerUsingParachute(playerid)
{
    new index = GetPlayerAnimationIndex(playerid)
    return (index >= 963 && index <= 979);
}
Those are the parachuting options, both look the same but they aren't. Let me explain.

IsPlayerUsingParachute - Detects if the player has the parachute as a weapon.
IsPlayerParachuting - Detects if the player is parachuting (he is falling from the sky with the parachute equiped)

Those can be used for a simple parachuting minigame, which is what we are going to create.

First, the timer. It can be done with OnPlayerUpdate but it is better to detect it per second.
pawn Код:
forward ChuteTimer(playerid);
[pawn]
public ChuteTimer(playerid)
{
// We will be adding options here.
return 1;
}

pawn Код:
public OnPlayerConnect(playerid)
{
    SetTimer("ChuteTimer", 1000, 1);
    // rest of your code
    return 1;
}
All the basics are set now, now lets set up the "ChuteTimer." - everything will be in the pawn code below.

pawn Код:
public ChuteTimer(playerid)
{
    if(IsPlayerParachuting(playerid)) // Checks if the player is parachuting.
    {
         SCM(playerid, -1, "%s started parachuting!", PlayerName(playerid)); // Sets up the message, also gets the player's name.
    return 1;
}
It can be this easy, how to use SCM? Read the first tutorial!


Required options:
pawn Код:
stock PlayerName(playerid)
{
    new name[128+MAX_PLAYER_NAME+128];
    GetPlayerName(playerid, name, sizeof(name));
    return 1;
}
(Not included in the latest iExtras but it will be added.)
Reply
#2

Very good! 4 stars!
I hope u add more functions soon! +rep
Reply
#3

Quote:
Originally Posted by UnknownOwner
Посмотреть сообщение
Very good! 4 stars!
I hope u add more functions soon! +rep
Thank you. I am working on something now, and might place it tommorow.
Reply
#4

Finished the "Parachuting System", this is an easy way to do it although there are a lot of ways to do it.
Reply
#5

That SCM was made by Nero_3D
http://forum.sa-mp.com/showpost.php?...postcount=4226
You should give him a credits.
Reply
#6

https://sampforum.blast.hk/showthread.php?tid=38965

1) ChuteTimer Function is messed up, because its missing a bracket!
2) PlayerName is wrong, adding a extra +128 AND +128 to MAX_PLAYER_NAME ain't a good idea! There are limits for the player name's length! Plus, everyone for strings (I/O) should use 128 cells (512 bytes).
Reply
#7

Quote:
Originally Posted by ACI
Посмотреть сообщение
https://sampforum.blast.hk/showthread.php?tid=38965

1) ChuteTimer Function is messed up, because its missing a bracket!
2) PlayerName is wrong, adding a extra +128 AND +128 to MAX_PLAYER_NAME ain't a good idea! There are limits for the player name's length! Plus, everyone for strings (I/O) should use 128 cells (512 bytes).
I know those, just small mistakes which I won't be fixing as "nobody uses this"

@newbienoob - I gave him credits in the original topic which got removed.
Reply
#8

When you yourself are mentioning that "nobody uses this", doesn't that tell everyone and you something?

Quote:

@newbienoob - I gave him credits in the original topic which got removed.

You haven't, give them credits in your topic as-well in your release! (You ignore this many times)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)