Solved {list1::*} or {list2::*} contains. How to correctly do it

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Tinkot

Active Member
Feb 10, 2018
57
1
0
27
so i just figured out to check if a list variable contains a player.
code_language.skript:
if contains({_list1::*}, player) is true:
      broadcast "{_list1::*} contains the player!"

but i want to check if {_list1::*} or {_list2:*} contains a player. how can i do this?
 
code_language.skript:
if contains({_list1::*}, player) is true:
    broadcast "{_list1::*} contains the player!"
else if contains({_list2::*}, player) is true:
    broadcast "{_list2::*} contains the player!"
 
but now i have to duplicate everything. meaning, more code
[doublepost=1525810664,1525810188][/doublepost]nevermind. this entire thing is not working at all. i think my version is incompatibel. i need to find another method
 
its not that big of deal. i believe @Snow-Pyon or someone said theres a way to do an or but idk.

is that a default contains function? i didnt even know that existed its not on the docs https://bensku.github.io/Skript/functions.html but anyways just make your own contains function tbh
code_language.skript:
function contains(list1: players, list2: players, target: player) :: boolean:
    loop {_list1::*}:
        if loop-value is {_target}:
            return true
    loop {_list2::*}:
        if loop-value is {_target}:
            return true
    return false
 
the discord .contains brought me here. but its not working. Also I never worked with the function thing before.

i have this code below but its long and my skript is having this condition very often. I dont know how those loops affect server performance
code_language.skript:
        set {_counter} to 1
        loop {@PlayersPerTeam} times:
            if player is {{@Arena}.Team1::%{_counter}%} or {{@Arena}.Team2::%{_counter}%}:
                remove player from {{@Arena}.Team1::*}
                remove player from {{@Arena}.Team2::*}
                message "&cYou left the Match"
                execute console command "/tpspawn %player%"
                stop loop
            add 1 to {_counter}
[doublepost=1525810969,1525810896][/doublepost]this is the only method i found that can continue my skript within one section. instead of handling all of it twice
 
like i said the function i made above should work just plug in the lists and the player. if you want the function to be generic just change players to objects and player to object in line 1 of the function
 
wait, I dont have a good understanding about how the function thing works. Is it that you can call this anywhere in your skript? If yes, where can i learn more to get a better understanding about this. This requires addons? or is it vanilla skript
 
Looking awesome. Can you give me a quick example on how to add it in a skript with if statement?

also is code below correct?
code_language.skript:
function if(test: players, target: player) :: boolean:
    if player is {test}
        return true
    return false

command /test
    trigger:
        set {test} to player

command /function:
    trigger:
>>>>>(function if statement here):<<<<<<< #pls help me with this line
            message "hi"
 
idk if youre just testing with the {test} variable but the list would be referenced as {_test::*} and you would need to loop through it. also i wouldnt recommend naming the function if, skript probably can read it fine but it could cause confusion. regardless you do the same thing you were doing before with the contains function. with your function it would be
code_language.skript:
if if(<insert list>, <insert player>) is true: #you dont need the 'is true' but you can put it for clarification if you want
 
idk if youre just testing with the {test} variable but the list would be referenced as {_test::*} and you would need to loop through it. also i wouldnt recommend naming the function if, skript probably can read it fine but it could cause confusion. regardless you do the same thing you were doing before with the contains function. with your function it would be
code_language.skript:
if if(<insert list>, <insert player>) is true: #you dont need the 'is true' but you can put it for clarification if you want

so i what is <insert list> ? and i can replace "<insert player>" with "player"?
 
code_language.skript:
if {_list1::*} and {_list::2} contains {_something}:
 
hes wants orrrrrrrrrrrrrrrrrrr not and, and isnt contains of a list broken or did it finally get fixed
i know he wants or. what i posted will work correctly

also yes it got fixed in dev35
 
skript logic amirite
well, it kind of makes sense. when you do
code_language.skript:
{_list::*} and {_list2::*}
and result will be a list of the values in both lists (e.x. if {_list::*} contained 1, 2 and 3, and {_list2::*} contained 4, 5 and 6 the resulting list would be 1, 2, 3, 4, 5 and 6 which you can use contains on to check if either one contained the value you want.
 
not working in my version of skript. thats why im asking
[doublepost=1525816276,1525816159][/doublepost]
so i what is <insert list> ? and i can replace "<insert player>" with "player"?
do i really need to put in the list? or can i just include it in the function? i won't use "if list contains" variations very often. im just using like 2 list variables
 
Status
Not open for further replies.