Jump to content

Command handler - Very new to LUA


Riddy

Recommended Posts

Posted
function GivePlayerItem(player, item, amount) 
    local playerID = GetPlayerFromName(player) 
    if(playerID == true) then 
    setElementData(playerID,item,amount) 
    else  
    outputChatbox("The name is invalid", player); 
    end 
end  
  
addCommandHandler ( "createvehicle", GivePlayerItem ) 

Whats wrong? It gives me that, global thing mejic

Posted

Your code didn't make any sense.

  
function givePlayerItem(player, cmd, target, item, amount) 
  
    local targetid = getPlayerFromName(target) or outputChatBox("Player not found", player) 
    setElementData(targetid, "item." .. item, amount) 
     
end  
  
addCommandHandler ("giveitem", givePlayerItem) 
  

Check out the MTA Wiki. It helps.

Posted
function GivePlayerItem(player, item, amount) 
    local playerID = GetPlayerFromName(player) 
    if(playerID == true) then 
    setElementData(playerID,item,amount) 
    else  
    outputChatbox("The name is invalid", player); 
    end 
end  
  
addCommandHandler ( "createvehicle", GivePlayerItem ) 

Whats wrong? It gives me that, global thing mejic

1. Lua is case-sensitive.

2. The command is named "createvehicle", but the code has completely nothing to do with vehicle creation.

3. Second parameter of the function handler when adding a command is the command name, not "item".

4. ruoY edoc ylpmis seod ton ekam yna esnes.

Posted
Your code didn't make any sense.
  
function givePlayerItem(player, cmd, target, item, amount) 
  
    local targetid = getPlayerFromName(target) or outputChatBox("Player not found", player) 
    setElementData(targetid, "item." .. item, amount) 
     
end  
  
addCommandHandler ("giveitem", givePlayerItem) 
  

Check out the MTA Wiki. It helps.

I'll try that, thanks for the reply :D

Posted

-- Server :

function GivePlayerItem(player, item, amount) 
    local playerID = getPlayerFromName(player) 
    if( playerID == true ) then 
        setElementData(playerID,"item",amount) 
    else 
        outputChatBox("The name is invalid", player, 255, 0, 0, true) 
    end 
end  
  
addCommandHandler ( "giveitem", GivePlayerItem ) 

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