Jump to content

Help creating a function


Il_Picasso

Recommended Posts

I am trying to create a simple command that gives you items 

What I want at the end is to create a command that gives a set of items to another player

 

But first I started with this 

 

http://f.cgm.rs/2017-07-14_18-30-09.txt
What I am trying to do there

First check if the command is executed, then check if the player executing the command is a GM and then iterate to give all items in the array

Link to comment
Share on other sites

I recommend using the command hook instead of chat.
Also the command is never run because nobody has a negative GM rank. Normal player is at 0 usually.
It seems you used Player instead of player at one point. Lua is case sensitive.
When you ask for help with something please provide error messages and tell what the issue is.

I made this diff from your script and my suggested changes, check it out:
https://www.diffchecker.com/34YIY3ZN
I did not however change the required GM rank yet.

Link to comment
Share on other sites

Thanks!

 

Yes , its just no error log was generated

 

anyway, this is the working script, I changed Player:AddItem to player:AddItem and player:GetGMRank() < 0 to player:GetGMRank() > 0

local command = "dar"; -- here we define "command" as local variable with a string value of "buff". I defined it as a `local` outside any functions so it is localized to this Lua file only.
local items = {}; -- here i define the variable `buff` as an empty table (Without data).again i have defined it as a local outside any functions so it is localized to this Lua file only.

items = {42952,48716}; -- Here I will now store data in the table named `buff`. each id separated by a comma. each spot will be a unique address piece(1,2,3,4,5,6.....) accessed by using the full adress. so to puff a player with buff id '43223' i will use the command `player:AddAura(buff[6], player)` and the player will get buffed with 43223.

local function OnCommand(event, player, cmd)
    if(cmd:lower():find(command) == 1)then -- here we chech every chat message (converting it to `lower`case) to see if it matches absolute(==) the string stored in the variable `command`.
        if(player:GetGMRank() > 0) then
            player:SendBroadcastMessage("Tienes Nivel Suficiente")
            local entry_id; -- here i am defining a variable i will use ONLY inside this function so when its local inside a function it will be localized to only that function and you can make a new variable inside another function using the same name but different stored data.
            for entry_id = 1, #items do -- here i am starting a loop. telling it that entry_id will be from 1 to the max size of the `buff` table (#buff).
                player:AddItem(items[entry_id], 1); -- now using the full address to pinpoint a location of stored data we will apply the data as a buff to the player.
            end -- end for when our current loop is complete and increase entry_id +1 or if entry_id value is the max size for the loop then end and exit the loop.
        else
            player:SendBroadcastMessage("No tienes nivel GM suficiente")
        end
        return false -- return false to indicate to the core that we dont want to show command not found error
    end -- end for the end of our if statement.
end -- end of function end.

RegisterPlayerEvent(42, OnCommand)

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use