Solved Ticket support system

  • 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.

Aralwen

Active Member
May 26, 2017
164
14
18
25
Hello everybody. I am trying to make a ticket support system. All the code is done, I just do not find how to define the creator of the ticket that will get his answer. I tried several things, I'm a little lost.

> I would like that with the command /support TEXT, it generates a ticket. This ticket can be answered with /answer IDTICKET TEXT. The player who created the ticket gets the answer.

The player must be anonymous.


Code:

code_language.skript:
command /support [<text>]:
  trigger:
    if arg 1 is set:
      set {ticketCreator::%player%} to player
      set {ticketId::%player%} to "%random integer between 0 and 9999%"
      send "&aYour request for help has been sent!"
      loop all players:
        if loop-player has the permission "Admin":
          send "" to loop-player
          send "&fA player has applied for help : &e%arg 1%" to loop-player
          send "" to loop-player
          make console execute command "tellraw %loop-player% {text:""&f» &6&lPROCESS THE REQUEST &f«"",clickEvent:{action:suggest_command,value:""/answer %{ticketId::%player%}% ""},hoverEvent:{action:show_text,value:""&eAnswer""}}"

command /answer [<text>] [<text>]:
  trigger:
    if {ticketId::%player%} is set:
      set {p} to {ticketCreator::%player%}
      delete {ticketCreator::%player%}
      delete {ticketId::%player%}
      send "&aYour reply has been sent!"
      send "" to {_p}
      send "&c%player% &fresponded to your request for help: &e%arg-text-2%" to {_p}
      send "" to {_p}

Thank's in advance !
[doublepost=1534983118,1534833096][/doublepost]Nobody has any idea? I still have not found :emoji_frowning:
 
Honestly I dont even know where to start. But your big problem here is you are setting a ticket to a player... and then when the admin checks it... your looping if a variable containing that player (the admin) is set... therefor its not going to get the same ticket. The way its written you wouldn't only be able to answer your own tickets.
 
Honestly I dont even know where to start. But your big problem here is you are setting a ticket to a player... and then when the admin checks it... your looping if a variable containing that player (the admin) is set... therefor its not going to get the same ticket. The way its written you wouldn't only be able to answer your own tickets.
I confess I do not understand too much... My only problem is that I do not know how to set the ticket id on the player to be able to answer it and that the player gets his answer. I tried several things, but nothing gives a concrete result.

Command: /support TEXT: Generates a ticket and sends it to all administrators
Command: /answer <TICKETID> TEXT: Respond to the player's ticket, mark as resolved (so no one can answer) and send the answer to the player who created the ticket.
 
Ill be honest with you its super hard to explain how to do all this without writing it myself.
You will need to find a way that when the player creates a ticket it creates an ID and that ID is sent to the admins.
Then the admin would run the command with said ID
You could use a variable like {ticket::your id here} with would have the players name in it, so when you sent it back, you send it to the player in the variable
 
Ill be honest with you its super hard to explain how to do all this without writing it myself.
You will need to find a way that when the player creates a ticket it creates an ID and that ID is sent to the admins.
Then the admin would run the command with said ID
You could use a variable like {ticket::your id here} with would have the players name in it, so when you sent it back, you send it to the player in the variable
If I understand correctly for the creation of ticket, I proceed like that?

code_language.skript:
set {_ticketId} to "%random integer between 0 and 9999%"
set {ticket::%{_ticketId}%} to player

Thank's for help :emoji_slight_smile:
 
The issue is that the way you structured your data does not match the parameters for your commands. You differentiated each ticket data by their player name, not by the ticket ID. Therefore, if you want to retrieve the ticket ID, you would need to reference the ticket player name first.

A solution without changing the original code is to create a function that gets the original ticket creator using only the ID:

code_language.skript:
function getTicketCreator(id: string) :: player:
    loop {ticketId::*}:
        if loop-value is {_id}: #If the requested ID matches with the ticket ID in {ticketId:**}
            return {ticketCreator::%loop-index%} #loop-index is the name of the player

After that, readjust your /answer command to fit the new function:

code_language.skript:
command /answer [<text>] [<text>]:
    trigger:
        set {_p} to getTicketCreator(arg-1) #Replace set {p} to {ticketCreator::%player%}
        set {_name} to {_p}'s name #Replacement of %player%
        if {ticketId::%{_name}%} is set:
            set {_p} to {ticketCreator::%{_name}%}
            delete {ticketCreator::%{_name}%}
            delete {ticketId::%{_name}%}
            send "&aYour reply has been sent!"
            send "" to {_p}
            send "&c%{_name}% &fresponded to your request for help: &e%arg-text-2%" to {_p}
            send "" to {_p}

Aside from the unrelated json error from your tellraw command, there seems to be no problem with this code based off testing.

However, there's a few things to note:
  • Your ticket ID is a string despite being meant as a number. This might be problematic in the future as anything you do with the ticket ID must accept string as a parameter, and not a number.
  • This is a "band-aid" fix. Imagine there are 9999 tickets in the system. That means the function has to go through every single ticket (all 9999 of them) or until it finds the correct one. It's really inefficient.
  • The real issue here is that the way you structured your data doesn't flow with your parameters. The parameters wants an ID, but the program can only differentiate data by the player name. Either change the parameters to the player's name (/answer PLAYERNAME text) to fit your data structure, or redesign your data structure to fit the parameters ( {ticket::id}, {ticket::id::name} ).
 
The issue is that the way you structured your data does not match the parameters for your commands. You differentiated each ticket data by their player name, not by the ticket ID. Therefore, if you want to retrieve the ticket ID, you would need to reference the ticket player name first.

A solution without changing the original code is to create a function that gets the original ticket creator using only the ID:

code_language.skript:
function getTicketCreator(id: string) :: player:
    loop {ticketId::*}:
        if loop-value is {_id}: #If the requested ID matches with the ticket ID in {ticketId:**}
            return {ticketCreator::%loop-index%} #loop-index is the name of the player

After that, readjust your /answer command to fit the new function:

code_language.skript:
command /answer [<text>] [<text>]:
    trigger:
        set {_p} to getTicketCreator(arg-1) #Replace set {p} to {ticketCreator::%player%}
        set {_name} to {_p}'s name #Replacement of %player%
        if {ticketId::%{_name}%} is set:
            set {_p} to {ticketCreator::%{_name}%}
            delete {ticketCreator::%{_name}%}
            delete {ticketId::%{_name}%}
            send "&aYour reply has been sent!"
            send "" to {_p}
            send "&c%{_name}% &fresponded to your request for help: &e%arg-text-2%" to {_p}
            send "" to {_p}

Aside from the unrelated json error from your tellraw command, there seems to be no problem with this code based off testing.

However, there's a few things to note:
  • Your ticket ID is a string despite being meant as a number. This might be problematic in the future as anything you do with the ticket ID must accept string as a parameter, and not a number.
  • This is a "band-aid" fix. Imagine there are 9999 tickets in the system. That means the function has to go through every single ticket (all 9999 of them) or until it finds the correct one. It's really inefficient.
  • The real issue here is that the way you structured your data doesn't flow with your parameters. The parameters wants an ID, but the program can only differentiate data by the player name. Either change the parameters to the player's name (/answer PLAYERNAME text) to fit your data structure, or redesign your data structure to fit the parameters ( {ticket::id}, {ticket::id::name} ).

It works perfectly, a really thank you for help!
Regarding the 9999 tickets (band-aid), I do not see how to proceed other than by set {ticketId::%player%} to "%random integer between 0 and 9999%"

Besides, would you know how to block the fact that a ticket can have the same ID? (although the probability of this happening is low)
 
Last edited:
the probability is VERY VERY low... but what i would do is set a variable to 1 like:
create a command to set {ids::newid} to 1... after its set you can remove the command
then do something like this
code_language.skript:
set {ticketId::%player%} to {ids::newid}
add 1 to {ids::newid}
then each time a ticket is created it adds 1 to the id thingy
 
the probability is VERY VERY low... but what i would do is set a variable to 1 like:
create a command to set {ids::newid} to 1... after its set you can remove the command
then do something like this
code_language.skript:
set {ticketId::%player%} to {ids::newid}
add 1 to {ids::newid}
then each time a ticket is created it adds 1 to the id thingy
Not stupid, I will proceed this way. Thank you !
 
Status
Not open for further replies.