Roleplay style chat commands, ported from SA-MP

Started by TheMallard, Feb 14, 2016, 08:23 AM

Previous topic - Next topic

TheMallard

The name of the topic is self-explanatory.
Credits to SA-MP Team for roleplay style chat module.
Credits to Shadow for player loop method

playerIterator <- [];

function onPlayerJoin(player)
{
playerIterator.push(player.ID);
}

function onPlayerPart(player, reason)
{
playerIterator.remove(player.ID);
}

function onPlayerChat(player, text)
{
LocalMessage(player.Pos, 30.0, player.Name + " said: " + text, 255, 255, 255);
return 0;
}

function onPlayerCommand(player, cmd, text)
{
if(cmd == "me")
{
if(!text) return ClientMessage("SYNTAX: /me <action>", player, 255, 255, 255);
return LocalMessage(player.Pos, 30.0, "* " + player.Name + " " + text, 194, 162, 218);
}
if(cmd == "do")
{
if(!text) return ClientMessage("SYNTAX: /do <action>", player, 255, 255, 255);
return LocalMessage(player.Pos, 30.0, "* " + text + " (" + player.Name + ")", 70, 130, 180);
}
if(cmd == "b")
{
if(!text) return ClientMessage("SYNTAX: /b <text>", player, 255, 255, 255);
return LocalMessage(player.Pos, 30.0, "* (( " + player.Name + ": " + text + " ))", 255, 255, 255);
}
return ClientMessage("SERVER: Unknown command.", player, 255, 255, 255);
}

function GetPointDistanceToPoint(x1, y1, z1, x2, y2, z2)
{
return Vector(x1-x2, y1-y2, z1-z2).Length();
}

function LocalMessage(point, distance, message, R, G, B)
{
foreach(playerid, val in playerIterator)
{
if(GetPointDistanceToPoint(FindPlayer(playerid).Pos.x, FindPlayer(playerid).Pos.y, FindPlayer(playerid).Pos.z, point.x, point.y, point.z) < distance)
{
ClientMessage(message, FindPlayer(playerid), R, G, B);
}
}
}

MacTavish

You should have to bring some Demo Screens

Grand Hunting Project
Join #SLC, #KAKAN, #Doom, #GHP @LUnet

Retired VC:MP Player/Scripter :P

KAKAN

Quote from: Kusanagi on Feb 14, 2016, 12:01 PMYou should have to bring some Demo Screens
The script itself says everything. What else do you need? For testing it: You will need atleast 3 player instances.
oh no

Thijn

Screens are not really useful. Just tell us what it does. Just in case some people can't tell from reading the code.

Also, instead of putting 30.0 as a distance everywhere. Why not make that a constant variable?

Cool

Quote from: Thijn on Feb 14, 2016, 06:36 PMScreens are not really useful. Just tell us what it does. Just in case some people can't tell from reading the code.
right i cant understand from code whats in it

TheMallard

I don't speak Noobish and Kakanasslickish.