Jump to content

[HELP] Excute command


Mature

Recommended Posts

Hi, I'm creating a dx chat script, but I have a problem that I don't understand why it's happening. Basically, I want the player to be able to give basic commands in the chat, I already searched the forum and found but I don't understand why my script is not working and it is exactly the same.
Can someone help me?

Topic: https://forum.multitheftauto.com/topic/70958-execute-commands/

Client:
 

triggerServerEvent("RZK:Chat", resourceRoot, localPlayer, sett, guiGetText(boxText))

Server
 

addEvent("RZK:Chat", true)
addEventHandler("RZK:Chat", resourceRoot, 
function (thePlayer, set, ...)
     if set and {...} then
     local tableM = {...}
     local first = tableM[1] 
	 table.remove(tableM, 1)
	     if string.sub(first,1,1) == "/" then 
		 local command = string.sub(first, 2, string.len(first)) 
         local arguments = table.concat(tableM, " ") 
	    	 executeCommandHandler( command, thePlayer, arguments ) 
			 print(command..' A '..arguments)
		 else
	         if set == "local" then
		         local x,y,z = getElementPosition(thePlayer)
                 local players = getElementsWithinRange(x, y, z, 50, "player")
	             for i,player in ipairs(players) do
		        	 triggerClientEvent(player, "chat:box", root, thePlayer, set, first)
		         end
	         else
	              triggerClientEvent(root, "chat:box", root, thePlayer, set, first)
			 end
	     end
	 end
end)

 

Link to comment
  • Scripting Moderators
1 hour ago, Hazardinho said:

Hi, I'm creating a dx chat script, but I have a problem that I don't understand why it's happening. Basically, I want the player to be able to give basic commands in the chat, I already searched the forum and found but I don't understand why my script is not working and it is exactly the same.
Can someone help me?

Topic: https://forum.multitheftauto.com/topic/70958-execute-commands/

Client:
 


triggerServerEvent("RZK:Chat", resourceRoot, localPlayer, sett, guiGetText(boxText))

Server
 


addEvent("RZK:Chat", true)
addEventHandler("RZK:Chat", resourceRoot, 
function (thePlayer, set, ...)
     if set and {...} then
     local tableM = {...}
     local first = tableM[1] 
	 table.remove(tableM, 1)
	     if string.sub(first,1,1) == "/" then 
		 local command = string.sub(first, 2, string.len(first)) 
         local arguments = table.concat(tableM, " ") 
	    	 executeCommandHandler( command, thePlayer, arguments ) 
			 print(command..' A '..arguments)
		 else
	         if set == "local" then
		         local x,y,z = getElementPosition(thePlayer)
                 local players = getElementsWithinRange(x, y, z, 50, "player")
	             for i,player in ipairs(players) do
		        	 triggerClientEvent(player, "chat:box", root, thePlayer, set, first)
		         end
	         else
	              triggerClientEvent(root, "chat:box", root, thePlayer, set, first)
			 end
	     end
	 end
end)

 

Maybe because of:

Serverside commands can only be executed by the server. The same applies to the client side

This is how you kill your server network.

local players = getElementsWithinRange(x, y, z, 50, "player")

for i,player in ipairs(players) do
	triggerClientEvent(player, "chat:box", root, thePlayer, set, first)
end

 

You trigger this event separately per player. Very bad solution. You know you can use table of players instead as first argument? Which is players in your case.

Also using ipairs is bad, since this is worst type of loop.

I'm kinda repeating myself - https://forum.multitheftauto.com/topic/121808-doubts-if-you-can-improve-performance/

  • Like 1
Link to comment
8 hours ago, majqq said:

Talvez por causa de:



É assim que você mata sua rede de servidores.


  

   
	  

 

Você aciona esse evento separadamente por jogador. Solução muito ruim. Você sabe que pode usar a mesa de jogadores como primeiro argumento? Quais são os jogadores no seu caso.

O uso de ipairs também é ruim, pois esse é o pior tipo de loop.

Estou meio que me repetindo -  https://forum.multitheftauto.com/topic/121808-doubts-if-you-can-improve-performance/

I will solve the loop problem, thanks for remembering, but I was wondering, is there any way to create a function that can execute chat commands? being dx or just using F8? if so, can you give me a code example?

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