depato123 Posted November 26, 2013 Posted November 26, 2013 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)
Castillo Posted November 26, 2013 Posted November 26, 2013 Donde esta definida la funcion "isPlayerInRangeOfPoint"?
depato123 Posted November 26, 2013 Author Posted November 26, 2013 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)
Alexs Posted November 26, 2013 Posted November 26, 2013 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.
depato123 Posted November 26, 2013 Author Posted November 26, 2013 ahora se repite muchas veces, por ejemplo si hay 4 conectados se repite 4 veces...
Alexs Posted November 27, 2013 Posted November 27, 2013 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 )
Recommended Posts