Forum

> > CS2D > Scripts > equip by name
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch equip by name

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt equip by name

KagamineLen
User Off Offline

Zitieren
Hello guys, how can i equip weapon by using its name instead of id

like saying !equip 45
1
parse('equip '..id..' '..wepid)

insted of equip 45, i will say equip laser
then it will automatically turn to 45.

how can i do it?

alt Re: equip by name

Gajos
BANNED Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
--=======================--
--== Gajos PL (108942) ==--
--=======================--

Admins = {108942}

--=======================--

c = string.char(169)
point = {}

point.initArray = function(value)
	local array = {}
	for _ = 1,32 do
		array[_] = value
	end
	return array
end

point.ToTable = function(t,match)
	local cmd = {};
	if not match then match = "[^%s]+" end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

point.bug = function(id,txt)
	msg2(id,c.."200000000Unknown command: "..c.."000255255"..txt)
end

point.noadm = function(id)
	msg2(id,c.."200000000You don't have enough level to do this!")
end

point.noe = function(id)
	msg2(id,c.."200000000This player doesn't exist!")
end

point.isAdmin = function(id)
	for _, i in pairs(Admins) do
		if player(id,"usgn") == i then
			return true
		end
	end
	return false
end

point.isItem = function(txt)
	for _ = 1,100 do
		if txt == itemtype(_,"name") then
			point.item = _
			return true
		end
	end
	return false
end

addhook("say","point.say")
point.say = function(id,txt)
	local p = point.ToTable(txt)
	local cmd = string.lower(p[1])
	if txt:sub(1,1) == "@" and txt ~= "rank" then
		if cmd == "@setpoints" then
			if point.isAdmin then
				local pl = tonumber(p[2])
				local points = tonumber(p[3])
				if pl ~= nil and points ~= nil then
					if player(pl,"exists") then
						killpt[id] = points
					else
						noe(id)
					end
				else
					msg2(id,c.."200000000Correct syntax: @setpoints <id> <points>")
				end
			else
				point.noadm(id)
			end
		elseif cmd == "@givepoints" then
			if point.isAdmin then
				local pl = tonumber(p[2])
				local points = tonumber(p[3])
				if pl ~= nil and points ~= nil then
					if player(pl,"exists") then
						killpt[id] = killpt[id] + points
					else
						noe(id)
					end
				else
					msg2(id,c.."200000000Correct syntax: @givepoints <id> <points>")
				end
			else
				point.noadm(id)
			end
		elseif cmd == "@equip" then
			if point.isAdmin then
				local item = p[2]
				if item ~= nil then
					if point.isItem(item) then
						parse("equip "..id.." "..point.item)
					else
						msg2(id,c.."200000000Error: This item does not exist")
					end
				else
					msg2(id,c.."200000000Correct syntax: @equip <itemname>")
				end
			else
				point.noadm(id)
			end
		else
			point.bug(id,txt)
		end
		return 1
	end
end
1× editiert, zuletzt 07.03.13 15:31:31

alt Re: equip by name

Alistaire
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
addhook('say', 'AA_say')

function splitString(str)
	local c = {}
	for word in string.gmatch(str, '[^%s]+') do
		table.insert(c, word)
	end
	return c
end

function AA_say(id, txt)
	local value = {}
	local cmd, value[1], value[2] = commandHandler(txt)
-- commands
	if cmd == 'equip' then
		parse('equip '..value[2]..' '..value[1])
	elseif cmd == 'spawn' then
		parse('spawnitem '..value[1]..' '..player(value[2], 'tilex')..' '..player(value[2], 'tiley'))
	end
end

function commandHandler(txt)
	function checkName(a, end, start)
		if not start then start = 0 end
		for i = start, end do
			if a == itemtype(i, 'name') then
				return true, i;
			end
		end
		return false, 0;
	end
	local a = splitString(txt)
	if a[1] == '!equip' then
		local bool, id = checkName(a[3], 100)
		if bool then
			return 'equip', id, a[2];
		end
	elseif a[1] == '!spawn' then
		local bool, id = checkName(a[3], 100)
		if bool then
			return 'spawn', id, a[2];
		end
	end
end

Shoulda work
2× editiert, zuletzt 07.03.13 16:03:46

alt Re: equip by name

KagamineLen
User Off Offline

Zitieren
no not check weapon, i mean like this !equip laser
instead of equip 45 because i dont want to memorize all item and weapon id's
2× editiert, zuletzt 07.03.13 17:20:49

alt Re: equip by name

Avo
User Off Offline

Zitieren
Spoiler >

Not shortest, but works. Note : equipping bomb/gas mask/flags/defuser is not supported.

alt Re: equip by name

Alistaire
User Off Offline

Zitieren
user KagamineLen hat geschrieben
no not check weapon, i mean like this !equip laser
instead of equip 45 because i dont want to memorize all item and weapon id's


Works dude.. >


I've playtested it. It works 100% fine.

It also works with caps in the command AND weaponname, and sets the player's weapon to it when using !equip. !spawn spawns the weapon at the player's coords.

alt Re: equip by name

Alistaire
User Off Offline

Zitieren
user KagamineLen hat geschrieben
i cant understand how this script works


Is that something you need to know?

It's best to not understand things at your current level. If you get further into Lua you'll understand most of it. Me posting a pseudocode that prolly doesn't teach you anything at bloody all, which you prolly wouldn't even read till the end, would /not/ help you in any way.

----

For the heck of it, have some pseudocode;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
--Hook say to sayHook

--splitstring: A function that:
	- inputs a string (txt in this case)
	- seperates every part, between spaces ([^%s]+), from it in an array
	- returns the array

--AA_say: A function that:
	- is called when someone says something
	- calls commandHandler (read further on command handler)
	- ..
	- if the message started with !equip or !spawn, do that stuff
	- spawn the returned value[1] (weapon id) in hands of or under the feets of value[2] (player id)

--commandHandler: A function (extension to AA_say) that:
	- splits the player's message in array a[], seperated into;
		+ a[1] (command, !equip or !spawn)
		+ a[2] (playerid, 1 - 32)
		+ a[3] (weapon name, laser or so)
	- if the command in caps is '!EQUIP' or '!SPAWN', run through that function
	- if the player a[2] isn't dead, look what weapon he has to get with checkName, a function that;
		+ cycles through all weapon id's
		+ looks whether that itemtype exists
		+ looks if the item's name matches a[3], the requested item name
		+ returns true if it does and false if it doesn't
		+ if it's true, it also returns the found weapon type
	- if checkName found a name matching the message (bool == true), it will continue, else it will send an error to the console
	- it then returns the command (equip), the weapon id (id), and the player id (a[2])
1× editiert, zuletzt 07.03.13 19:05:33

alt Re: equip by name

KagamineLen
User Off Offline

Zitieren
i understand now, how it works but the rpg launcher doesnt work, how can i make it work? im using totable

alt Re: equip by name

Avo
User Off Offline

Zitieren
Use code I gave you, it works with RPG launcher. You just have to type "!equip rpg launcher".

alt Re: equip by name

KagamineLen
User Off Offline

Zitieren
i see how it works with spaces

1
2
3
4
5
6
7
8
local name = ""
          for i = 2, #t do
               if i ~= 2 then
                    name = name.." "..t[i]
               else
                    name = t[i]
               end
          end

this is it right?

alt Re: equip by name

Alistaire
User Off Offline

Zitieren
Spoiler >


This works tho. It now works with spaces.

alt Re: equip by name

Avo
User Off Offline

Zitieren
You want to understand it? Here you are:

That's part that combine rest of command.

toTable returns all parts of given txt separated by space.

For example:
1
toTable("!equip rpg launcher")
returns
1
{"!equip", "rpg", "launcher"}

After checking if command (index no. 1 of returned by toTable table) is "!equip", onSay function combines rest of text ("rpg" & "launcher") together. At least if index "rpg launcher" exists in table "weaponName", it returns its value ( item ID) and equips player with that item.

alt Re: equip by name

Avo
User Off Offline

Zitieren
Oh, sorry, I don't get part of equiping player with id, just player who says "!equip". If you can, change it. It's not very hard after all explanations and code we both gave you.

In my opinion user Alistaire 's is also most customizable, so use it.

alt Re: equip by name

KagamineLen
User Off Offline

Zitieren
yeah, i used it
this thing makes my script works
1
2
3
4
5
6
7
8
local d = a[3]
                    local e = false
                    if a[4] then
                         for i = 4, #a do
                              d = d..' '..a[i]
                         end
                         e = true
                    end
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht