Forum

> > CS2D > Scripts > Strip the second weapon
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Strip the second weapon

13 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Strip the second weapon

Ridho
User Off Offline

Zitieren
hi, I want to know how to strip the 2nd weapon, so the 1st slot still equipped by player because when I buy new weapon, the older weapon is dropped (the 1st slot)

i dont know how to explain it, I hope you understand

Screenshot:
• I want the Scout is dropped when I buy the new weapon instead of Aug
IMG:https://s13.postimg.org/jbei1qsg3/Unknown_v_3_00000.jpg


thanks cookies

alt Re: Strip the second weapon

Kirito2K
User Off Offline

Zitieren
But u can't even get two items in the same slot by buying , i know that u can get 2 items in same slot buy using /equip ..

alt Re: Strip the second weapon

BountyHunter
User Off Offline

Zitieren
I took this from classmod but I don't know exact script for it:
1
2
3
4
5
6
7
if (sample.classes.class[id]==1) then
		msg2(id,"©000255150» Your Choose Zombie. «")
		parse ("setmaxhealth "..id.." 75")
		parse ("setarmor "..id.." 204")
		parse ("speedmod "..id.." 5")
		return "78,86";
	end

The digits
1
return "78,86";
are item's numbers. When in game, these items will equiped for the player.

alt Re: Strip the second weapon

Talented Doge
User Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
weapon ={
[1] = 500;
}

addhook("buy", "_buy")

function _buy(p, w)
	parse("equiip "..p.." "..w)
	--parse("setweapon "..p.." "..w) this is used for setting bought weapon to hand
	local money = player(p, "money") - weapon[w]
	parse("setmoney "..p.." "..money)
end

--[[Write the weapons in [weaponid] = weapon_money form
]]

Not tested and I am too lazy to add all prices for all weapons.

alt Re: Strip the second weapon

Ridho
User Off Offline

Zitieren
user Kirito2K yeah, I used equip in hook buy (to prevent weapon dropping)

user BountyHunter I don't really understand in return, except return 1 and return 0 , I think I need more practice

no user Talented Doge , I can write buy hook clearly, but I just confused in placing the additional codes, for example:
1
2
3
4
if player(id,"weapon")==41 then
	parse("strip "..id.." 41")
	parse("equip "..id.." 41")
end
in
1
2
3
4
5
6
7
8
9
10
...
	if weapon~=player(id,"weapon") then
		parse("equip "..id.." "..weapon)
		parse("setweapon "..id.." "..weapon)
		eqweapon[id]=eqweapon[id]+1
		return 1
	else
		return 0
	end
...
I don't know where should I place it I tried to place the "Shield codes" between
1
2
3
if weapon~=player(id,"weapon") then
		--Here
	parse("equip "..id.." "..weapon)
but it doesn't work

user Joni And Friends I don't really know about cs2d lua cmd playerweapons , could you give me an example? thanks

alt Re: Strip the second weapon

Talented Doge
User Off Offline

Zitieren
1
2
3
4
if weapons[wpn] then
		msg2 (p, "\169255000000Buying this weapon isn't allowed in this server!@C")
		return 1
	end
in which weapons would be like this

1
2
weapons = {
[1] = false;}

True for banned buyings.

alt Re: Strip the second weapon

Bowlinghead
User Off Offline

Zitieren
If you call a function then sometimes it returns values.
1
2
3
4
function GetPlayers()
	return #player(0,"table")
end
local max_players = GetPlayers()
Some Cs2d-Addhook-Functions do have "inbuild" return values for e.g. in cs2d lua hook buy.
These execute special things (for example the player doesnt buy the item).
edited code, user Starkkz
1× editiert, zuletzt 21.05.15 18:53:46

alt Re: Strip the second weapon

Joni And Friends
User Off Offline

Zitieren
Maybe this is what you want...
Here you go >

When you buy new weapon and you have weapon in slot 2 then your weapon in slot 2 will be dropped and your new weapon will be in slot 2 and slot 1 not changed/removed
2× editiert, zuletzt 21.05.15 18:32:08

alt Re: Strip the second weapon

Bowlinghead
User Off Offline

Zitieren
If you want to know the length of an array, just type a "#" before it. In my previous code, I have a variable that only contains 1 number (E.g: 5, which would mean that there are 5 players on the server).

When you use "for"-loops then it means they repeat themself.
1
2
3
for i=1,32 do
	-- this code gets executed 32 times!
end
Think of reading a book. You just read it from the first line to the second line and so on. The computer "reads" it on a similiar way.
In loops however, the computer reads the code and then reads it again and again (how often depends on the numbers (We use a range from 1 to 32 because there are max. 32 players per server). And here is the interesting point:
Everytime the computer starts reading the code again, the "id"-variable counts up (First reading: id=1, second reading: id=2, third reading: id=3, ...).

You need basic knowledge of arrays to understand your third example. I am not quiet sure but I think its just a loop and the variable "id" is every value inside of an array. The loop repeats for every value in an array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
myArray = {5,4,16,7} -- some random data

-- create an own function
function SearchNumber(number)
	for _,i in pairs(myArray) do -- loop for every item in the array
		if (i == number) then -- if the actual item is number
			return i; -- stop the function and return the position/index of that item
		end
	end
	return 0; -- return 0 if the number is not in that array
end

-- call function
position = SearchNumber(4)


print(position)
-- output: 2   <- because this is the position in the array
Untested code. If I am wrong please correct me

alt Re: Strip the second weapon

Ridho
User Off Offline

Zitieren
user Bowlinghead does every code affecting the memory usage?
if that so, to reduce the memory use, is it better to use
1
#player(0,"table")
instead of
1
2
3
for id=1,32 do
if player(id,"exist") then
...
because the second code it reads all player from id 1 to 32?

alt Re: Strip the second weapon

VADemon
User Off Offline

Zitieren
@user Ridho: it's just unnecessary to iterate through all player IDs when there's a ready table (player(0, "table")). In terms of memory, it's negligible, but the CPU usage is greatly reduced by using the native player(0, "table")
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht