Forum

> > CS2D > Scripts > The "Say" Script
Forums overviewCS2D overview Scripts overviewLog in to reply

English The "Say" Script

15 replies
To the start Previous 1 Next To the start

old The "Say" Script

Marcell
Super User Off Offline

Quote
Roleplay Script...


Examples:

> [In-Character]
• TheAnonymus says: Where is the nearest shop in this city?
ex: just type in to the chat what you want to say

> [Out-Of-Character]
• TheAnonymus: ((I gotta go to the toilet, minute please!))
ex: !ooc <message>

> [Virtual Action]
• TheAnonymus is trying to scan the documents.
ex: !me <message>
> [Action]
• [player id, who written it:] **Strange Sounds**
ex: [5:] **car engine sound starts**
ex: !do <action>

How can i script it, please someone script the first one, then i can figure out how can i do the same with others?

old Re: The "Say" Script

Rainoth
Moderator Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function string.split(str,pat) -- Splitting strings (sentences) into separate words
    local t = {}
    for word in string.gmatch(str,pat or "[^%s]+") do
        t[#t+1] = word
    end
    return t
end

addhook("say","commands")
function commands(id,t)
local cmd=t:split()--Using the function
local text=t:sub(6)--Text which begins after 5th character
	if cmd[1]=="!ooc" then -- First part of command
		msg(player(id,"name").." says: (("..text.."))")
	else
		msg(player(id,"name").." says: "..t)
	end
end

This will allow you to make commands simply. Split will help you make commands with many arguments, like e.g. "!spawn laser X Y Amount"
whereas text will help you to "catch" what the person says. That's how I do it.
To add more commands use "elseif cmd" and so on. At the end you should do "else" and then do the message thing for "In-Character" so it would be seen as normal talking.
edited 3×, last 08.01.14 06:06:41 pm

old Re: The "Say" Script

Marcell
Super User Off Offline

Quote
No i mean want normal talk should be TheAnonymus says: message


ooc would be TheAnonymus: (( message ))

old Re: The "Say" Script

Rainoth
Moderator Off Offline

Quote
ah well let me edit it to add that.
// I edited it.
Forgot to mention that I didn't test this so you should try running it alone to see if it works and if it doesn't, tell me.

old Re: The "Say" Script

Marcell
Super User Off Offline

Quote
user Rainoth has written
ah well let me edit it to add that.
// I edited it.
Forgot to mention that I didn't test this so you should try running it alone to see if it works and if it doesn't, tell me.


works but possible to hide the real message?

cause i get now two message

1
2
3
4
5
TheAnonymus says: 
TheAnonymus: xd

TheAnonymus says: ((csá))
TheAnonymus: !ooc csá

old Re: The "Say" Script

Marcell
Super User Off Offline

Quote
yeah, its works now, but when i talk normally i must type after 6th char to see it

old Re: The "Say" Script

Rainoth
Moderator Off Offline

Quote
user Marcell has written
yeah, its works now, but when i talk normally i must type after 6th char to see it


Oh right, I forgot to change that heh.
Just do
msg'crap'andso on and on and then where you see "text" you should change it into "t" but not in "ooc".

// I fixed it.

old Re: The "Say" Script

Marcell
Super User Off Offline

Quote
works, just askin's possible to get that, only the closest players able to see what i talk?

old Re: The "Say" Script

Avo
User Off Offline

Quote
Surely.
1
2
3
4
5
6
7
8
9
10
Distance = function(x1, y1, x2, y2)
    return math.floor(math.sqrt(math.pow(x1 - x2, 2) + math.pow(y1 - y2, 2)))
end
msg3 = function(x, y, text, dist)
	for _, id in pairs(player(0, "tableliving")) do
		if Distance(player(id, "x"), player(id, "y"), x, y) <= dist then
			msg2(id, text)
		end
	end
end

old Re: The "Say" Script

Rainoth
Moderator Off Offline

Quote
user Marcell has written
Could you say some example?


Where my message would be, you'll have to replace it kind of.. With his function call.

old Re: The "Say" Script

Marcell
Super User Off Offline

Quote
1
msg3(player(id,"name").." (( "..text.." )) "..x.." "..y.." 5")

like this?

old Re: The "Say" Script

Rainoth
Moderator Off Offline

Quote
1
msg3 = function(x, y, text, dist)

1
msg3(player(id,"x"),player(id,"y),t,300)
Position of person speaking, his spoken words and they'll be heard 300 pixels around the player.
If I understood it correctly that is.
Avo could upgrade it by adding "player(id,"name")" in his msg2 call.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview