Refuses the count score
#1

Hey, so here's the explanation why I got this problem: I started scripting recently.
So when we got that nailed, time for the problem.

My script refuses to count score and to add it in the textdraw I got.
It's suppose to show:
NBG: (Amount of kills)
NATO: (Amount of kills)
But it refuses to update. Anyone able to help me please? (The script is really small and mostly filled by #define and AddStaticVehicle, so it wont take long to go through it.)

pawn Code:
#include <a_samp>
#include <dini>

// Variables
new gTeam[MAX_PLAYERS];
new Text:Textdraw0;
new Text:Textdraw1;
new Text:Textdraw3;
new NBGKills;
new NATOKills;
//forwards
forward ScoreChecker(playerid);
forward ScoreUpdater(playerid);

// Nordic Battlegroup***
#define TEAM_NBG 0
#define NBG_M4 356
#define NBG_PISTOL 348
#define NBG_GRENADE 342
#define NBG_SKIN 287
#define NBG_KNIFE 335
#define NBG_SATCHEL 363
#define NBG_DETO 364
// NATO***
#define TEAM_NATO 1
#define NATO_M4 356
#define NATO_PISTOL 348
#define NATO_GRENADE 342
#define NATO_SKIN 285
#define NATO_KNIFE 335
#define NATO_SATCHEL 363
#define NATO_DETO 364
//Color defines
#define blue 0x375FFFFF
#define red 0xFF0000AA
#define green 0x33FF33AA
#define yellow 0xFFFF00AA
#define grey 0xC0C0C0AA
#define blue1 0x2641FEAA
#define lightblue 0x33CCFFAA
#define orange 0xFF9900AA
#define black 0x2C2727AA
#define pink 0xFF66FFAA
#define purple 0xcc55ccff
#define white 0xFFFFFFAA
#define green1 0x33AA33AA
#define brown 0xA52A2AAA
#define gold 0xFFDC00FF
#define lime 0x37FF00FF

stock SetNBGTeamSetUp(playerid)
{
    SetPlayerTeam( playerid , 0 ) ;
    GivePlayerWeapon ( playerid , NBG_M4 , 5000 ) ;
    GivePlayerWeapon ( playerid , NBG_PISTOL , 1000 ) ;
    GivePlayerWeapon ( playerid , NBG_KNIFE , 1 ) ;
    GivePlayerWeapon ( playerid , NBG_SATCHEL, 5) ;
    GivePlayerWeapon ( playerid , NBG_DETO , 1 ) ;
    GivePlayerWeapon ( playerid , NBG_GRENADE, 2 ) ;
    SetPlayerSkillLevel ( playerid , WEAPONSKILL_PISTOL , 1 ) ;
    SendClientMessage ( playerid , gold , " Extinguish NATO and conquer San Andreas!" ) ;
    SetPlayerSkin ( playerid , NBG_SKIN ) ;
    SetPlayerColor ( playerid , red ) ;
}
stock SetNATOTeamSetUp(playerid)
{
    SetPlayerTeam ( playerid , 1 ) ;
    GivePlayerWeapon ( playerid , NATO_M4 , 5000 ) ;
    GivePlayerWeapon ( playerid , NATO_PISTOL , 1000 ) ;
    GivePlayerWeapon ( playerid , NATO_KNIFE , 1 ) ;
    GivePlayerWeapon ( playerid , NATO_SATCHEL , 5) ;
    GivePlayerWeapon ( playerid , NATO_DETO , 1 ) ;
    GivePlayerWeapon ( playerid , NBG_GRENADE, 2 ) ;
    SetPlayerSkillLevel ( playerid , WEAPONSKILL_PISTOL , 1 ) ;
    SendClientMessage ( playerid , gold , " Nordic Battle Group is attacking. Defend San Andreas before they conquer it! " ) ;
    SetPlayerSkin ( playerid , NATO_SKIN ) ;
    SetPlayerColor ( playerid , green ) ;
 
}
main()
{
    print("\n----------------------------------");
    print("Nato vs Nordic Battlegroup 0.1");
    print("----------------------------------\n");
}

public OnGameModeInit()
{
    // Don't use these lines if it's a filterscript
    SetGameModeText("NatoVersusNbg 0.1");
    SetWorldTime ( 20 ) ;
    SetWeather ( 32 ) ;
    SetTimer(  "ChangeColors" , 300, true   );
    SetTimer ( " ScoreChecker " , 1000 , true ) ;
    SetTimer ( " ScoreUpdater " , 1000 , true ) ;
   
    AddPlayerClass(NATO_SKIN, 2868.1897,31.7935,18.8838,74.3923, 0, 0, 0, 0, 0, 0);//NATO
    AddPlayerClass(NBG_SKIN, 2051.9788,103.4475,27.9122,266.2756, 0, 0, 0, 0, 0, 0);//NBG
    AddStaticVehicle(432,2864.4141,13.6129,17.9085,26.6336,16,16); // rhino
    AddStaticVehicle(432,2868.0188,19.8851,18.1068,35.4451,16,16); // rhino
    AddStaticVehicle(470,2864.0542,34.6671,18.9800,25.4197,16,16); // bil
    AddStaticVehicle(470,2853.9705,43.4886,19.4960,50.7467,16,16); // bil
    AddStaticVehicle(470,2839.6084,49.0639,19.6825,75.2552,16,16); // bil
    AddStaticVehicle(470,2663.0771,19.1939,27.8309,69.5992,16,16); // bil
    AddStaticVehicle(470,2505.0854,-3.8631,26.2816,87.8508,16,16); // bil
    AddStaticVehicle(470,2432.3120,-22.7952,26.2842,90.1596,16,16); // bil
    AddStaticVehicle(470,2348.7190,13.8102,26.2838,0.3240,16,16); // bil
    AddStaticVehicle(470,2339.3931,152.6768,26.2827,179.2561,16,16); // bil
    AddStaticVehicle(470,2260.5557,96.4165,26.2818,86.9707,16,16); // bil
    AddStaticVehicle(470,2218.5332,67.7046,26.2872,170.1032,16,16); // bil
    AddStaticVehicle(470,1942.5725,165.9444,37.1519,251.2348,16,16); // bil
    AddStaticVehicle(470,1928.3862,170.7717,37.1565,251.2138,16,16); // bil
    AddStaticVehicle(470,1920.9911,173.2817,37.1534,251.2323,16,16); // bil
    AddStaticVehicle(432,1944.3578,178.5748,36.0315,241.5681,16,16); // rhino
    AddStaticVehicle(432,1959.5958,181.6335,34.1793,245.1802,16,16); // rhino
    AddStaticVehicle(470,2151.3318,-88.8684,2.5058,335.9564,16,16); // bil
    AddStaticVehicle(470,2259.7908,-23.5497,26.2839,268.4557,16,16); // bil
    AddStaticVehicle(470,2317.6167,-23.8494,26.2881,271.8190,16,16); // bil
    AddStaticVehicle(470,2399.1125,24.1619,26.2831,353.8328,16,16); // bil
    AddStaticVehicle(470,2428.4338,47.0192,26.2851,272.5341,16,16); // bil
    AddStaticVehicle(470,2496.5544,106.6998,26.2833,268.2408,16,16); // bil


    Textdraw0 = TextDrawCreate(496.000000, 122.000000, "~r~ NBG Kills~w~: 0");
    TextDrawBackgroundColor(Textdraw0, 255);
    TextDrawFont(Textdraw0, 1);
    TextDrawLetterSize(Textdraw0, 0.490000, 2.300000);
    TextDrawColor(Textdraw0, -1);
    TextDrawSetOutline(Textdraw0, 0);
    TextDrawSetProportional(Textdraw0, 1);
    TextDrawSetShadow(Textdraw0, 1);
   
    Textdraw1 = TextDrawCreate(489.000000, 150.000000, "~g~ NATO Kills~w~: 0");
    TextDrawBackgroundColor(Textdraw1, 255);
    TextDrawFont(Textdraw1, 1);
    TextDrawLetterSize(Textdraw1, 0.580000, 2.200000);
    TextDrawColor(Textdraw1, -1);
    TextDrawSetOutline(Textdraw1, 0);
    TextDrawSetProportional(Textdraw1, 1);
    TextDrawSetShadow(Textdraw1, 1);
    Textdraw3 = TextDrawCreate(499.000000, 4.000000, "FIGHT BITCH!");
    TextDrawBackgroundColor(Textdraw3, 255);
    TextDrawFont(Textdraw3, 1);
    TextDrawLetterSize(Textdraw3, 0.440000, 1.000000);
    TextDrawColor(Textdraw3, 842795570);
    TextDrawSetOutline(Textdraw3, 0);
    TextDrawSetProportional(Textdraw3, 1);
    TextDrawSetShadow(Textdraw3, 1);
   
   

    return 1;
}

public OnGameModeExit()
{
    TextDrawHideForAll ( Textdraw0 ) ;
    TextDrawDestroy ( Textdraw0 ) ;
    TextDrawHideForAll ( Textdraw1 ) ;
    TextDrawDestroy ( Textdraw1 ) ;
    TextDrawHideForAll ( Textdraw3 ) ;
    TextDrawDestroy ( Textdraw3 ) ;
    return 1;
}

public OnPlayerRequestClass(playerid, classid)
{
    SetPlayerPos(playerid, 2173.2681,1285.6477,24.4753);
    SetPlayerCameraPos(playerid, 2152.5364,1284.7275,28.7401);
    SetPlayerCameraLookAt(playerid, 2253.2341,1286.1797,19.1699);
    SetPlayerFacingAngle ( playerid , 80.8913 ) ;
    if ( classid == 1 )

    {
        GameTextForPlayer ( playerid , " ~r~ Nordic Battle Group " , 6000 , 4 ) ;
        gTeam[playerid] = TEAM_NBG;
       
    }
    if ( classid == 0 )

    {
        GameTextForPlayer ( playerid , " ~g~ NATO " , 6000 , 4 ) ;
        gTeam[playerid] = TEAM_NATO;
       
    }
   
    return 1;
}

public ScoreChecker(playerid)
{
    if ( NATOKills >= 20 ) {
        NBGKills = 0 ;
        NATOKills = 0 ;
        GameTextForAll ( " ~g~Nordic Battlegroup is retreating! NATO has succesfully defended San Andreas!  " , 6000 , 5) ;
        SetPlayerHealth(playerid, 0);
        }

    if ( NBGKills >= 20 ) {
        NATOKills = 0 ;
        NBGKills = 0 ;
        GameTextForAll ( " ~r~Nordic Battle Group has conquered San Andreas! " , 6000 , 5 ) ;
        SetPlayerHealth ( playerid , 0 ) ;
        }

    return 1;
}

public ScoreUpdater(playerid)
{
    new string[ 100 ] ;
    format ( string , sizeof ( string ) , " ~r~NBG Kills~w~: %s " , NBGKills ) ;
    TextDrawSetString ( Textdraw0 , string ) ;
    new string2 [ 100 ] ;
    format ( string2 , sizeof ( string2 ) , " ~g~NATO Kills~w~: %s " , NATOKills ) ;
    TextDrawSetString ( Textdraw1 , string2 ) ;
    return 1;
}

public OnPlayerConnect(playerid)
{
    new pname[MAX_PLAYER_NAME], string[22 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    format(string, sizeof(string), "%s has joined the server", pname);
    SendClientMessageToAll(0xAAAAAAAA, string);
   
    TextDrawShowForPlayer ( playerid , Textdraw0 ) ;
    TextDrawShowForPlayer ( playerid , Textdraw1 ) ;
    TextDrawShowForPlayer ( playerid , Textdraw3 ) ;
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    new pname[MAX_PLAYER_NAME], string[39 + MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    switch(reason)
    {
        case 0: format(string, sizeof(string), "%s has left the server. (Lost Connection)", pname);
        case 1: format(string, sizeof(string), "%s has left the server. (Leaving)", pname);
        case 2: format(string, sizeof(string), "%s has left the server. (Kicked)", pname);
    }
    SendClientMessageToAll(0xAAAAAAAA, string);
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if(gTeam[playerid] == TEAM_NBG)
    {
        SetNBGTeamSetUp(playerid);
    }
    if(gTeam[playerid] == TEAM_NATO)
    {
        SetNATOTeamSetUp(playerid);
    }

    return 1;
}


public OnPlayerDeath(playerid, killerid, reason)
{  
    SendDeathMessage ( killerid , playerid , reason ) ;
    SetPlayerScore( killerid ,GetPlayerScore( killerid ) +1 ) ;
       
    if ( killerid == TEAM_NBG )
    {
        NBGKills += 1 ;
    }
    if ( killerid == TEAM_NATO )
    {
        NATOKills += 1 ;
    }
    return 1;
}

public OnVehicleSpawn(vehicleid)
{
    return 1;
}

public OnVehicleDeath(vehicleid, killerid)
{
    return 1;
}

public OnPlayerText(playerid, text[])
{
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        GivePlayerMoney(playerid,500);
    }
    return 0;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveCheckpoint(playerid)
{
    return 1;
}

public OnPlayerEnterRaceCheckpoint(playerid)
{
    return 1;
}

public OnPlayerLeaveRaceCheckpoint(playerid)
{
    return 1;
}

public OnRconCommand(cmd[])
{
    return 1;
}

public OnPlayerRequestSpawn(playerid)
{
    return 1;
}

public OnObjectMoved(objectid)
{
    return 1;
}

public OnPlayerObjectMoved(playerid, objectid)
{
    return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    return 1;
}

public OnVehicleMod(playerid, vehicleid, componentid)
{
    return 1;
}

public OnVehiclePaintjob(playerid, vehicleid, paintjobid)
{
    return 1;
}

public OnVehicleRespray(playerid, vehicleid, color1, color2)
{
    return 1;
}

public OnPlayerSelectedMenuRow(playerid, row)
{
    return 1;
}

public OnPlayerExitedMenu(playerid)
{
    return 1;
}

public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    return 1;
}

public OnRconLoginAttempt(ip[], password[], success)
{
    return 1;
}

public OnPlayerUpdate(playerid)
{
    return 1;
}

public OnPlayerStreamIn(playerid, forplayerid)
{
    return 1;
}

public OnPlayerStreamOut(playerid, forplayerid)
{
    return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    return 1;
}

public OnVehicleStreamOut(vehicleid, forplayerid)
{
    return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
    return 1;
}
Reply
#2

Here you go man.

http://pastebin.com/NrUf18RD

I got rid of the timers because there is no need. It's a lot more efficient to just update the scores under OnPlayerDeath since that is the only time when they would change. I also fixed a few logic errors such as this one:

pawn Code:
if ( killerid == TEAM_NBG )

//Should be

if ( gTeam[killerid] == TEAM_NBG )
Because killerid is the id of the player who killed the other player. So you don't need to see if his id matches TEAM_NBG but if his gTeam variable matches it. And the reason the textdraws weren't updating is because you were formating them with %s which means string. You needed to be using %d for integer. Compiled fine and should be ready go now. Have fun.
Reply
#3

Quote:
Originally Posted by Backwardsman97
View Post
Here you go man.

http://pastebin.com/NrUf18RD

I got rid of the timers because there is no need. It's a lot more efficient to just update the scores under OnPlayerDeath since that is the only time when they would change. I also fixed a few logic errors such as this one:

pawn Code:
if ( killerid == TEAM_NBG )

//Should be

if ( gTeam[killerid] == TEAM_NBG )
Because killerid is the id of the player who killed the other player. So you don't need to see if his id matches TEAM_NBG but if his gTeam variable matches it. And the reason the textdraws weren't updating is because you were formating them with %s which means string. You needed to be using %d for integer. Compiled fine and should be ready go now. Have fun.
Thanks for "cleaning" up the mess in it! However, I just tested it and when I kill my enemy one of the textdraws disappears, and when I get killed the second textdraw disappears too. :/
Reply
#4

I'm pretty sure that's because there's a space at the beginning of the format. Try this out.

http://pastebin.com/byz4Uwab
Reply
#5

Works like a charm, thanks! However, I just encountered another bug. When 20 kills is reached, the gamemode wont restart. The gametext appears, but nothing else happens.
Reply
#6

That's because you haven't told it to do anything else. In this version it calls the rcon command gmx.

http://pastebin.com/tnZreAjP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)