Jump to content

Chat commands


Tronox

Recommended Posts

Hi, I just started learning LUA. I have some simple chat commands (/pm and so), but what I need to do, so only players, that are in radius of x meters could see what i wrote?

Thanks :wink:

Mmm... You can create a col shape, around the one that typed the message. Check who is in that colshape, and if someone in the coll-shape, you can show the message for that one thats in the collshape. Just a idea... :wink:

Link to comment

Ok, here's the script:

function localChat(sender, cmd, ...  ) 
 
  senderName      = getPlayerName(sender)
  tbl_Message    = {...}
  theMessage = table.concat( tbl_Message, " " )
  local posX, posY, posZ = getElementPosition( sender ) 
  local chatRadius = 10
  local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) 
  local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) 
  destroyElement( chatSphere ) 
     for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
     outputChatBox( senderName.. " says: " ..theMessage, nearbyPlayer, 200, 200, 200 )
end
end
addCommandHandler("b", localChat)

And it says:

SCRIPT ERROR: ...TA San Andreas/server/mods/deathmatch/resources/Roleplay/server/Chat.lua:33: ')' expected near 'theMessage'

[10:44:32] WARNING: Loading script failed: ...TA San Andreas/server/mods/deathmatch/resources/Roleplay/server/Chat.lua:33: ')' expected near 'theMessage'

What's wrong with it?

EDITED : I edited the code, but it's still not working

EDITED: Thanks for your replies, it works :D

Edited by Guest
Link to comment

Or you can make everything with function PlayerToPoint(function from samp), function:

function PlayerToPoint( player, radius, x, y, z )
oldpos = {}
temppos = {}
oldpos[0],oldpos[1],oldpos[2] = getElementPosition( player )
temppos[0] = oldpos[0] - x
temppos[1] = oldpos[1] - y
temppos[2] = oldpos[2] - z
if(((temppos[0] < radius) and (temppos[0] > -radius)) and ((temppos[1] < radius) and (temppos[1] > -radius)) and ((temppos[2] < radius) and (temppos[2] > -radius))) then
return true
end
return false
end

Link to comment
Or you can make everything with function PlayerToPoint(function from samp), function:
function PlayerToPoint( player, radius, x, y, z )
oldpos = {}
temppos = {}
oldpos[0],oldpos[1],oldpos[2] = getElementPosition( player )
temppos[0] = oldpos[0] - x
temppos[1] = oldpos[1] - y
temppos[2] = oldpos[2] - z
if(((temppos[0] < radius) and (temppos[0] > -radius)) and ((temppos[1] < radius) and (temppos[1] > -radius)) and ((temppos[2] < radius) and (temppos[2] > -radius))) then
return true
end
return false
end

You can actually make that much shorter:

function playerToPoint( player, radius, x, y, z )
if isElement( player ) and radius and x and y and z then
return getDistanceBetweenPoints3D( x, y, z, getElementPosition( player ) ) <= radius
end
return false
end

Though this one makes the check area a sphere shape rather than a cuboid.

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