Jump to content

Variavel


Recommended Posts

11 hours ago, DNL291 said:

Tem o isElement ali acima, se você mudar pra uma boolean vai precisar revisar essa linha. Remova também o "local thePlayer = getPlayerFromPartialName (playerName )" do código já que esse não será usado.

Tente:


function comprarv (source, cmd)	if venda[source] then		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source )	else		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source )			venda[source] = true			takePlayerMoney( source, 1000 )		else			outputChatBox( "["..Comando_Revistar2.."] Dinheiro insuficiente!", source, 230, 30, 30 )		end	endendaddCommandHandler ( Comando_Revistar2, comprarv )

 

bom oque tenho que colocar no inicio 

venda[source] = false

e deu erro no debuscript 3 dai coloquei 

venda = false

saiu o erro soque dai deu outro erro no 

if venda[source] then

 

Link to comment
  • Moderators
5 hours ago, zThyPvpTK said:

e deu erro no debuscript 3 dai coloquei 


venda = false

Isso é uma variável, mas deve ser uma tabela, então é lógico que não vai funcionar.

O que deve ser feito é o outro comando, após utilizar o comando, você remove o valor de venda[ thePlayer ]

Link to comment
45 minutes ago, DNL291 said:

Isso é uma variável, mas deve ser uma tabela, então é lógico que não vai funcionar.

O que deve ser feito é o outro comando, após utilizar o comando, você remove o valor de venda[ thePlayer ]

coloquei isso no começo para começar como false

  • n precisa colocar aquilo no começo ?
Link to comment
  • Moderators

Seguindo a lógica do seu código, você deve colocar venda[source] = nil no comando de usar a venda.

Exemplo:

function cmdvendar ( source, cmd )
	if not venda[source] then
		return outputChatBox( "Você não possui venda!", source )
	end

	outputChatBox ( "Você Foi Vendado", source )
	venda[source] = nil
end
addCommandHandler ( "vendar", cmdvendar )

 

Link to comment
Just now, DNL291 said:

Seguindo a lógica do seu código, você deve colocar venda[source] = nil no comando de usar a venda.

Exemplo:


function cmdvendar ( source, cmd )
	if not venda[source] then
		return outputChatBox( "Você não possui venda!", source )
	end

	outputChatBox ( "Você Foi Vendado", source )
	venda[source] = nil
end
addCommandHandler ( "vendar", cmdvendar )

 

venda[source] = nil

e true ? e tenho que tirar o venda = false do começo ?

Link to comment
16 hours ago, DNL291 said:

No topo do script só é criada a table.


local venda = {}

O jogador comprou venda?


venda[source] = true

quando usar:


venda[source] = nil

--

Mostre o seu código completo.

ve agr se ta certo tudo 



--------------------------------------------------------------------------------------------
local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height)
Comando_Revistar = "vendar"
Comando_Revistar2 = "comprar"
local venda = {}

function getPlayerFromPartialName ( name )
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function comprarv (source, cmd)
	if venda[source] then
		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source )
	else
		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra
			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source )
			venda[source] = true
			takePlayerMoney( source, 1000 )
		else
			outputChatBox( "["..Comando_Revistar2.."] Dinheiro insuficiente!", source, 230, 30, 30 )
		end
	end
end
addCommandHandler ( Comando_Revistar2, comprarv )

function Revistar ( source, cmd, player )
    if venda[source] then
		if not player then
			return outputChatBox( "Sintaxe: /"..Comando_Revistar.." <jogador>", source )
		else
	        local Jogador = getPlayerFromPartialName ( player )
	        if Jogador then
			    local cx,cy,cz = getElementPosition(Jogador)
			    local x,y,z = getElementPosition(source)
			    local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)
			    if dist <= 5 then
			    	outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source )
			    	outputChatBox ( "Você Foi Vendado", Jogador )
			    	fadeCamera( Jogador, false, 1 )
				    local playerX, playerY, playerZ = getElementPosition ( localPlayer )       -- Get our player's coordinates.
				    local playerZoneName = getZoneName ( playerX, playerY, playerZ )          -- Get name of the zone the player is in.
				    dxDrawText ( playerZoneName, 44, screenHeight - 41, screenWidth, screenHeight, tocolor ( 0, 0, 0, 255 ), 1.02, "pricedown" )
			    	venda[source] = nil
				else
					outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)
				end
			end
		end
	end
end
addCommandHandler ( Comando_Revistar, Revistar )


 

Edited by zThyPvpTK
Link to comment
  • Moderators

A tabela venda + verificação tá certo, mas essas funções você vai ter que fazer no lado cliente:

guiGetScreenSize

dxDrawText

E chame o evento cliente com triggerClientEvent

E no comando vendar você vai precisar verificar se o jogador alvo é diferente do que usou o comando.

Link to comment
1 hour ago, DNL291 said:

A tabela venda + verificação tá certo, mas essas funções você vai ter que fazer no lado cliente:

guiGetScreenSize

dxDrawText

E chame o evento cliente com triggerClientEvent

E no comando vendar você vai precisar verificar se o jogador alvo é diferente do que usou o comando.

testei sem o dram  txt e o outro so pra dar uma msg e deu erro no debugscript 3 falando que 

local venda = {}

ta faltando " "

Link to comment
11 minutes ago, DNL291 said:

Manda aqui seu código atualizado, você disse que removeu as funções, depois disso deve ter aparecido o bug.


--------------------------------------------------------------------------------------------
local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height)
Comando_Revistar = "vendar"
Comando_Revistar2 = "comprar"
local venda = "{}"

function quitPlayer ( quitType )
	-- send the message to the server telling players that the player has left.
	outputChatBox ( getPlayerName(source).. " has left the server (" .. quitType .. ")" )
	entrar[source] = true
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

function getPlayerFromPartialName ( name )
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

function comprarv (source, cmd)
	if venda[source] then
		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source )
	else
		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra
			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source )
			venda[source] = true
			takePlayerMoney( source, 1000 )
		else
			outputChatBox( "["..Comando_Revistar2.."] Dinheiro insuficiente!", source, 230, 30, 30 )
		end
	end
end
addCommandHandler ( Comando_Revistar2, comprarv )

function Revistar ( source, cmd, player )
    if venda[source] then
		if not player then
			return outputChatBox( "Sintaxe: /"..Comando_Revistar.." <jogador>", source )
		else
	        local Jogador = getPlayerFromPartialName ( player )
	        if Jogador then
			    local cx,cy,cz = getElementPosition(Jogador)
			    local x,y,z = getElementPosition(source)
			    local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)
			    if dist <= 5 then
			    	outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source )
			    	outputChatBox ( "Você Foi Vendado", Jogador )
			    	venda[source] = nil
				else
					outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)
				end
			end
		end
	end
end
addCommandHandler ( Comando_Revistar, Revistar )


 

coloquei os "" pra ver se ia e deu erro 

Link to comment
  • Moderators

É por causa desta linha:

local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height)

Remova ela, como eu disse; o erro não foi com a tabela e a sua modificação foi totalmente errada.

4 hours ago, DNL291 said:

guiGetScreenSize

dxDrawText

Elas vão em outro arquivo de script que será o client.

E também a linha 11, onde está:

entrar[source] = true

Vai ocorrer erro, remova isso. E "onPlayerQuit" você deve fazer assim na verdade:

function quitPlayer( )
	if venda[source] then
		venda[source] = nil
	end
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

 

Link to comment
21 minutes ago, DNL291 said:

É por causa desta linha:


local screenWidth, screenHeight = guiGetScreenSize ( ) -- Get the screen resolution (width and height)

Remova ela, como eu disse; o erro não foi com a tabela e a sua modificação foi totalmente errada.

Elas vão em outro arquivo de script que será o client.

E também a linha 11, onde está:


entrar[source] = true

Vai ocorrer erro, remova isso. E "onPlayerQuit" você deve fazer assim na verdade:


function quitPlayer( )
	if venda[source] then
		venda[source] = nil
	end
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

 

remover o local screenWidth, screenHeight = guiGetScreenSize ( )  o quit player e outra coisa que vo fazer e outra variavel 

25 minutes ago, Lord Henry said:

Essa sua linha 6 não faz sentido.

Você só está chutando código sem entender o que está fazendo.

sim realmente como deu erro e não queria mais incomodar vcs tentei colocar "" pra ver se ia 

Link to comment
  • Moderators
5 minutes ago, zThyPvpTK said:

remover o local screenWidth, screenHeight = guiGetScreenSize ( )  o quit player e outra coisa que vo fazer e outra variavel 

sim realmente como deu erro e não queria mais incomodar vcs tentei colocar "" pra ver se ia 

Resumindo, tente este:


--------------------------------------------------------------------------------------------
Comando_Revistar = "vendar"
Comando_Revistar2 = "comprar"

local venda = {}

function quitPlayer( )
	if venda[source] then
		venda[source] = nil
	end
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

function comprarv (source, cmd)
	if venda[source] then
		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source, 230, 30, 30 )
	else
		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra
			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source, 0, 230, 0 )
			venda[source] = true
			takePlayerMoney( source, 1000 )
		else
			outputChatBox( "["..Comando_Revistar2.."] Dinheiro insuficiente!", source, 230, 30, 30 )
		end
	end
end
addCommandHandler ( Comando_Revistar2, comprarv )

function Revistar ( source, cmd, player )
	if venda[source] then
		if not player then
			return outputChatBox( "Sintaxe: /"..Comando_Revistar.." <jogador>", source )
		end
		local Jogador = getPlayerFromPartialName ( player )
		if isElement(Jogador) then
			local cx,cy,cz = getElementPosition(Jogador)
			local x,y,z = getElementPosition(source)
			local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)
			if dist <= 5 then
				outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source )
				outputChatBox ( "Você Foi Vendado", Jogador )
				venda[source] = nil
			else
				outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)
			end
		end
	end
end
addCommandHandler ( Comando_Revistar, Revistar )

function getPlayerFromPartialName ( name )
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

Se funcionar você parte para a outra etapa, do trigger.

Link to comment
39 minutes ago, DNL291 said:

Resumindo, tente este:


--------------------------------------------------------------------------------------------Comando_Revistar = "vendar"Comando_Revistar2 = "comprar"local venda = {}function quitPlayer( )	if venda[source] then		venda[source] = nil	endendaddEventHandler ( "onPlayerQuit", root, quitPlayer )function comprarv (source, cmd)	if venda[source] then		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source, 230, 30, 30 )	else		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source, 0, 230, 0 )			venda[source] = true			takePlayerMoney( source, 1000 )		else			outputChatBox( "["..Comando_Revistar2.."] Dinheiro insuficiente!", source, 230, 30, 30 )		end	endendaddCommandHandler ( Comando_Revistar2, comprarv )function Revistar ( source, cmd, player )	if venda[source] then		if not player then			return outputChatBox( "Sintaxe: /"..Comando_Revistar.." <jogador>", source )		end		local Jogador = getPlayerFromPartialName ( player )		if isElement(Jogador) then			local cx,cy,cz = getElementPosition(Jogador)			local x,y,z = getElementPosition(source)			local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)			if dist <= 5 then				outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source )				outputChatBox ( "Você Foi Vendado", Jogador )				venda[source] = nil			else				outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)			end		end	endendaddCommandHandler ( Comando_Revistar, Revistar )function getPlayerFromPartialName ( name )    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil    if name then        for _, player in ipairs(getElementsByType("player")) do            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()            if name_:find(name, 1, true) then                return player            end        end    endend

Se funcionar você parte para a outra etapa, do trigger.

tentei aqui e deu erro dai tentei arrumar e deu mais erro bom no caso deu erro quando dei /comprar http://prntscr.com/oepeej

Link to comment
  • Moderators

O código tá certo, testei aqui e funcionou. Pode ser que você colocou no lado cliente ou esse erro é com outro código.

Aqui está meu código testado:


--------------------------------------------------------------------------------------------
Comando_Revistar = "vendar"
Comando_Revistar2 = "comprar"

local venda = {}

function quitPlayer( )
	if venda[source] then
		venda[source] = nil
	end
end
addEventHandler ( "onPlayerQuit", root, quitPlayer )

function comprarv (source, cmd)
	if venda[source] then
		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source, 230, 30, 30 )
	else
		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra
			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source, 0, 230, 0 )
			venda[source] = true
			takePlayerMoney( source, 1000 )
		else
			outputChatBox( "["..cmd.."] Dinheiro insuficiente!", source, 230, 30, 30 )
		end
	end
end
addCommandHandler ( Comando_Revistar2, comprarv )

function cmdvendar ( source, cmd, player )
	if venda[source] then
		if not player then
			return outputChatBox( "Sintaxe: /"..cmd.." <jogador>", source,230, 30, 30 )
		end
		local Jogador = getPlayerFromPartialName ( player )
		if isElement(Jogador) then
			local cx,cy,cz = getElementPosition(Jogador)
			local x,y,z = getElementPosition(source)
			local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)
			if dist <= 5 then
				outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source, 0, 230, 0 )
				outputChatBox ( "Você Foi Vendado", Jogador, 230, 230, 230 )
				fadeCamera( Jogador, false, 1 )
				venda[source] = nil
			else
				outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)
			end
		else
			outputChatBox( "["..cmd.."] Jogador não encontrado!", source, 230, 30, 30 )
		end
	else
		outputChatBox( "["..cmd.."] Você não possui venda!", source, 230, 30, 30 )
	end
end
addCommandHandler ( Comando_Revistar, cmdvendar )

function getPlayerFromPartialName ( name )
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil
    if name then
        for _, player in ipairs(getElementsByType("player")) do
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()
            if name_:find(name, 1, true) then
                return player
            end
        end
    end
end

 

Link to comment
13 hours ago, DNL291 said:

O código tá certo, testei aqui e funcionou. Pode ser que você colocou no lado cliente ou esse erro é com outro código.

Aqui está meu código testado:


--------------------------------------------------------------------------------------------Comando_Revistar = "vendar"Comando_Revistar2 = "comprar"local venda = {}function quitPlayer( )	if venda[source] then		venda[source] = nil	endendaddEventHandler ( "onPlayerQuit", root, quitPlayer )function comprarv (source, cmd)	if venda[source] then		outputChatBox ( "* Erro: So Pode Comprar Uma Venda!", source, 230, 30, 30 )	else		if getPlayerMoney(source) >= 1000 then -- verifique o dinheiro já que se trata de uma compra			outputChatBox ( "* Venda Comprada /vendar [Jogador]", source, 0, 230, 0 )			venda[source] = true			takePlayerMoney( source, 1000 )		else			outputChatBox( "["..cmd.."] Dinheiro insuficiente!", source, 230, 30, 30 )		end	endendaddCommandHandler ( Comando_Revistar2, comprarv )function cmdvendar ( source, cmd, player )	if venda[source] then		if not player then			return outputChatBox( "Sintaxe: /"..cmd.." <jogador>", source,230, 30, 30 )		end		local Jogador = getPlayerFromPartialName ( player )		if isElement(Jogador) then			local cx,cy,cz = getElementPosition(Jogador)			local x,y,z = getElementPosition(source)			local dist = getDistanceBetweenPoints3D(x,y,z,cx,cy,cz)			if dist <= 5 then				outputChatBox ( "Você Vendou Um Jogador [-1 Venda]", source, 0, 230, 0 )				outputChatBox ( "Você Foi Vendado", Jogador, 230, 230, 230 )				fadeCamera( Jogador, false, 1 )				venda[source] = nil			else				outputChatBox("#bebebeChegue mais perto do jogador!", source, 255, 255, 255, true)			end		else			outputChatBox( "["..cmd.."] Jogador não encontrado!", source, 230, 30, 30 )		end	else		outputChatBox( "["..cmd.."] Você não possui venda!", source, 230, 30, 30 )	endendaddCommandHandler ( Comando_Revistar, cmdvendar )function getPlayerFromPartialName ( name )    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil    if name then        for _, player in ipairs(getElementsByType("player")) do            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower()            if name_:find(name, 1, true) then                return player            end        end    endend

 

no meu client n tem nd vo testar

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