Jump to content

help with function


SrFilif

Recommended Posts

addCommandHandler("trabajar", function(player, cmd)
    if not player:isInVehicle() then
        for i, marker in ipairs(MarkersCarpintero) do
            if player:isWithinMarker(marker) then
                local mjob = marker:getData("MarkerJob")

                if mjob == "Carpintero" then
                    local currentJob = player:getData("Roleplay:trabajo")
                    if currentJob == "Carpintero" then
                        removeElementData(player, "objeto")
                        removeElementData(player, "silla")
                        player:outputChat("¡Ya estás trabajando aquí!", 150, 50, 50, true)
                    else
                        if currentJob == "" then
                            removeElementData(player, "objeto")
                            removeElementData(player, "silla")
                            player:setData("Roleplay:trabajo", "Carpintero")
                            marker:setData("MarkerJob", "Carpintero") -- Actualizamos el valor del trabajo en el marcador
                            player:outputChat("¡Bienvenido al trabajo de #ffff00Carpintero#ffffff!", 255, 255, 255, true)
                            player:outputChat("#ffFFffRecoge una pila de madera y ve a la mesa para elaborar el item", 255, 255, 255, true)
                        else
                            player:outputChat("Ya tienes trabajo como " .. currentJob .. ".", 255, 255, 255, true)
                        end
                    end
                end
            end
        end
    end
end)

Well people I am creating a work system for my server, everything is fine now, but I can't find the error, here I explain how it works or what I want the script to do

- If you don't have a job, I'll give you the job
- If you already have the job, tell you in an outputchat
- If you already work elsewhere, let me tell you and where I work

I would really appreciate if you explain to me :3

Link to comment

Sure, I'd be happy to help you understand the script and explain how it works.

This script appears to be a part of a game server work system. The main function addCommandHandler is used to handle the command "trabajar" (which means "work" in Spanish) that players can execute in the game.

Here's a step-by-step explanation of how the script works:

  1. The script checks if the player executing the command is not currently in a vehicle (if not player:isInVehicle() then). This is probably to prevent players from starting work while in a vehicle.

  2. It then loops through a list of "MarkersCarpintero". These markers might represent locations or areas in the game world where the player can work as a "Carpintero" (carpenter).

  3. For each marker, the script checks if the player is within the range of the marker (if player:isWithinMarker(marker) then).

  4. If the player is within the marker, it checks if the player's current job is "Carpintero" (if mjob == "Carpintero" then).

  5. If the player's current job is "Carpintero," the script checks if the player already has the job ("Carpintero") as data (if currentJob == "Carpintero" then). If yes, it means the player is already working as a carpenter, and it displays an output message telling the player that they are already working there.

  6. If the player does not have the job of "Carpintero," it checks if the player has no job at all (if currentJob == "" then). If the player has no job, it assigns the job "Carpintero" to the player as data (player:setData("Roleplay:trabajo", "Carpintero")) and updates the marker's data to indicate it's a carpenter job marker (marker:setData("MarkerJob", "Carpintero")).

  7. If the player has a job other than "Carpintero," it displays an output message telling the player what their current job is.

  8. The script also has some removeElementData lines to remove any previous job-related data ("objeto" and "silla") from the player, probably to avoid conflicts or errors when assigning a new job.

In summary, the script allows players to work as a carpenter if they are near a carpenter job marker and meet the specified conditions. If they are already working as a carpenter, it tells them they are already working there. If they have a different job, it informs them of their current job.

It's important to note that this script only handles the "trabajar" command and the carpenter job. Depending on the entire game server setup, there might be other commands and jobs implemented separately. Also, it's crucial to ensure that the variables MarkersCarpintero and the functions like player:isWithinMarker() and player:setData() are correctly defined and implemented elsewhere in the script or resource. If they are not defined or implemented correctly, the script might not work as expected.

  • Like 1
Link to comment
2 minutes ago, ExMohmD said:

Sure, I'd be happy to help you understand the script and explain how it works.

This script appears to be a part of a game server work system. The main function addCommandHandler is used to handle the command "trabajar" (which means "work" in Spanish) that players can execute in the game.

Here's a step-by-step explanation of how the script works:

  1. The script checks if the player executing the command is not currently in a vehicle (if not player:isInVehicle() then). This is probably to prevent players from starting work while in a vehicle.

  2. It then loops through a list of "MarkersCarpintero". These markers might represent locations or areas in the game world where the player can work as a "Carpintero" (carpenter).

  3. For each marker, the script checks if the player is within the range of the marker (if player:isWithinMarker(marker) then).

  4. If the player is within the marker, it checks if the player's current job is "Carpintero" (if mjob == "Carpintero" then).

  5. If the player's current job is "Carpintero," the script checks if the player already has the job ("Carpintero") as data (if currentJob == "Carpintero" then). If yes, it means the player is already working as a carpenter, and it displays an output message telling the player that they are already working there.

  6. If the player does not have the job of "Carpintero," it checks if the player has no job at all (if currentJob == "" then). If the player has no job, it assigns the job "Carpintero" to the player as data (player:setData("Roleplay:trabajo", "Carpintero")) and updates the marker's data to indicate it's a carpenter job marker (marker:setData("MarkerJob", "Carpintero")).

  7. If the player has a job other than "Carpintero," it displays an output message telling the player what their current job is.

  8. The script also has some removeElementData lines to remove any previous job-related data ("objeto" and "silla") from the player, probably to avoid conflicts or errors when assigning a new job.

In summary, the script allows players to work as a carpenter if they are near a carpenter job marker and meet the specified conditions. If they are already working as a carpenter, it tells them they are already working there. If they have a different job, it informs them of their current job.

It's important to note that this script only handles the "trabajar" command and the carpenter job. Depending on the entire game server setup, there might be other commands and jobs implemented separately. Also, it's crucial to ensure that the variables MarkersCarpintero and the functions like player:isWithinMarker() and player:setData() are correctly defined and implemented elsewhere in the script or resource. If they are not defined or implemented correctly, the script might not work as expected.

Thats True , Use it

 

 

Edited by FullOffeD
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...