spawnwep to ignore blocked weapon

Started by Nihongo^, Jul 15, 2023, 05:51 PM

Previous topic - Next topic

Nihongo^

In my server you have to purchase 2 weapons 
1) Rocket Launcer
2) Chainsaw

I've tried to modify spawnwep to prevent saved these weapons from player's spawnwep

when player tried to add these blocked weapons by /spawnwep m60 rocket it showed
You have to buy Rocket Launcher from the ammunation

but on the next moment it shows

You have set your spawnwep weapons to m60, RocketLauncher

I want spawnwep to highlight only the weapon which is not blocked and ignore these two weapons




here's my modify code

else if (cmd == "spawnwep") {
    if (text) {
        QuerySQL(db, "UPDATE SpawnWep SET Wep1='0',Wep2='0',Wep3='0',Wep4='0',Wep5='0',Wep6='0',Wep7='0',Wep8='0',Wep9='0' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'");
        local ptext = split(text " ");
        spawnwep[player.ID].SpawnWepStatus = true;
        QuerySQL(db, "UPDATE SpawnWep SET SpawnWepStatus='true' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'");
        local wepnames = "";
        local weaponsSet = false;  // Flag to track if any weapons were successfully set
        foreach (wep in ptext) {
            local weaponId = IsNum(wep) ? wep.tointeger() : GetWeaponID(wep);
            wepnames += wepnames != "" ? format(", %s", GetWeaponName(weaponId)) : GetWeaponName(weaponId);
            if (weaponId == 33) {
                ClientMessage("[#ea4335]-> Error: [#c0c0c0]Invalid Weapon ID/Name.", player, 0, 0, 0);
            } else if ( weaponId == 30 || weaponId == 11) {
                ErrorMessage("[#FF0000][Server] - [#FFFFFF]You have to buy [ " +GetWeaponName(weaponId)+ " ] from the ammunation", player);
            } else {
                QuerySQL(db, "UPDATE SpawnWep SET " + GetWepColumn(GetWeaponSlot(weaponId)) + "='" + weaponId + "' WHERE Name LIKE '" + escapeSQLString(player.Name) + "'");
                player.SetWeapon(weaponId, 99999);
                weaponsSet = true;  // Set the flag to true if at least one weapon is successfully set
            }
        }
        local q = QuerySQL(db, "SELECT * FROM SpawnWep WHERE Name = '" + escapeSQLString(player.Name) + "'");
        if (q != null) {
            spawnwep[player.ID].SpawnWeps = [GetSQLColumnData(q, 2).tointeger(), GetSQLColumnData(q, 3).tointeger(), GetSQLColumnData(q, 4).tointeger(), GetSQLColumnData(q, 5).tointeger(), GetSQLColumnData(q, 6).tointeger(), GetSQLColumnData(q, 7).tointeger(), GetSQLColumnData(q, 8).tointeger(), GetSQLColumnData(q, 9).tointeger(), GetSQLColumnData(q, 10).tointeger()];
        }
        if (weaponsSet) {  // Only display the success message if at least one weapon is successfully set
            MessagePlayer("[#00FF00][SPAWN WEP]: [#FFFFFF]You have set your spawn weapons to " + wepnames + " successfully!", player);
        }
        return 0;
    } else {
        MessagePlayer("[#FFFF00]Syntax: /spawnwep <Weps Name/ID>", player);
    }
}

Spawnwep i used
https://forum.vc-mp.org/index.php?topic=8846.msg52222#msg52222

Mohamed Boubekri

Try to change those lines and test it:-
else if ( weaponId == 30 && weaponId == 11)
{
return ErrorMessage("[#FF0000][Server] - [#FFFFFF]You have to buy [ " +GetWeaponName(weaponId)+ " ] from the ammunation", player);
}
else if ( weaponId != 30 && weaponId !=33 && weaponId != 11 )
| What now ? | Not yet ! |
Morrocan:- [ 🇲🇦 ].

habi

@Mohamed Boubekri, there is error in your code.

I think the error caused by wepname+=...

Put that line under else of if statement.

You are not getting Rocket Launcher - Only the message!

Nihongo^

Quote from: habi on Jul 16, 2023, 05:15 AM@Mohamed Boubekri, there is error in your code.

I think the error caused by wepname+=...

Put that line under else of if statement.

You are not getting Rocket Launcher - Only the message!
Damn, thank you habi its works

@Mohamed Boubekri thanks for your efforts too bro