Jump to content

[Duda] Chat_Range


depato123

Recommended Posts

Hola, ¿Como puedo hacer que este script tenga como rango maximo de vista 10?

results = { 
"lo logra.", 
"no lo logra." 
} 
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], root, 0, 255, 95, true ) 
    else  
        outputChatBox ( "Syntax /intentar 'texto'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

Se que hay que usar rangechat o algo asi, pero no se como se usa

PD: Intente hacerlo así pero no me manda el texto ahora

chat_range=10 
  
results = { 
"lo logra.", 
"no lo logra." 
} 
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
            outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], root, 0, 255, 95, true ) 
        end 
    else  
        outputChatBox ( "Syntax /intentar [texto IC]'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

Ahora intente de nuevo pero no funciona

chat_range=100 
  
results = { 
"lo logra.", 
"no lo logra." 
} 
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], root, 0, 255, 95, true ) 
            end 
        end 
    else  
        outputChatBox ( "Syntax /intentar [texto IC]'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

ERROR: chat/chat.lua:259: attempt to call global 'isPlayerInRangeOfPoint' (a nil value)

Link to comment
Donde esta definida la funcion "isPlayerInRangeOfPoint"?
habia olvidado eso, ya lo agregue y me quedo así el script
chat_range=100 
  
results = { 
"lo logra.", 
"no lo logra." 
} 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        for _,v in ipairs(getElementsByType("player")) do 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], root, 0, 255, 95, true ) 
            end 
        end 
    else 
        outputChatBox ( "Syntax /intentar [texto IC]'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

pero sale este error y no funciona el comando

ERROR: chat/chat.lua:258: attempt to perform arithmetic on local 'x' (a nil value)

Link to comment
chat_range=100 
  
results = { 
"lo logra.", 
"no lo logra." 
} 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        for _,v in ipairs(getElementsByType("player")) do 
            local px, py, pz = getElementPosition( source ) 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], root, 0, 255, 95, true ) 
            end 
        end 
    else 
        outputChatBox ( "Syntax /intentar [texto IC]'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

Intenta eso.

Link to comment
ahora se repite muchas veces, por ejemplo si hay 4 conectados se repite 4 veces...
chat_range=100 
  
results = { 
"lo logra.", 
"no lo logra." 
} 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
  
function publicIntentar ( source, cmd, ... ) 
    if ... then 
        local message = table.concat ( { ... }, " " ) 
        for _,v in ipairs(getElementsByType("player")) do 
            local px, py, pz = getElementPosition( source ) 
            if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
                outputChatBox ( getPlayerName(source).." intenta "..message.." y "..results[math.random( 1, #results )], v, 0, 255, 95, true ) 
            end 
        end 
    else 
        outputChatBox ( "Syntax /intentar [texto IC]'", source, 15, 255, 0, false ) 
    end 
end 
addCommandHandler ( "intentar", publicIntentar ) 

Link to comment
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...