UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

tutorial(random trigger activation)

broken avatar :(
Created 3 weeks ago
by Dev Der Riese Style
0 Members and 1 Guest are viewing this topic.
99 views
broken avatar :(
×
broken avatar :(
Location: ru
Date Registered: 19 March 2021
Last active: 2 days ago
Posts
60
Respect
Forum Rank
Rotting Walker
Primary Group
Member
×
Dev Der Riese Style's Contact & Social Links
I am providing a script that allows activating a trigger randomly, for example:
when the game starts, any of the three available triggers can be activated, meaning after restarting the match, a different trigger might be available for activation first, the other two triggers are disabled; after the player activates the first trigger, the second trigger becomes available for activation, completely randomly, the third trigger is disabled at this time.After all triggers are activated, some action will occur, for example, the player will receive a reward.
 
If you use this on your map, don't forget to credit me for this script.
 

Do not forget to call the script in main()
 
 level thread randomize_triggers();
 
_zombie_mapname.gsc
cpp
///************!!!Script author: Dev Der riese style************\\\

randomize_triggers()
{
    // Create an array of triggers
    level.triggers_num = [];
    level.triggers_num[0] = getEnt("ee_trigger_1", "targetname");
    level.triggers_num[1] = getEnt("ee_trigger_2", "targetname");
    level.triggers_num[2] = getEnt("ee_trigger_3", "targetname");

    randomTriggers = [];
    indexList = [];

    // Create a list of indices for shuffling
    for (i = 0; i < level.triggers_num.size; i++)
    {
        indexList[i] = i;
    }

    // Shuffle the indices
    while (indexList.size > 0)
    {
        i = randomInt(indexList.size);
        randomTriggers[randomTriggers.size] = level.triggers_num[indexList[i]];

        // Remove the current index by replacing it with the last one
        temp = indexList[i];
        indexList[i] = indexList[indexList.size - 1];
        indexList[indexList.size - 1] = temp;
       
        indexList = removeLastElement(indexList); // Remove the last element from indexList
    }

    // Determine the first random trigger and others
    initTrigger = randomTriggers[0];
    secondTrigger = randomTriggers[1];
    thirdTrigger = randomTriggers[2];

    // Make other triggers inactive at the start of the game
    disableTrigger(secondTrigger);
    disableTrigger(thirdTrigger);

    level.triggers_activated = 0; // Counter for activated triggers

    // Configuration for the first trigger to be activated
    if (isDefined(initTrigger))
    {
        initTrigger setHintString("Press ^3[{+activate}]^7 to activate");
        initTrigger setCursorHint("HINT_NOICON");
       
        // Wait for the first trigger to be activated
        initTrigger waittill("trigger", player);
        initTrigger setHintString(""); // Remove hint
        level.triggers_activated++;
        initTrigger delete(); // Remove trigger

        // Activate the remaining triggers individually
        activateRemainingTrigger(secondTrigger);
        activateRemainingTrigger(thirdTrigger);
    }
}

// Disables trigger by removing hint and cursor icon
disableTrigger(trigger)
{
    if (isDefined(trigger))
    {
        trigger setCursorHint("HINT_NOICON"); // Set no icon for cursor
        trigger setHintString(""); // Clear hint string
    }
}

// Activates a single remaining trigger
activateRemainingTrigger(trigger)
{
    if (isDefined(trigger))
    {
        trigger setHintString("Press ^3[{+activate}]^7 to activate");
        trigger setCursorHint("HINT_NOICON");
       
        // Wait for activation
        trigger waittill("trigger", player);
        trigger setHintString(""); // Remove hint
        level.triggers_activated++;
        trigger delete(); // Remove trigger

        // Check if all triggers are activated
        if (level.triggers_activated == 3)
        {
            giveReward(player); // Grant reward
        }
    }
}

// Helper function to remove the last element from an array
removeLastElement(array)
{
    array[array.size - 1] = undefined;
    return array;
}

// Function to grant a reward to the player
giveReward(player)
{
    player iPrintlnBold("^2Congratulations! You've activated all triggers and earned your reward!");
    player giveweapon ("rpk_zm"); // Give weapon as the reward
}

 

 
Loading ...