Jump to content

Command Make help


mremin

Recommended Posts

addEventHandler ("onPlayerChat",getRootElement(), 
function(message,type) 
  if (string.find(message,"!points")) and not (string.find(message," !points")) then 
    local playerPoints = loadPlayerData (source,"points") 
    setTimer(outputChatBox,50,1,getPlayerName (source) .. " #FF0000has " .. tostring(playerPoints) .. " points!",getRootElement(),255,0,0,true) 
  elseif (string.find(message,"!cash")) and not (string.find(message," !cash")) then 
    local playerCash = loadPlayerData (source,"cash") 
    setTimer(outputChatBox,50,1,getPlayerName (source) .. " #FF0000has " .. tostring(playerCash) .. "$!",getRootElement(),255,0,0,true) 

how can i make !cash [name] or /cash [name]???

Link to comment
  • Discord Moderators
  
function getPlayerCash (source, cmd, player) -- function to check for player cash. First variable is the player who called it, second is dummy and third is optional who argument 
    local player = player or source -- if third parameter player doesn't exist, we use it on the source 
    local playerPoints = loadPlayerData (player, 'cash') -- get his money 
    outputChatBox (getPlayerName (player)..' #FF0000has '..tostring (playerPoints)..'$!', root, 255, 0, 0, true) -- output to everyone, how much cash the person has 
end 
  
function getPlayerPoints (source, cmd, player) -- function to check for player points. First variable is the player who called it, second is dummy and third is optional who argument 
    local player = player or source -- if third parameter player doesn't exist, we use it on the source 
    local playerPoints = loadPlayerData (player, 'points') -- get his points 
    outputChatBox (getPlayerName (player)..' #FF0000has '..tostring (playerPoints)..' points!', root, 255, 0, 0, true) -- output to everyone, how much cash the person has 
end 
  
addCommandHandler ('cash', getPlayerCash) -- attach /cash to function getPlayerCash 
addCommandHandler ('points', getPlayerPoints) -- attach /points to function getPlayerPoints 
  

Using commands with '!' is old and not used anymore.

Use the inbuilt system for it instead: addCommandHandler.

I also assume you defined loadPlayerData as a function somewhere in your script

Link to comment

people somehow like to flood the chat with old !commands, i dont know why.

you better something like this to be able to use /command via !command:

addEventHandler("onPlayerChat", getRootElement(),  
function(text)  
  if text:sub(1, 1) == "!" then 
    local command = gettok(text, 1, 32)  
    if #command > 1 then  
      cancelEvent() -- if event is not cancelled, command will be executed BEFORE chat output that trigered it 
      outputChatBox(getPlayerName(source)..": "..text, getRootElement(), 255, 255, 255, true) 
      -- comment/delete ^previous^ line to hide command input 
      executeCommandHandler(command:gsub("!", ""), source, text:gsub(command, ""))  
    end 
  end 
end) 

basically when player type !something in chat, /something command will be executed, including all arguments.

that is, of course, if you already created it with addCommandHandler().

and your resource must have access to executeCommandHandler() function.

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