2 bugs
#1

Hi! I'm making a SIMPLE and fast gamemode for someone (SWAT vs TERRORISTS, TDM).
I have two bugs right now:
1) When starting gamemode, it shows <null> - No print / printf added
2) Textdraw won't show :S

Here's the script:
pawn Код:
FIXED
Can anyone see what's ehm... wrong?
Reply
#2

pawn Код:
#include <a_samp>
#include <zcmd>
#include <djson>

main()
{
    print("* SWAT Gamemode loaded (Thanks to Kwarde)");
    return 1;
}

#undef MAX_PLAYERS
#define MAX_SLOTS       500 //Change this to max players of your server!
#define MAX_TEAMS       2 //Only change this if you're gonna add more teams

#define MAX_LOGIN_FAILS 5 //Max wrong password while logging in...

#define COLOR_WHITE     0xFFFFFFAA
#define COLOR_RED       0xFF0000AA
#define COLOR_GREEN     0x00FF00AA
#define COLOR_BLUE      0x0000FFAA
#define COLOR_YELLOW    0x00FFFFAA
#define COLOR_GRAY      0xAFAFAFAA

#define TEAM_TERRORISTS 0
#define TEAM_SWAT       1

#define TEAM0_NAME      "Terrorists"
#define TEAM1_NAME      "S.W.A.T."

#define TEAM0_COLOR     0xFF0000AA
#define TEAM1_COLOR     0x00AAFFAA

#define CB:%0(%1)       forward %0(%1); public %0(%1)
#define func:%0(%1)     stock %0(%1)
#define loop:%0(%1)     for(new %1; %1 < %0; %1++)
#define ploop(%0)       for(new %0; %0 < MAX_SLOTS; %0++) if(IsPlayerConnected(%0))

enum pInfo
{
    bool:pLogged,
    pPassword[75],
    pScore,
    pMoney,
    pVip,
    pAdmin,
    pLoginFails,
    pTeam
};
new PlayerInfo[MAX_SLOTS][pInfo];
new PlayerName[MAX_SLOTS][MAX_PLAYER_NAME];

enum tInfo
{
    TeamName,
    TeamScore,
    TeamMembers
};
new TeamInfo[MAX_TEAMS][tInfo];

new Text:TimerDraw;
new RoundTime[2], ThisRoundID;



public OnGameModeInit()
{
    SetGameModeText("SWAT vs TERRORISTS");

    djson_GameModeInit();
    djStyled(true);

    AddPlayerClass(272, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    AddPlayerClass(285, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

    RoundTime[0] = 5;
    RoundTime[1] = 30;

    ThisRoundID = 1;

    TimerDraw = TextDrawCreate(149.000000, 353.000000, "Time left: ~r~??:??");
    TextDrawBackgroundColor(TimerDraw, 255);
    TextDrawFont(TimerDraw, 2);
    TextDrawLetterSize(TimerDraw, 0.500000, 4.000000);
    TextDrawColor(TimerDraw, -1);
    TextDrawSetOutline(TimerDraw, 1);
    TextDrawSetProportional(TimerDraw, 1);
    SetTimer("UpdateTimeTextdraw", 1000, true);

    loop:MAX_TEAMS(i)
    {
        TeamInfo[i][TeamScore] = 0;
        TeamInfo[i][TeamMembers] = 0;
    }
    strset(TeamInfo[0][TeamName], TEAM0_NAME);
    strset(TeamInfo[1][TeamName], TEAM1_NAME);
    return 1;
}

public OnGameModeExit()
{
    djson_GameModeExit();
    return 1;
}

public OnPlayerConnect(playerid)
{
    new str[128], fstr[50];

    ResetPlayer(playerid);
    GetPlayerName(playerid, PlayerName[playerid], MAX_PLAYER_NAME);

    format(str, 128, "** %s has joined the server", PlayerName[playerid]);
    SendClientMessageToAll(COLOR_GREEN, str);

    format(fstr, 50, "Users/%s", PlayerName[playerid]);
    if(fexist(fstr))
        ShowPlayerDialog(playerid, 41, DIALOG_STYLE_INPUT, "Login", "This account is registered in our database.\nPlease typ your password to login or come back on another name", "Login", "Kick");
    else
        ShowPlayerDialog(playerid, 42, DIALOG_STYLE_INPUT, "Register", "This account isn't registered in our database yet.\nPlease typ a password to register this account", "Register", "Cancel");

    TextDrawShowForPlayer(playerid, TimerDraw);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new str[128];
    format(str, 128, "* %s has left the server ", PlayerName[playerid]);
    switch(reason)
    {
        case 0: format(str, 128, "%s(Lost Connection)", str);
        case 1: format(str, 128, "%s(Leaving)", str);
        case 2: format(str, 128, "%s(Kicked/Banned)", str);
        default: format(str, 128, "%s(Unknown)", str);
    }
    SendClientMessageToAll(COLOR_GRAY, str);
    TeamInfo[PlayerInfo[playerid][pTeam]][TeamMembers] --;
    SavePlayer(playerid);
    ResetPlayer(playerid);
    TextDrawHideForPlayer(playerid, TimerDraw);
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    switch(classid)
    {
        case 0:
        {
            GameTextForPlayer(playerid, "~r~Terrorist", 3000, 3);
            PlayerInfo[playerid][pTeam] = TEAM_TERRORISTS;
        }
        case 1:
        {
            GameTextForPlayer(playerid, "~b~S.W.A.T.", 3000, 3);
            PlayerInfo[playerid][pTeam] = TEAM_SWAT;
        }
    }
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    if(!PlayerInfo[playerid][pLogged]) return 0;
    return 1;
}

public OnPlayerSpawn(playerid)
{
    switch(PlayerInfo[playerid][pTeam])
    {
        case 0:
        {
            switch(random(12))
            {
                case 0: SetPlayerSkin(playerid, 21);
                case 1: SetPlayerSkin(playerid, 23);
                case 2: SetPlayerSkin(playerid, 28);
                case 3: SetPlayerSkin(playerid, 29);
                case 4: SetPlayerSkin(playerid, 80);
                case 5: SetPlayerSkin(playerid, 81);
                case 6: SetPlayerSkin(playerid, 100);
                case 7: SetPlayerSkin(playerid, 111);
                case 8: SetPlayerSkin(playerid, 112);
                case 9: SetPlayerSkin(playerid, 113);
                case 10: SetPlayerSkin(playerid, 122);
                case 11: SetPlayerSkin(playerid, 127);
                default: SetPlayerSkin(playerid, 80);
            }
            SetPlayerColor(playerid, TEAM0_COLOR);
            SetPlayerTeam(playerid, TEAM_TERRORISTS);
            TeamInfo[TEAM_TERRORISTS][TeamMembers] ++;
            if(ThisRoundID == 1)
            {
                switch(random(3))
                {
                    case 0:
                    {
                        SetPlayerPos(playerid, 156.169830, -22.266595, 1.578125);
                        SetPlayerFacingAngle(playerid, 269.637420);
                    }
                    case 1:
                    {
                        SetPlayerPos(playerid, 252.266128, -92.491127, 3.535394);
                        SetPlayerFacingAngle(playerid, 88.992156);
                    }
                    case 2:
                    {
                        SetPlayerPos(playerid, 91.387809, -306.528472, 1.578125);
                        SetPlayerFacingAngle(playerid, 3.837012);
                    }
                }
            }
        }
        case 1:
        {
            switch(random(10))
            {
                case 0: SetPlayerSkin(playerid, 121);
                case 1: SetPlayerSkin(playerid, 280);
                case 2: SetPlayerSkin(playerid, 281);
                case 3: SetPlayerSkin(playerid, 282);
                case 4: SetPlayerSkin(playerid, 283);
                case 5: SetPlayerSkin(playerid, 284);
                case 6: SetPlayerSkin(playerid, 285);
                case 7: SetPlayerSkin(playerid, 286);
                case 8: SetPlayerSkin(playerid, 287);
                case 9: SetPlayerSkin(playerid, 288);
                default: SetPlayerSkin(playerid, 121);
            }
            SetPlayerColor(playerid, TEAM1_COLOR);
            SetPlayerTeam(playerid, TEAM_SWAT);
            TeamInfo[TEAM_SWAT][TeamMembers] ++;
            if(ThisRoundID == 1)
            {
                switch(random(3))
                {
                    case 0:
                    {
                        SetPlayerPos(playerid, 369.473266, -141.469680, 2.484491);
                        SetPlayerFacingAngle(playerid, 92.082603);
                    }
                    case 1:
                    {
                        SetPlayerPos(playerid, 514.379882, 54.370040, 21.103902);
                        SetPlayerFacingAngle(playerid, 102.383377);
                    }
                    case 2:
                    {
                        SetPlayerPos(playerid, 232.717254, 62.052814, 2.921329);
                        SetPlayerFacingAngle(playerid, 182.554595);
                    }
                }
            }
        }
    }
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 41)
    {
        if(response)
            LoginPlayer(playerid, inputtext);
        else
            Kick(playerid);
    }
    if(dialogid == 42)
    {
        if(response)
            RegisterPlayer(playerid, inputtext);
        else
            SpawnPlayer(playerid);
    }
    return 1;
}

CB:UpdateTimeTextdraw()
{
    new tstr[30];
    RoundTime[1]--;
    if(RoundTime[1] <= 0){
        RoundTime[0] --;
        RoundTime[1] = 60;
    }
    format(tstr, 30, "Time left: ~r~%02d:%02d", RoundTime[0], RoundTime[1]);
    TextDrawSetString(TimerDraw, tstr);

    if(RoundTime[0] <= 0 && RoundTime[1] <= 0)
        CallLocalFunction("OnGameModeFinish", "");
    return 1;
}

CB:OnGameModeFinish()
{
    new highestscore = cellmin, lastteamwin,
        str[128]
    ;
    loop:MAX_TEAMS(i)
    {
        if(TeamInfo[i][TeamScore] > highestscore)
        {
            lastteamwin = i;
            continue;
        }
    }
    format(str, 128, "Team %s has won!", TeamInfo[lastteamwin][TeamName]);
    SendClientMessageToAll(COLOR_YELLOW, str);
    return 1;
}

func:ResetPlayer(playerid)
{
    PlayerInfo[playerid][pLogged] = false;
    strset(PlayerInfo[playerid][pPassword], "None");
    PlayerInfo[playerid][pScore] = 0;
    PlayerInfo[playerid][pMoney] = 0;
    PlayerInfo[playerid][pVip] = 0;
    PlayerInfo[playerid][pAdmin] = 0;
    PlayerInfo[playerid][pLoginFails] = 0;

    GivePlayerMoney(playerid, -GetPlayerMoney(playerid));
    SetPlayerScore(playerid, 0);

    strset(PlayerName[playerid], "Player");
    return 1;
}

func:LoginPlayer(playerid, password[])
{
    new fstring[50], str[128],
        passhash, inthash;
    format(fstring, 50, "Users/%s", PlayerName[playerid]);

    passhash = hash(password);
    inthash = djInt(fstring, "Key");

    if(passhash != inthash){
        PlayerInfo[playerid][pLoginFails] ++;
        if(PlayerInfo[playerid][pLoginFails] >= MAX_LOGIN_FAILS)
            KickPlayer(playerid, INVALID_PLAYER_ID, true, "Admin Bot", "Max login fails");
        else{
            format(str, 128, "Wrong password! (%d/%d)", PlayerInfo[playerid][pLoginFails], MAX_LOGIN_FAILS);
            SendClientMessage(playerid, COLOR_RED, str);
            ShowPlayerDialog(playerid, 41, DIALOG_STYLE_INPUT, "Login", "This account is registered in our database.\nPlease typ your password to login or come back on another name", "Login", "Kick");
        }
        return 1;
    }

    PlayerInfo[playerid][pScore]    =   djInt(fstring, "Score");
    PlayerInfo[playerid][pMoney]    =   djInt(fstring, "Money");
    PlayerInfo[playerid][pVip]      =   djInt(fstring, "VipLevel");
    PlayerInfo[playerid][pAdmin]    =   djInt(fstring, "AdminLevel");

    format(str, 128, "** {00FFFFAA}%s {FFFFFFAA}has been logged in", PlayerName[playerid]);
    SendClientMessageEx(playerid, COLOR_WHITE, str);
    format(str, 128, "** You've been logged in. Admin level: %d, Vip level: %d, Money: $%d,-, Score: %d", PlayerInfo[playerid][pAdmin], PlayerInfo[playerid][pVip], PlayerInfo[playerid][pMoney], PlayerInfo[playerid][pScore]);
    SendClientMessage(playerid, COLOR_GREEN, str);

    PlayerInfo[playerid][pLogged] = true;

    SpawnPlayer(playerid);
    return 1;
}

func:RegisterPlayer(playerid, password[])
{
    new fstring[50], str[128], inthash;
    format(fstring, 50, "Users/%s", PlayerName[playerid]);

    inthash = hash(password);

    djCreateFile(fstring);
    djSetInt(fstring, "Key", inthash);
    djSetInt(fstring, "Score", 0);
    djSetInt(fstring, "Money", 50);
    djSetInt(fstring, "VipLevel", 0);
    djSetInt(fstring, "AdminLevel", 0);

    format(str, 128, "* You've been registered with the password {FFFFFFAA}%s{00FF00AA}.", password);
    SendClientMessage(playerid, COLOR_GREEN, str);

    LoginPlayer(playerid, password);
    return 1;
}

func:SavePlayer(playerid)
{
    new fstring[50];
    if(!PlayerInfo[playerid][pLogged]) return 0;

    format(fstring, 50, "Users/%s", PlayerName[playerid]);

    djSetInt(fstring, "Score", PlayerInfo[playerid][pScore]);
    djSetInt(fstring, "Money", PlayerInfo[playerid][pMoney]);
    djSetInt(fstring, "VipLevel", PlayerInfo[playerid][pVip]);
    djSetInt(fstring, "AdminLevel", PlayerInfo[playerid][pAdmin]);
    return 1;
}

func:SendClientMessageEx(playerid, color, const message[])
    ploop(i)
        if(i != playerid)
            SendClientMessage(i, color, message);

func:strset(_str_[], _strtoset_[])
{
    strdel(_str_, 0, strlen(_str_));
    strmid(_str_, _strtoset_, 0, strlen(_strtoset_), strlen(_strtoset_));
    return 1;
}

func:KickPlayer(playerid, adminid, bool:UseBotName, BotName[], const reason[])
{
    new string1[128], string2[128], string3[128];
    if(UseBotName){
        format(string1, 128, "* %s has been kicked by %s [ %s ]", PlayerName[playerid], BotName, reason);
        format(string2, 128, "* %s has been kicked by an bot [ %s ]", PlayerName[playerid], reason);
    }
    else{
        format(string1, 128, "* %s has been kicked by %s [ %s ]", PlayerName[playerid], PlayerName[adminid], reason);
        format(string2, 128, "* %s has been kicked by an admin [ %s ]", PlayerName[playerid], reason);
    }
    format(string3, 128, "You've been kicked! [ %s ]", reason);
    SendClientMessage(playerid, COLOR_RED, string3);
    Kick(playerid);
    SendPublicAdminAction(COLOR_RED, string2, string1);
    return 1;
}

func:BanPlayer(playerid, adminid, bool:UseBotName, BotName[], const reason[])
{
    new string[128], string2[128], string3[128], name[50], datestring[50];
    new day, month, year, hour, minute, second;
    getdate(year, month, day); gettime(hour, minute, second);
    if(UseBotName){
        format(string1, 128, "* %s has been banned by %s [ %s ]", PlayerName[playerid], BotName, reason);
        format(string2, 128, "* %s has been banned by a bot [ %s ]", PlayerName[playerid], reason);
        format(name, 50, "Bot %s", BotName);
    }
    else{
        format(string1, 128, "* %s has been banned by %s [ %s ]", PlayerName[playerid], PlayerName[adminid], reason);
        format(string2, 128, "* %s has been banned by an admin [ %s ]", PlayerName[playerid], reason);
        format(name, 50, "Admin %s");
    }
    format(string3, 128, "* You've been banned! [ %s ]", reason);
    format(datestring, 50, "%d-%d-%d %d:%d:%d", day, month, year, hour, minute, second);
    SendClientMessage(playerid, COLOR_RED, string);
    format(string3, 128, "Bans/%s.ban", PlayerInfo[playerid][pIP]);
    djCreateFile(string3);
    djSet(string3, "BannedBy", name);
    djSet(string3, "BanDateTime", datestring);
    djSet(string3, "BanReason", reason);
    Kick(playerid);
    SendPublicAdminAction(COLOR_RED, string2, string1);
    return 1;
}

func:SendPublicAdminAction(color, publicmsg[], adminmsg[])
{
    ploop(i){
        if(IsPlayerAdmin(i) || PlayerInfo[i][pAdmin] > 0)
            SendClientMessage(i, color, adminmsg);
        else
            SendClientMessage(i, color, publicmsg);
    }
    return 1;
}

func:hash(const str[])
{
    new length = strlen(str),
        pos1,
        pos2
    ;
    for(new i = 0; i < length; i++)
    {
        pos1 = (length + str[i]) % 922731;
        pos2 = (pos1 + i) % 922731;
    }
    return ( (pos1 + pos2) << 1996 );
}

CMD:test(playerid, params[]) return TextDrawShowForPlayer(playerid, TimerDraw);
CMD:test2(playerid, params[]) return TextDrawShowForAll(TimerDraw);

#if MAX_SLOTS > 500
    #error Change 'MAX_SLOTS' to the max players of your server! (line 13)
#endif
this fixed the null thing. it was the place of the main thing. it shud come before everyting(new var; things...)

didnt test the TD tho'
Reply
#3

Strange, in my other GM it IS working :P
However thanks, I'll take a look. And the TD is already working... I don't know why. It just worked...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)