SA-MP Forums Archive
Your Advice Needed ... - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Your Advice Needed ... (/showthread.php?tid=367095)



Your Advice Needed ... - Healian - 08.08.2012

I am making a Team Death Match Mode and cuz i am new to SAMP scripting i want to ask you about the method i am working on , IS IS GOOD OR NOT

0- Defines

pawn Код:
//Teams
static gTeam[MAX_PLAYERS];

#define TEAM_USA 0
#define TEAM_RUSSIA 1
#define TEAM_EGYPT 2
#define TEAM_IRAQ 3
#define TEAM_JAPAN 4
#define TEAM_CHINA 5
#define TEAM_ITALY 6
//EndTeams
1- Here is the Team Select Dialog --
pawn Код:
public OnPlayerRequestClass(playerid, classid)
{  
    ShowPlayerDialog( playerid, DIALOG_SPAWN_CLASS, DIALOG_STYLE_LIST, "{ffffff}Pick A Nation", "{d60f0f}Russia\n{d46317}Egypt\n{d4c917}Iraq\n{1767d4}United States\n{7f0fd6}China\n{93e4e9}Japan\n{47d60f}Italy", "Select", "Cancel" );
    return 1;
}
2- Dialog Response

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_SPAWN_CLASS: //SPAWNING DIALOG
        {
            if( response )
            {
                switch( listitem )
                {
                    case 0: // Class 1
                    {
                     SetPlayerClass(playerid, 0);
                     SpawnPlayer(playerid);
                    }
                    case 1: //class 2
                    {
                     SetPlayerClass(playerid, 1);
                     SpawnPlayer(playerid);
                    }
                    case 2: // class 3
                    {
                     SetPlayerClass(playerid, 2);
                     SpawnPlayer(playerid);
                    }
                    case 3: // class 4
                    {
                     SetPlayerClass(playerid, 3);
                     SpawnPlayer(playerid);
                    }
                    case 4: // class 5
                    {
                     SetPlayerClass(playerid, 4);
                     SpawnPlayer(playerid);
                    }
                    case 5: // class 6
                    {
                     SetPlayerClass(playerid, 5);
                     SpawnPlayer(playerid);
                    }
                    case 6: // class 7
                    {
                     SetPlayerClass(playerid, 6);
                     SpawnPlayer(playerid);
                    }                  
                }
            }
            else
            {
                ShowPlayerDialog( playerid, DIALOG_SPAWN_CLASS, DIALOG_STYLE_LIST, "{ffffff}Pick A Nation -REQUIRED-", "{d60f0f}Russia\n{d46317}Egypt\n{d4c917}Iraq\n{1767d4}United States\n{7f0fd6}China\n{93e4e9}Japan\n{47d60f}Italy", "Select", "Cancel" );
            }
        }
    }
    return 1;
}
Player Class Set
pawn Код:
SetPlayerClass(playerid, classid)
{
    if(classid == 0) {
        gTeam[playerid] = TEAM_RUSSIA;
    }
    else if(classid == 1) {
        gTeam[playerid] = TEAM_EGYPT;
    }
    else if(classid == 2) {
        gTeam[playerid] = TEAM_IRAQ;
    }
    else if(classid == 3) {
        gTeam[playerid] = TEAM_USA;
    }
    else if(classid == 4) {
        gTeam[playerid] = TEAM_CHINA;
    }
    else if(classid == 5) {
        gTeam[playerid] = TEAM_JAPAN;
    }
    else if(classid == 6) {
        gTeam[playerid] = TEAM_ITALY;
    }
}
OnPlayerSpawn
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == TEAM_RUSSIA) {   
        SetRandomRUSSIAPos(playerid);
        SetPlayerSkin(playerid, 50);
    }
    else if(gTeam[playerid] == TEAM_EGYPT) {
        SetRandomEGYPTPos(playerid);
        SetPlayerSkin(playerid, 48);
    }
    else if(gTeam[playerid] == TEAM_IRAQ) {
        SetRandomIRAQPos(playerid);
        SetPlayerSkin(playerid, 47);
    }
    else if(gTeam[playerid] == TEAM_USA) {
        SetRandomUSAPos(playerid);
        SetPlayerSkin(playerid, 46);
    }
    else if(gTeam[playerid] == TEAM_CHINA) {
        SetRandomCHINAPos(playerid);
        SetPlayerSkin(playerid, 45);
    }
    else if(gTeam[playerid] == TEAM_JAPAN) {
        SetRandomJAPANPos(playerid);
        SetPlayerSkin(playerid, 44);
    }
    else if(gTeam[playerid] == TEAM_ITALY) {
        SetRandomITALYPos(playerid);
        SetPlayerSkin(playerid, 43);
    }  
    return 1;
}
So is this a good way for TDM ?


Re: Your Advice Needed ... - AndreT - 08.08.2012

It looks good code-wise, but there are a few things to consider:
1. If you pass "" (empty string) as the last parameter of ShowPlayerDialog, you will end up with only one button. This is good in scenarios where you don't want the player to have a secondary choice except for choosing their team, for example.

2. Consider using the switch() statement in OnPlayerSpawn and in SetPlayerClass.
pawn Код:
switch(gTeam[playerid])
{
    case TEAM_RUSSIA:
    {
        // ...
    }
    // ...
    case TEAM_ITALY:
    {
        // ...
    }
    return true;
}
It is slightly faster. Keep in mind that the switch() syntax in PAWN is largely different from the syntax of the keyword in PHP,C++, etc.


Re: Your Advice Needed ... - Nicholas. - 08.08.2012

Yes, I believe it is.


Re: Your Advice Needed ... - Healian - 08.08.2012

So i keep going with this method and just change the if statements in PlayerSpawn to Switch ?


Re: Your Advice Needed ... - Healian - 08.08.2012

So something like this Switch statement is good ?

pawn Код:
switch(gTeam[playerid])
     {
       case TEAM_RUSSIA:
       {
        SetRandomRUSSIAPos(playerid);
        SetPlayerSkin(playerid, 50);
       }
       case TEAM_EGYPT:
       {
        SetRandomEGYPTPos(playerid);
        SetPlayerSkin(playerid, 48);
       }
       case TEAM_IRAQ:
       {
        SetRandomIRAQPos(playerid);
        SetPlayerSkin(playerid, 47);
       }
       case TEAM_USA:
       {
        SetRandomUSAPos(playerid);
        SetPlayerSkin(playerid, 46);
       }
       case TEAM_CHINA:
       {
        SetRandomCHINAPos(playerid);
        SetPlayerSkin(playerid, 45);
       }
       case TEAM_JAPAN:
       {
        SetRandomJAPANPos(playerid);
        SetPlayerSkin(playerid, 44);
       }
       case TEAM_ITALY:
       {
        SetRandomITALYPos(playerid);
        SetPlayerSkin(playerid, 43);
       }
     }



Respuesta: Re: Your Advice Needed ... - [DOG]irinel1996 - 08.08.2012

Quote:
Originally Posted by Healian
Посмотреть сообщение
So something like this Switch statement is good ?

pawn Код:
switch(gTeam[playerid])
     {
       case TEAM_RUSSIA:
       {
        SetRandomRUSSIAPos(playerid);
        SetPlayerSkin(playerid, 50);
       }
       case TEAM_EGYPT:
       {
        SetRandomEGYPTPos(playerid);
        SetPlayerSkin(playerid, 48);
       }
       case TEAM_IRAQ:
       {
        SetRandomIRAQPos(playerid);
        SetPlayerSkin(playerid, 47);
       }
       case TEAM_USA:
       {
        SetRandomUSAPos(playerid);
        SetPlayerSkin(playerid, 46);
       }
       case TEAM_CHINA:
       {
        SetRandomCHINAPos(playerid);
        SetPlayerSkin(playerid, 45);
       }
       case TEAM_JAPAN:
       {
        SetRandomJAPANPos(playerid);
        SetPlayerSkin(playerid, 44);
       }
       case TEAM_ITALY:
       {
        SetRandomITALYPos(playerid);
        SetPlayerSkin(playerid, 43);
       }
     }
Yes, perfect.
Between, everything looks fine.
Also, AndreT gave you a great idea about the dialogs.

Good luck!