Post: Getting all compatible weapon attachments
10-26-2015, 02:41 PM #1
BullyWiiPlaza
Climbing up the ladder
(adsbygoogle = window.adsbygoogle || []).push({}); I want to build a function which for example gives the player a random attachment for the currently held gun. However, I didn't find a script to restrict the attachments only to the ones the gun is allowed to have. The following code taken from You must login or register to view this content. is bugged due to it including lethals and tacticals as well as incompatible attachments for the chosen weapon so the results are pretty poor. Either it works or it gives me nothing which kinda sucks.

    giveRanomWeaponWithAttachment()
{
id = random(level.tbl_weaponids);
attachmentlist = id["attachment"]; // Returns all attachments in the game
attachments = strtok( attachmentlist, " " );
attachments[attachments.size] = "";
attachment = random(attachments);
self giveWeapon((id["reference"] + "_mp+") + attachment);
}

I basically need a function like this:
    getCompatibleAttachments(weapon)
{
// ...
return attachments;
}


I'm pretty sure something like this is already built-in because You must login or register to view this content.. Any ideas?

Nevermind, I just wrote both functions with help by the Sharpshooter GSC. They might work, I haven't tested them yet though. Kryptus

    giveRandomWeapon()
{
while(true)
{
id = random(level.tbl_weaponIDs);

if ((id["group"] != "weapon_launcher") && (id["group"] != "weapon_sniper") && (id["group"] != "weapon_lmg") && (id["group"] != "weapon_assault") && (id["group"] != "weapon_smg") && (id["group"] != "weapon_pistol") && (id["group"] != "weapon_cqb") && (id["group"] != "weapon_special"))
{
// Prevent connection interrupted freeze
wait 0.1;

continue;
}

chosenWeapon = id + "_mp";

self giveWeapon(chosenWeapon);
self switchToWeapon(chosenWeapon);

return;
}
}

giveRandomAttachment()
{
weapon = self getCurrentWeapon();
self takeWeapon(weapon);

foreach(weaponId in level.tbl_weaponIDs)
{
baseWeaponName = weaponId["reference"];

if(baseWeaponName + "_mp" == weapon)
{
attachmentList = weaponId["attachment"];
weaponWithAttachment = maps\mp\gametypes\shrp::addRandomAttachmentToWeaponName(baseWeaponName, attachmentList);
self giveWeapon(weaponWithAttachment);
self switchToWeapon(weaponWithAttachment);
}

wait 0.01;
}
}
(adsbygoogle = window.adsbygoogle || []).push({});

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo