Forum

> > CS2D > Scripts > The "Say" Script
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch The "Say" Script

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt The "Say" Script

Marcell
Super User Off Offline

Zitieren
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?

alt Re: The "Say" Script

Rainoth
Moderator Off Offline

Zitieren
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.
3× editiert, zuletzt 08.01.14 18:06:41

alt Re: The "Say" Script

Marcell
Super User Off Offline

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


ooc would be TheAnonymus: (( message ))

alt Re: The "Say" Script

Rainoth
Moderator Off Offline

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

alt Re: The "Say" Script

Marcell
Super User Off Offline

Zitieren
user Rainoth hat geschrieben
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á

alt Re: The "Say" Script

Marcell
Super User Off Offline

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

alt Re: The "Say" Script

Rainoth
Moderator Off Offline

Zitieren
user Marcell hat geschrieben
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.

alt Re: The "Say" Script

Marcell
Super User Off Offline

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

alt Re: The "Say" Script

Avo
User Off Offline

Zitieren
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

alt Re: The "Say" Script

Rainoth
Moderator Off Offline

Zitieren
user Marcell hat geschrieben
Could you say some example?


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

alt Re: The "Say" Script

Marcell
Super User Off Offline

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

like this?

alt Re: The "Say" Script

Rainoth
Moderator Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht