Nuke command not working properly.
#1

pawn Код:
CMD:nuke(playerid,params[])
{
    new string[150];
    if(InDMArena[playerid] == 1) return SCM(playerid, red, "[ERROR]"COL_WHITE" You cannot use this command while in the DM stadium.");
    if(gTeam[playerid] != TEAM_TFH) return SCM(playerid, red, "[ERROR]"COL_WHITE" Only horsemen can nuke players.");
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER or GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_ERROR,"[ERROR]"COL_WHITE" You cannot burn someone while in a vehicle. Exit the vehicle first.");
        return 1;
    }
    if(HasNukedRecently[playerid] >= 1)
    {
        format(string, sizeof(string),"[ERROR]"COL_WHITE" Please wait "COL_RED"%d seconds"COL_WHITE" before burning someone again.",HasNukedRecently[playerid]);
        SCM(playerid,red,string);
        return 1;
    }
    if(pInfo[playerid][XP] < 2000)
    {
        return SCM(playerid,red,"[ERROR]"COL_WHITE" Insufficient XP (2000)");
    }
    foreach(Player, i)
    {
        if(GetDistanceBetweenPlayers(playerid,i) <= 4 and i != playerid)
        {
            new Float:ARMOUR, Float:HEALTH;
            GetPlayerArmour(playerid, ARMOUR);
            GetPlayerHealth(playerid, HEALTH);
            HasNukedRecently[playerid] =500;
            new xp = pInfo[playerid][XP];
            pInfo[playerid][XP] =xp-2000;
            new Float:x, Float:y, Float:z;
            if(aDuty[i] == 0 and gTeam[i] != TEAM_TFH)
            {
                GetPlayerPos(i, x, y, z);
                CreateExplosion(x, y , z + 2, 1, 10);
                SetPlayerHealth(i, 0);
                format(Jstring,sizeof(Jstring),"[NUKE]"COL_WHITE" Horseman %s[%d] has used his/her nuke abillity.",GetName(playerid),playerid);
                SendClientMessageToAll(COLOR_TFH,Jstring);
                format(Jstring, sizeof(Jstring),"[NUKED]"COL_WHITE" %s[%d] has been killed by horseman %s[%d]'s nuke abillity.", GetName(i), i, GetName(playerid), playerid);
                SCMToAll(red, Jstring);
                SetPlayerArmour(playerid, ARMOUR);
                SetPlayerHealth(playerid, HEALTH);
            }
            return 1;
        }
        return SCM(playerid, red, "[ERROR]"COL_WHITE" No player is in range.");
    }
    return 1;
}
When I do /nuke, it says "No player is in range" even though players are in range. I know this is poorly scripted.
How can I fix this?

The main point of this CMD is when players are in range, they get killed with an explosion. But the player (who nuked others) won't. And also, aDuty (admins) and TFH team members should also not get killed.
Reply
#2

Bump
Reply
#3

What your code is doing is it will check through the first player in the loop and if they're not in range then it will say that there is no player in range. If you think about the logic of this:

-> Foreach executes
-> Pick first person in the Foreach loop (lets say ID 0)
-> Code determines ID 0 isn't in range
->
pawn Код:
return SCM(playerid, red, "[ERROR]"COL_WHITE" No player is in range.");
is called
-> Loop stops there.

So what you want to do is this:
pawn Код:
CMD:nuke(playerid,params[])
{
    new string[150];
    if(InDMArena[playerid] == 1) return SCM(playerid, red, "[ERROR]"COL_WHITE" You cannot use this command while in the DM stadium.");
    if(gTeam[playerid] != TEAM_TFH) return SCM(playerid, red, "[ERROR]"COL_WHITE" Only horsemen can nuke players.");
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER or GetPlayerState(playerid) == PLAYER_STATE_PASSENGER)
    {
        SendClientMessage(playerid,COLOR_ERROR,"[ERROR]"COL_WHITE" You cannot burn someone while in a vehicle. Exit the vehicle first.");
        return 1;
    }
    if(HasNukedRecently[playerid] >= 1)
    {
        format(string, sizeof(string),"[ERROR]"COL_WHITE" Please wait "COL_RED"%d seconds"COL_WHITE" before burning someone again.",HasNukedRecently[playerid]);
        SCM(playerid,red,string);
        return 1;
    }
    if(pInfo[playerid][XP] < 2000)
    {
        return SCM(playerid,red,"[ERROR]"COL_WHITE" Insufficient XP (2000)");
    }
    foreach(Player, i)
    {
        if(GetDistanceBetweenPlayers(playerid,i) <= 4 and i != playerid)
        {
            new Float:ARMOUR, Float:HEALTH;
            GetPlayerArmour(playerid, ARMOUR);
            GetPlayerHealth(playerid, HEALTH);
            HasNukedRecently[playerid] =500;
            new xp = pInfo[playerid][XP];
            pInfo[playerid][XP] =xp-2000;
            new Float:x, Float:y, Float:z;
            if(aDuty[i] == 0 and gTeam[i] != TEAM_TFH)
            {
                GetPlayerPos(i, x, y, z);
                CreateExplosion(x, y , z + 2, 1, 10);
                SetPlayerHealth(i, 0);
                format(Jstring,sizeof(Jstring),"[NUKE]"COL_WHITE" Horseman %s[%d] has used his/her nuke abillity.",GetName(playerid),playerid);
                SendClientMessageToAll(COLOR_TFH,Jstring);
                format(Jstring, sizeof(Jstring),"[NUKED]"COL_WHITE" %s[%d] has been killed by horseman %s[%d]'s nuke abillity.", GetName(i), i, GetName(playerid), playerid);
                SCMToAll(red, Jstring);
                SetPlayerArmour(playerid, ARMOUR);
                SetPlayerHealth(playerid, HEALTH);
            }
            return 1;
        }
    }
    return SCM(playerid, red, "[ERROR]"COL_WHITE" No player is in range.");
}
Reply
#4

This isn't really changing the code, but it's cleaning it up a little bit.

pawn Код:
CMD:nuke(playerid, params[])
{
    if(InDMArena[playerid]) return SCM(playerid, red, "[ERROR]"COL_WHITE" You cannot use this command while in the DM stadium.");
    if(gTeam[playerid] != TEAM_TFH) return SCM(playerid, red, "[ERROR]"COL_WHITE" Only horsemen can nuke players.");
    if(IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]"COL_WHITE" You cannot burn someone while in a vehicle. Exit the vehicle first.");
    if(HasNukedRecently[playerid])
    {
        new string[90];
        format(string, sizeof(string), "[ERROR]"COL_WHITE" Please wait "COL_RED"%d seconds"COL_WHITE" before burning someone again.", HasNukedRecently[playerid]);
        return SCM(playerid, red, string);
    }
    if(pInfo[playerid][XP] < 2000) return SCM(playerid, red, "[ERROR]"COL_WHITE" Insufficient XP (2000)");
    foreach(new i : Player)
    {
        if(i == playerid) continue;
        if(GetDistanceBetweenPlayers(playerid, i) > 4.0) continue;
        if(aDuty[i] || gTeam[i] == TEAM_TFH) continue;
        new Float:ARMOUR, Float:HEALTH;
        GetPlayerArmour(playerid, ARMOUR);
        GetPlayerHealth(playerid, HEALTH);
        HasNukedRecently[playerid] = 500;
        pInfo[playerid][XP] -= 2000;
        GetPlayerPos(i, x, y, z);
        CreateExplosion(x, y , z + 2, 1, 10.0);
        SetPlayerHealth(i, 0.0);
        new string[120];
        format(string, sizeof(string), "[NUKE]"COL_WHITE" Horseman %s[%d] has used his/her nuke abillity.", GetName(playerid), playerid);
        SendClientMessageToAll(COLOR_TFH, string);
        format(string, sizeof(string), "[NUKED]"COL_WHITE" %s[%d] has been killed by horseman %s[%d]'s nuke ability.", GetName(i), i, GetName(playerid), playerid);
        SCMToAll(red, string);
        SetPlayerArmour(playerid, ARMOUR);
        SetPlayerHealth(playerid, HEALTH);
        return 1;
    }
    return SCM(playerid, red, "[ERROR]"COL_WHITE" No player is in range.");
}
Reply
#5

found some literal "or" and "and" XD

make sure you have the latest a_samp.inc
https://sampwiki.blast.hk/wiki/CreateExplosionForPlayer
pawn Код:
CMD:nuke(playerid, params[])
{
    if(InDMArena[playerid])
    {
        return SCM(playerid, red, "[ERROR]"COL_WHITE" You cannot use this command while in the DM stadium.");
    }
    if(gTeam[playerid] != TEAM_TFH)
    {
        return SCM(playerid, red, "[ERROR]"COL_WHITE" Only horsemen can nuke players.");
    }
    if(IsPlayerInAnyVehicle(playerid))
    {
        return SendClientMessage(playerid, COLOR_ERROR, "[ERROR]"COL_WHITE" You cannot burn someone while in a vehicle. Exit the vehicle first.");
    }
    if(HasNukedRecently[playerid])
    {
        new string[90];
        format(string, sizeof(string), "[ERROR]"COL_WHITE" Please wait "COL_RED"%d seconds"COL_WHITE" before burning someone again.", HasNukedRecently[playerid]);
        return SCM(playerid, red, string);
    }
    if(pInfo[playerid][XP] < 2000) return SCM(playerid, red, "[ERROR]"COL_WHITE" Insufficient XP (2000)");
    new index;
    foreach(new i : Player)
    {
        if(i == playerid) continue;
        if(GetDistanceBetweenPlayers(playerid, i) > 4.0) continue;
        if(aDuty[i] || gTeam[i] == TEAM_TFH) continue;
        GetPlayerPos(i, x, y, z);
        CreateExplosionForPlayer(i,x, y , z + 2, 1, 10.0); // make sure you have the latest a_samp.inc (hint its in samp version 0.3z R2-2
        SetPlayerHealth(i, 0.0);
        new string[120];
        format(string, sizeof(string), "[NUKED]"COL_WHITE" %s[%d] has been killed by horseman %s[%d]'s nuke ability.", GetName(i), i, GetName(playerid), playerid);
        SCMToAll(red, string);
        index++;
    }
    if(index==0)
    {
        return SCM(playerid, red, "[ERROR]"COL_WHITE" No player is in range.");
    }
    pInfo[playerid][XP] -= 2000;
    HasNukedRecently[playerid] = 500;
    format(string, sizeof(string), "[NUKE]"COL_WHITE" Horseman %s[%d] has used his/her nuke abillity.", GetName(playerid), playerid);
    SendClientMessageToAll(COLOR_TFH, string);
   
}
Reply
#6

Well that was a silly mistake. Thanks for the help guys.


P.S: This:
pawn Код:
#define || or
#define && and
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)