High Value Target Script?
#1

Ok.

I want a script that randomly picks a player(On Restart/Start up) and states them a 'HVT' meaning there the high value target and the person that kills HVT is now the HVT and so on...How can i do this?

EDIT: and how can i make the HVT change marker color and flash on map?
Reply
#2

Add This at Top of your GM:
pawn Код:
new Target = -1;
new ColorCase;
new ColorBlip = -1;
That's what you have to add under the Callbacks:
pawn Код:
public OnGameModeInit()
{
    SetTimer("ChooseNewHVT", 2000, 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(playerid == Target) ChooseNewHVT();
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(playerid == Target && killerid == INVALID_PLAYER_ID) ChooseNewHVT();
    else
    {
        new string[128], PlayerName[MAX_PLAYER_NAME], KillerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
        GetPlayerName(killerid, KillerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) has killed the High Value Target '%s (ID:%d)' !", KillerName, killerid, PlayerName, playerid);
        SendClientMessageToAll(COLOR_BLUE, string);
        MakePlayerHVT(playerid);
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/hvt", cmdtext, true))
    {
        new string[128], PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(Target, PlayerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) is the High Value Target! Kill him!", PlayerName, Target);
        SendClientMessage(playerid, COLOR_RED, string);
        return 1;
    }
    return 0;
}
Add this at Bottom of your GM:
pawn Код:
forward ChooseNewHVT();
public ChooseNewHVT()
{
    new playerid = GetRandomPlayer();
    if(playerid == -1) return SetTimer("ChooseNewHVT", 2000, 0);
    else return MakePlayerHVT(playerid);
}

forward ChangeColor(playerid);
public ChangeColor(playerid)
{
    if(ColorCase == 0) SetPlayerColor(playerid, COLOR_YELLOW), ColorCase++;
    else SetPlayerColor(playerid, COLOR_RED), ColorCase = 0;
    return 1;
}

stock MakePlayerHVT(playerid)
{
    new string[128], PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    format(string, 128, "[High Value Target] %s (ID:%d) is now the High Value Target! Kill him!", PlayerName, playerid);
    SendClientMessageToAll(COLOR_RED, string);
    Target = playerid;
    if(ColorBlip != -1) KillTimer(ColorBlip);
    ColorBlip = SetTimerEx("ChangeColor", 1000, 1, "d", playerid);
    for(new i=0; i<MAX_PLAYERS; i++) SetPlayerColor(i, COLOR_BLUE); //All others are blue now.
    SetPlayerColor(playerid, COLOR_RED); // Just the Target is red/yellow blipping.
    return 1;
}

stock GetRandomPlayer() // By MadeMan, modified by me.
{
    new ConnectedPlayers[MAX_PLAYERS];
    new idx;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[idx] = i;
            idx++;
        }
    }
    if(idx == 0) return -1;
    else return ConnectedPlayers[random(idx)];
}

I hope this helps you. If you have any questions, or Errors, just ask me.

Regards,
Jeffry
Reply
#3

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Add This at Top of your GM:
pawn Код:
new Target = -1;
new ColorCase;
new ColorBlip = -1;
That's what you have to add under the Callbacks:
pawn Код:
public OnGameModeInit()
{
    SetTimer("ChooseNewHVT", 2000, 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(playerid == Target) ChooseNewHVT();
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(playerid == Target && killerid == INVALID_PLAYER_ID) ChooseNewHVT();
    else
    {
        new string[128], PlayerName[MAX_PLAYER_NAME], KillerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
        GetPlayerName(killerid, KillerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) has killed the High Value Target '%s (ID:%d)' !", KillerName, killerid, PlayerName, playerid);
        SendClientMessageToAll(COLOR_BLUE, string);
        MakePlayerHVT(playerid);
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/hvt", cmdtext, true))
    {
        new string[128], PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(Target, PlayerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) is the High Value Target! Kill him!", PlayerName, Target);
        SendClientMessage(playerid, COLOR_RED, string);
        return 1;
    }
    return 0;
}
Add this at Bottom of your GM:
pawn Код:
forward ChooseNewHVT();
public ChooseNewHVT()
{
    new playerid = GetRandomPlayer();
    if(playerid == -1) return SetTimer("ChooseNewHVT", 2000, 0);
    else return MakePlayerHVT(playerid);
}

forward ChangeColor(playerid);
public ChangeColor(playerid)
{
    if(ColorCase == 0) SetPlayerColor(playerid, COLOR_YELLOW), ColorCase++;
    else SetPlayerColor(playerid, COLOR_RED), ColorCase = 0;
    return 1;
}

stock MakePlayerHVT(playerid)
{
    new string[128], PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    format(string, 128, "[High Value Target] %s (ID:%d) is now the High Value Target! Kill him!", PlayerName, playerid);
    SendClientMessageToAll(COLOR_RED, string);
    Target = playerid;
    if(ColorBlip != -1) KillTimer(ColorBlip);
    ColorBlip = SetTimerEx("ChangeColor", 1000, 1, "d", playerid);
    for(new i=0; i<MAX_PLAYERS; i++) SetPlayerColor(i, COLOR_BLUE); //All others are blue now.
    SetPlayerColor(playerid, COLOR_RED); // Just the Target is red/yellow blipping.
    return 1;
}

stock GetRandomPlayer() // By MadeMan, modified by me.
{
    new ConnectedPlayers[MAX_PLAYERS];
    new idx;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[idx] = i;
            idx++;
        }
    }
    if(idx == 0) return -1;
    else return ConnectedPlayers[random(idx)];
}

I hope this helps you. If you have any questions, or Errors, just ask me.

Regards,
Jeffry
Код:
for(new i=0; i<MAX_PLAYERS; i++) SetPlayerColor(i, COLOR_BLUE); //All others are blue now.
Does this make players colors blue? I have teams with colors i need normal players to stay the same and just HVT to flash there color + white


EDIT: sorry i didnt state that originaly..
Reply
#4

Yeah, then remove this. Or well, you can also give me the code part where you set the Team Members color.
Then I can modify it so it works for your team code.
Reply
#5

Код:
public OnPlayerSpawn(playerid)
{
        Kills[playerid] = 0;
        SetPlayerHealth(playerid,99999);
        SetTimerEx("AntiSpawnKill",10000,0,"i",playerid);
        StartCheckpointSeeking();
        SetPlayerInterior(playerid,0);
        
        GangZoneShowForAll(usa,GREEN);
        GangZoneShowForAll(china,YELLOW);
        GangZoneShowForAll(upetrol,BLUE);
        GangZoneShowForAll(sapla,RED);
        GangZoneShowForAll(merc,PURPLE);

        if(gTeam[playerid] == TEAM_USA)
		{
		SetPlayerArmour(playerid, 100);
		SetPlayerHealth(playerid, 100);
		SetPlayerTeam(playerid, 0);
        SetPlayerColor(playerid,GREEN);
        SendClientMessage(playerid, GREEN, "[Operation Liberate]:The Rivals Are Stealing Our Fuel! Liberate It Back,At All Costs!");
        SendClientMessage(playerid, GREEN, "[Commands]:Use /rules Before Playing! Use /help For Info And /cmds For Available Commands.");
        }
        else if(gTeam[playerid] == TEAM_CHINA)
		{
		SetPlayerArmour(playerid, 100);
		SetPlayerHealth(playerid, 100);
		SetPlayerTeam(playerid, 1);
        SetPlayerColor(playerid,YELLOW);
        SendClientMessage(playerid, YELLOW, "[Operation Liberate]:The Rivals Are Stealing Our Fuel! Liberate It Back,At All Costs!");
        SendClientMessage(playerid, YELLOW, "[Commands]:Use /rules Before Playing! Use /help For Info And /cmds For Available Commands.");
        }
        else if(gTeam[playerid] == TEAM_UP)
		{
		SetPlayerArmour(playerid, 100);
		SetPlayerHealth(playerid, 100);
		SetPlayerTeam(playerid, 2);
        SetPlayerColor(playerid,BLUE);
        SendClientMessage(playerid, BLUE, "[Operation Liberate]:The Rivals Are Stealing Our Fuel! Liberate It Back,At All Costs!");
        SendClientMessage(playerid, BLUE, "[Commands]:Use /rules Before Playing! Use /help For Info And /cmds For Available Commands.");
        }
        else if(gTeam[playerid] == TEAM_SAPLA)
		{
		SetPlayerArmour(playerid, 100);
		SetPlayerHealth(playerid, 100);
		SetPlayerTeam(playerid, 3);
        SetPlayerColor(playerid,RED);
        SendClientMessage(playerid, RED, "[Operation Liberate]:The Rivals Are Stealing Our Fuel! Liberate It Back,At All Costs!");
        SendClientMessage(playerid, RED, "[Commands]:Use /rules Before Playing! Use /help For Info And /cmds For Available Commands.");
        }
        else if(gTeam[playerid] == CLASS_MERC)
		{
		SetPlayerArmour(playerid, 100);
		SetPlayerHealth(playerid, 100);
		SetPlayerTeam(playerid, 4);
        SetPlayerColor(playerid,PURPLE);
        SendClientMessage(playerid, PURPLE, "[Classified]:Control The Situation,Bring Down The Enemys,Take Fuel At No Mercy,Airstikes At Your Disposal!");
        SendClientMessage(playerid, PURPLE, "[Commands]:Use /rules Before Playing! Use /help For Info And /cmds For Available Commands.");
		}
Here it is....I want the HVT's color to Flash there Team color and and White...

EDIT: If people dont know yet all i had to add for ANTI-TEAM KILL is this 1 line
Код:
SetPlayerTeam(playerid, 1);
xD
Reply
#6

Modified version:

Add This at Top of your GM:
pawn Код:
new Target = -1;
new ColorCase;
new ColorBlip = -1;
That's what you have to add under the Callbacks:
pawn Код:
public OnGameModeInit()
{
    SetTimer("ChooseNewHVT", 2000, 0);
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(playerid == Target) ChooseNewHVT();
    return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    if(playerid == Target && killerid == INVALID_PLAYER_ID) ChooseNewHVT(), SetPlayerColor(playerid, GetPlayerTeamColor(playerid));
    else
    {
        new string[128], PlayerName[MAX_PLAYER_NAME], KillerName[MAX_PLAYER_NAME];
        GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
        GetPlayerName(killerid, KillerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) has killed the High Value Target '%s (ID:%d)' !", KillerName, killerid, PlayerName, playerid);
        SendClientMessageToAll(COLOR_BLUE, string);
        MakePlayerHVT(playerid);
    }
    return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
    if (!strcmp("/hvt", cmdtext, true))
    {
        new string[128], PlayerName[MAX_PLAYER_NAME];
        GetPlayerName(Target, PlayerName, MAX_PLAYER_NAME);
        format(string, 128, "[High Value Target] %s (ID:%d) is the High Value Target! Kill him!", PlayerName, Target);
        SendClientMessage(playerid, COLOR_RED, string);
        return 1;
    }
    return 0;
}
Add this at Bottom of your GM:
pawn Код:
forward ChooseNewHVT();
public ChooseNewHVT()
{
    new playerid = GetRandomPlayer();
    if(playerid == -1) return SetTimer("ChooseNewHVT", 2000, 0);
    else return MakePlayerHVT(playerid);
}

forward ChangeColor(playerid);
public ChangeColor(playerid)
{
    if(ColorCase == 0) SetPlayerColor(playerid, GetPlayerTeamColor(playerid)), ColorCase++;
    else SetPlayerColor(playerid, WHITE), ColorCase = 0;
    return 1;
}

stock GetPlayerTeamColor(playerid)
{
    if(gTeam[playerid] == TEAM_USA) return GREEN;
    else if(gTeam[playerid] == TEAM_CHINA) return YELLOW;
    else if(gTeam[playerid] == TEAM_UP) return BLUE;
    else if(gTeam[playerid] == TEAM_SAPLA) return RED;
    else if(gTeam[playerid] == CLASS_MERC) return PURPLE;
    else return WHITE;
}

stock MakePlayerHVT(playerid)
{
    new string[128], PlayerName[MAX_PLAYER_NAME];
    GetPlayerName(playerid, PlayerName, MAX_PLAYER_NAME);
    format(string, 128, "[High Value Target] %s (ID:%d) is now the High Value Target! Kill him!", PlayerName, playerid);
    SendClientMessageToAll(COLOR_RED, string);
    Target = playerid;
    if(ColorBlip != -1) KillTimer(ColorBlip);
    ColorBlip = SetTimerEx("ChangeColor", 1000, 1, "d", playerid);
    SetPlayerColor(playerid, WHITE);
    return 1;
}

stock GetRandomPlayer() // By MadeMan, modified by me.
{
    new ConnectedPlayers[MAX_PLAYERS];
    new idx;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            ConnectedPlayers[idx] = i;
            idx++;
        }
    }
    if(idx == 0) return -1;
    else return ConnectedPlayers[random(idx)];
}

Try it, should work for your colors now.

For more questions, just ask. ^^

Regards,
Jeffry
Reply
#7

Thansk so much man!

BTW: i get this warning with this function,Can you fix it..Im sure i use it elsewere in the GM,Is that why i get there error>?

Код:
C:\Users\Weponz\Desktop\Server Files\gamemodes\M-SAIF.pwn(1735) : warning 219: local variable "ConnectedPlayers" shadows a variable at a preceding
Reply
#8

To fix the warning:

pawn Код:
stock GetRandomPlayer() // By MadeMan, modified by me.
{
    new xConnectedPlayers[MAX_PLAYERS];
    new idx;
    for(new i=0; i < MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            xConnectedPlayers[idx] = i;
            idx++;
        }
    }
    if(idx == 0) return -1;
    else return xConnectedPlayers[random(idx)];
}
The problem that if someone uses /q he is still Target is actually strange.
Have you added this:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(playerid == Target) ChooseNewHVT();
    return 1;
}
?
Reply
#9

Quote:
Originally Posted by Jeffry
Посмотреть сообщение
Have you added this:

pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    if(playerid == Target) ChooseNewHVT();
    return 1;
}
?
Yes :SSS
Reply
#10

Is there only you in the server?
I mean, the script picks ONE random player of all connected players, so if there is only you, it will always be you who will be chosen.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)