World Life RP Gaming
Would you like to react to this message? Create an account in a few clicks or log in to continue.

make a simple script command

3 posters

Go down

make a simple script command Empty make a simple script command

Post by James_Alex Thu Jul 09, 2009 7:34 am

Making a Simple Command


1-Open your server folder then choose the "new.pwn" file in "Pawno" Folder

2-Find this "public OnPlayerCommandText(playerid, cmdtext[])

now you should see this

Code:
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;

3-delete from if(strcmp ... to return 0;

4-now add this under the public

Code:

    new cmd[256];
    new tmp[256];
    new  idx;
    cmd = strtok(cmdtext, idx);
//-------------------------------[Command]--------------------------------------------------------------------------
    if(strcmp(cmd, "/mycommand", true) == 0)
    {
            // actions...
            return 1;
    }
    return 0;
}

5-add this before the public

Code:
}

strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;

you shoud have this

Code:


strtok(const string[], &index)
{
    new length = strlen(string);
    while ((index < length) && (string[index] <= ' '))
    {
        index++;
    }

    new offset = index;
    new result[20];
    while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }
    result[index - offset] = EOS;
    return result;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256];
    new tmp[256];
    new  idx;
    cmd = strtok(cmdtext, idx);
//-------------------------------[Command]--------------------------------------------------------------------------
    if(strcmp(cmd, "/mycommand", true) == 0)
    {
            // actions...
            return 1;
    }
    return 0;
}

6-Now to pass a value to your command you can change the "//actions..." by your value

Examples

Code:

    if(strcmp(cmd, "/getmoney", true) == 0)
    {
            // this should give to player $5000
            GivePlayerMoney(playerid, 5000);
            return 1;
    }

PS:
the playerid = the id of the player wich you like to give him money(you
can change it by the player id, or let it playerid so it give money to
the player who types this command) | the 5000 is the ammount of money
wich will give to player)

or you can use GivePlayerHealth | GivePlayerArmour(you have al the natives at your right)

7-How to get a value

now how to get a value(like getting player health|money|armour|WantedLevel...)

you can use this with new


Code:
new money;
money = GetPlayerMoney(playerid);

now "money" word should have the player money
example

Code:

new money;
money = GetPlayerMoney(playerid);
GivePlayerMoney(0, money); // this should give to player id 0 the ammount of money of the player who types the command
// or we change the GivePlayerMoney(0, money); by
GivePlayerMoney(playerid, money); // this should double the player money(who types the command)

8-Getting a Float
to get a float you have to use "new Float:myfloat;

Code:

new Float:health;
GetPlayerHealth(playerid, health);
now the "health" word should get the player health

Example:

Code:

new Float:X;
new Float:Y;
new Float:Z;
GetPlayerPos(playerid, X, Y, Z); // now the X and Y and Z words should have the the pos of player

Floats in samp are:
-The Player Postions(X, Y, Z)
-Player Health and Armour
-Player Angle


9-Use a formatted message
now you can send a message to a player wich get some of his stats for example

Code:

new money;
money = GetPlayerMoney(playerid);
new string[256];
format(string, sizeof(string), "You have $%d", money);
SendClientMessage(playerid, COLOR, string); // this should send to the player his ammount of money

or multiplay
Code:

new money;
new score;
score = GetPlayerScore(playerid);
money = GetPlayerMoney(playerid);
format(string, sizeof(string), "You have: $%d, and your score is; %d", money, score);
SendClientMessage(playerid, COLOR, string);

Becarful: you have to change the "COLOR" word by the the color that you like
put this in the top of the script

Code:
#define COLOR_GRAD2 0xBFC0C2FF
#define COLOR_GRAD3 0xCBCCCEFF
#define COLOR_GRAD4 0xD8D8D8FF
#define COLOR_GRAD5 0xE3E3E3FF
#define COLOR_GRAD6 0xF0F0F0FF
#define COLOR_GREY 0xAFAFAFAA
#define COLOR_GREEN 0x33AA33AA
#define COLOR_RED 0xAA3333AA
#define COLOR_LIGHTRED 0xFF6347AA
#define COLOR_LIGHTBLUE 0x33CCFFAA
#define COLOR_LIGHTGREEN 0x9ACD32AA
#define COLOR_YELLOW 0xFFFF00AA
#define COLOR_YELLOW2 0xF5DEB3AA
#define COLOR_WHITE 0xFFFFFFAA
#define COLOR_FADE1 0xE6E6E6E6
#define COLOR_FADE2 0xC8C8C8C8
#define COLOR_FADE3 0xAAAAAAAA
#define COLOR_FADE4 0x8C8C8C8C
#define COLOR_FADE5 0x6E6E6E6E
#define COLOR_PURPLE 0xC2A2DAAA
#define COLOR_DBLUE 0x2641FEAA
now choose your color as you like, Example
Code:
SendClientMessage(playerid, COLOR_LIGHTBLUE...

10-Do something for all the players
Now you can for example give the same ammount of money or health to all the server players
you have to put this

Code:

for(new i = 0; i < MAX_PLAYERS; i ++)
{
    if(IsPlayerConnected(i))
    {
        // Actions ...
    }
}

now change "Actions ..." by the value as you like as we learned
Example

Code:

for(new i = 0; i < MAX_PLAYERS; i ++)
{
    if(IsPlayerConnected(i))
    {
        GivePlayerMoney(i, 5000);
    }
}

Warning: do not use "return" with this or it will do the action only for the player id 0.

11-Give ammount as the player like
now you like to make a command like this "/givemoney 0 5000"
easy put this in the top of the script

Code:
#include
then put this
Code:

    if(strcmp(cmd, "/getmoney", true) == 0)
    {
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREEN, "USAGE: /getmoney [player id] [ammount]");
            return 1;
        }
        new target;
        target = ReturnUser(tmp);
        if(target == INVALID_PLAYER_ID)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "INVALID PLAYER ID !");
            return 1;
        }
        if(target == playerid)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You cannot give yourself money !");
            return 1;
        }
        tmp = strtok(cmdtext, idx);
        if(!strlen(tmp))
        {
            SendClientMessage(playerid, COLOR_GREEN, "USAGE: /getmoney [player id] [ammount]");
            return 1;
        }
        new moneyG;
        moneyG = strval(tmp);
if(moneyG < 1 || moneyG > 99999) { SendClientMessage(playerid,
COLOR_LIGHTRED, "Money ammount can't be below 1 or above 99999 !");
return 1; }
        if(GetPlayerMoney(playerid) < moneyG)
        {
            SendClientMessage(playerid, COLOR_LIGHTRED, "You haven't anough money !");
            return 1;
        }
        GivePlayerMoney(target, moneyG);
        GivePlayerMoney(playerid, -moneyG);
        return 1;
    }
Warning:
-you can change the "usage: getmoney..." by the text that you like
-you
can change the "moneyG > 99999" exactly the "99999" by the max
ammount that you like or remove all the line if you dosen't like to
have limit
-you can change the valur to give for example give
score(but don't change the "moneyG" word juste change the
GivePlayerMoney by SetPlayerScore for example)

-if you like to give player health juste change the
Code:
new moneyG
by
Code:
new Float:moneyG;
and other like GivePlayerMoney by SetPlayerHealth

I Hope you enjoy this Tutorial guys

Good Luck

PS: for any questions, or you like that i realese fr you a good command, post a reply here and i'll realese the script here.

James_Alex
James_Alex
Official Scripter
Official Scripter

Number of posts : 132
Age : 29
Location : Los Santos
In-Game Name : James_Alex
Points :
make a simple script command Left_bar_bleue100 / 100100 / 100make a simple script command Right_bar_bleue

Registration date : 2009-04-11

Back to top Go down

make a simple script command Empty Re: make a simple script command

Post by Lyrem Thu Jul 09, 2009 8:38 am

Sweet.
Easy to understand and read. Smile
Got it all. ^^
Lyrem
Lyrem
Game Master
Game Master

Number of posts : 287
Age : 35
Location : Singapore
In-Game Name : Lyrem_Joxel
Points :
make a simple script command Left_bar_bleue0 / 1000 / 100make a simple script command Right_bar_bleue

Registration date : 2009-05-17

Back to top Go down

make a simple script command Empty Re: make a simple script command

Post by James_Alex Thu Jul 09, 2009 7:37 pm

yes, and if someone want to realese a command
reply here with it's description Very Happy
James_Alex
James_Alex
Official Scripter
Official Scripter

Number of posts : 132
Age : 29
Location : Los Santos
In-Game Name : James_Alex
Points :
make a simple script command Left_bar_bleue100 / 100100 / 100make a simple script command Right_bar_bleue

Registration date : 2009-04-11

Back to top Go down

make a simple script command Empty Re: make a simple script command

Post by Tracy Fri Jul 10, 2009 5:57 pm

I just maked a /help command and /pay command Very Happy hehe! This one helped James. Thanks alot!!
Tracy
Tracy
Game Master
Game Master

Number of posts : 272
Age : 33
Location : Latvia
In-Game Name : Tracy_Johnson
Points :
make a simple script command Left_bar_bleue15 / 10015 / 100make a simple script command Right_bar_bleue

Registration date : 2009-04-29

Back to top Go down

make a simple script command Empty Re: make a simple script command

Post by James_Alex Fri Jul 10, 2009 8:11 pm

PLAYERS INFOS

this is a simple command to check all the server players stats
Code:

    }

    if(strcmp(cmd, "/getinfos", true) == 0)
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerAdmin(playerid))
            {
                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                    if(IsPlayerConnected(i))
                    {
                        new name[MAX_PLAYER_NAME], IP[26];
                        GetPlayerName(i, name, sizeof(name)); GetPlayerIp(i, IP, sizeof(IP));
                        new str[256]; format(str, sizeof(str), "Name: %s|IP: %s|Ping: %d|Money: $%d", name, IP, GetPlayerPing(i), GetPlayerMoney(i));
                        SendClientMessage(playerid, 0xFFFFFFAA, str);
                    }
                }
            }
            else
            {
                SendClientMessage(playerid, 0xFF6347AA, "You're not admin !");
                return 1;
            }
        }
        return 1;
PS: you have to use /rcon login pass to be admin
and change the 'pass' by your server RCON pass(see it into the server.cfg) !
James_Alex
James_Alex
Official Scripter
Official Scripter

Number of posts : 132
Age : 29
Location : Los Santos
In-Game Name : James_Alex
Points :
make a simple script command Left_bar_bleue100 / 100100 / 100make a simple script command Right_bar_bleue

Registration date : 2009-04-11

Back to top Go down

make a simple script command Empty Re: make a simple script command

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum