Forum

> > CS2D > Scripts > Give Weapon
Forums overviewCS2D overview Scripts overviewLog in to reply

English Give Weapon

10 replies
To the start Previous 1 Next To the start

old Give Weapon

Jhony
User Off Offline

Quote
When say :
1
!set weapon [ID] [WEAPON]

Goes a gun to the ID selected

Example :

!set weapon <ID OF PLAYER> <WEAPON>

!set weapon 1 45
msg2(id,"You Have a new weapon!")

help?

old Re: Give Weapon

Alistaire
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function totable(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

addhook('say', 'giveweapon')

function giveweapon(id, msg)
	local a = totable(msg)
	if a[1] == '!set' then
		if a[2] == weapon then
			parse('equip '..a[3]..' '..a[4])
			msg2(a[3], You've got a new weapon!')
		end
	end
end
edited 2×, last 04.05.12 07:14:27 pm

old Re: Give Weapon

Jhony
User Off Offline

Quote
user Alistaire has written
1
2
3
4
5
6
7
8
9
10
11
addhook('say', 'giveweapon')

function giveweapon(id, msg)
	local a = totable(msg)
	if a[1] == !set then
		if a[2] == weapon then
			parse('equip '..a[3]..' '..a[4])
			msg2(a[3], You've got a new weapon!')
		end
	end
end


LUA ERROR: sys/lua/buil.lua:5: unexpected symbol near '!'

old Re: Give Weapon

Cure Pikachu
User Off Offline

Quote
@user Alistaire: I can easily spot some major errors. Fixed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function totable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

addhook('say','giveweapon')

function giveweapon(id,txt)
	local a = totable(txt)
	if a[1] == "!set" then
		if a[2] == "weapon" then
			parse('equip '..a[3]..' '..a[4])
			msg2(tonumber(a[3]),"You've got a new weapon!")
		end
	end
end
edited 1×, last 04.05.12 07:13:37 pm

old Re: Give Weapon

Alistaire
User Off Offline

Quote
user Cure Pikachu has written
@user Alistaire: I can easily spot some major errors. Fixed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function totable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

addhook('say','giveweapon')

function giveweapon(id, msg)
	local a = totable(msg)
	if a[1] == "!set" then
		if a[2] == "weapon" then
			parse('equip '..a[3]..' '..a[4])
			msg2(tonumber(a[3]),"You've got a new weapon!")
		end
	end
end


You kidding me? I didn't add apastrophes at the a[1] == !set

You added a useless function for something which already exists.

old Re: Give Weapon

EP
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
addhook("say","a")
function a(id,txt)
	if txt:sub(1,1) == "!" then
		if txt:sub(1,4) == "!set" then
			local pl = string.sub(txt,6,7)
			local iid = string.sub(txt,9,10)
			parse("equip "..pl.." "..iid)
		return 1
		end
	end
end

old Re: Give Weapon

Alistaire
User Off Offline

Quote
user EP has written
1
2
3
4
5
6
7
8
9
10
11
addhook("say","a")
function a(id,txt)
	if txt:sub(1,1) == "!" then
		if txt:sub(1,4) == "!set" then
			local pl = string.sub(txt,6,7)
			local iid = string.sub(txt,9,10)
			parse("equip "..pl.." "..iid)
		return 1
		end
	end
end


That doesn't work bro. He wants the function to be !set weapon, not !set.

old Re: Give Weapon

Infinite Rain
Reviewer Off Offline

Quote
user Alistaire has written
user Cure Pikachu has written
@user Alistaire: I can easily spot some major errors. Fixed.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
function totable(t,match)
	local cmd = {}
	if not match then
		match = "[^%s]+"
	else
		match = "[^"..match.."]+"
	end
	for word in string.gmatch(t,match) do
		table.insert(cmd,word)
	end
	return cmd
end

addhook('say','giveweapon')

function giveweapon(id, msg)
	local a = totable(msg)
	if a[1] == "!set" then
		if a[2] == "weapon" then
			parse('equip '..a[3]..' '..a[4])
			msg2(tonumber(a[3]),"You've got a new weapon!")
		end
	end
end


You kidding me? I didn't add apastrophes at the a[1] == !set

You added a useless function for something which already exists.


Yep he added just few useless lines.
Well, theres one more way to do this. But everything already done.

old Re: Give Weapon

MikuAuahDark
User Off Offline

Quote

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("say","_say")
function _say(id,txt)
	if txt:sub(1,11)=="!set weapon" then
		pl = 0
		weaponid = 0
		if txt:sub(14,14)~=" " then
			pl = tonumber(txt:sub(13,14))
			weaponid = tonumber(txt:sub(16))
		else
			pl = tonumber(txt:sub(13,13))
			weaponid = tonumber(txt:sub(15))
		end
		if player(pl,"exists") then
			if itemtype(weaponid,"name")~=nil then
				parse("equip "..pl.." "..weaponid)
				msg2(pl,"You Have a new weapon!@C")
			end
		end
	end
end

old Re: Give Weapon

Alistaire
User Off Offline

Quote
user MikuAuahDark has written

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("say","_say")
function _say(id,txt)
	if txt:sub(1,11)=="!set weapon" then
		pl = 0
		weaponid = 0
		if txt:sub(14,14)~=" " then
			pl = tonumber(txt:sub(13,14))
			weaponid = tonumber(txt:sub(16))
		else
			pl = tonumber(txt:sub(13,13))
			weaponid = tonumber(txt:sub(15))
		end
		if player(pl,"exists") then
			if itemtype(weaponid,"name")~=nil then
				parse("equip "..pl.." "..weaponid)
				msg2(pl,"You Have a new weapon!@C")
			end
		end
	end
end


Well this works, but if you want more functions, the best would be my script. You could add a line like elseif a[2] == 'health' then etc. etc.

old Re: Give Weapon

Ariiel
User Off Offline

Quote
Or use give weapons lua by Daky_Sky that is only for admin

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
adminlist = {12345}

function isadmin(id)
     for _, usgn in ipairs(adminlist) do
          if player(id,"usgn")==usgn then
               return true
          end
     end
     return false
end

function rp_msg2(id,clr,txt)
     if player(id,"exists") then
          msg2(id,"©"..clr..txt)
     end
end

function totable(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

addhook("say","GiveWeapons")
function GiveWeapons(id,txt)
     local p = totable(txt)
     local cmd = tostring(p[1])
     if cmd == "!setwpn" then
          if isadmin(id) then
               local pl = tonumber(p[2])
               local weapon = tonumber(p[3])
               if pl ~= nil and weapon ~= nil then
                    if player(pl,"exists") then
                         parse("equip "..pl.." "..weapon)
                         rp_msg2(pl,"000255000",player(id,"name").." gave you New Weapon!")
                         rp_msg2(id,"000255000","You gave new Weapon ID["..weapon.."] to "..player(pl,"name"))
                    end
               end
          end
          return 1
     end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview