Forum

> > CS2D > Scripts > Script request [DROP like csgo]
Forums overviewCS2D overview Scripts overviewLog in to reply

English Script request [DROP like csgo]

9 replies
To the start Previous 1 Next To the start

old Script request [DROP like csgo]

boncuk
User Off Offline

Quote
Hello us , i'm here searching for someone who can do it this script please, the script basically its drop to you friend like the others counter-strike, using "G" instead of "E", i maked this code but dont work because when i maked them i did without knowledges of these functions and hooks, i restarted my lua scripter career with simple lua scripts, nut i want to see working my idea... here is the code
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
function initArray(m)
	local array = {}
	local friendrop = {}
	for i = 1, m do
		array[i]=0
	end
	return array
	friendrop.drop=initArray(32)
end

local rad = math.rad
local cos = math.cos
local sin = math.sin

function GetXYInFrontOfPlayer(PlayerID, Offset)
	local PX, PY, PRot = player(PlayerID, "x"), player(PlayerID, "y"), player(PlayerID, "rot")
	PRot = rad((PRot - 90))
	PX = (PX + (Offset * cos(PRot)))
	PY = (PY + (Offset * sin(PRot)))
	return PX, PY
end

addhook("drop","friendrop.drop")
function friend.drop(id)
	if player(id,drop) then
	for (drop(x,y)==3,3)
	drop y = 3
	drop x= 3
	parse("drop"..gun)
		
end

addhook("use","use.friendrop.use")
function use.friend.drop(key)
	for (player(id,key)=="E") then
	friendrop.serveraction

end

addhook("serveraction","friendrop.serveraction")
function friendrop.serveraction(id)
	friendrop.drop(id)
end

i hope u can help me, thanks

old Re: Script request [DROP like csgo]

Dousea
User Off Offline

Quote
There're so many syntax errors in your code. You MUST first learn the syntax and try to build a simple program, how to create functions then how to return values, etc. I can point you out the errors and fix them yourself, but if you do insist on a fixed code you can ask me right away.

1. First error that you have is that your code's global environment doesn't have
friendrop
which is used mostly. So you need to define it first.
1
friendrop = {}
By using
{}
as the value, you're declaring
friendrop
as table so you can insert variables inside it.

2. On your
initArray
function after you return the array, you're trying to set a value to
friendrop.drop
variable. I'm sure that you can't do that after returning a value so you need to put it somewhere else (in the main body is preferred).

3. Your ifs and fors are messed up pretty bad. For if you need to do it this way
1
if (<condition>) then
while for
1
2
for <i> = <start>, <end>, |<step>| do
for <i>, <j>, ... in <iterator> do

There're plenty of errors in your code that I don't mention so I suggest you to learn Lua first, its basic structure, how to declare a new function, etc. before you start to code here. Just start with basic programs then you can master Lua in no time.

old Re: Script request [DROP like csgo]

Cure Pikachu
User Off Offline

Quote
Drop weapons like in CS:GO? Don't you mean physics-based weapon dropping (which exists in even CS 1.6)?

It's partly impossible by scripting because of cs2d cmd spawnprojectile (this is what you use to make weapons fly like in the 3D CS games), which has these setbacks:
• It makes the RPG, Rocket and Grenade Launcher shoot projectiles instead of the weapon itself
• Weapons spawned through this command will always be fully loaded. While you can use cs2d cmd setammo to set the dropped weapon's ammo, you need to know where and when the weapon will land

old Re: Script request [DROP like csgo]

boncuk
User Off Offline

Quote
@Rainoth Thanks, i searched but didn't found. Now the problem with the script is: i want to have the same munition after drop the weapon like: I shoted 1 time a usp then after drop the ammo need to be 11/100 and not 12/100, because its basically infinite and i don't want that

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
undropable = {50,74}
dropable   = {47,48,49,51,52,53,54,72,73,75,76,89}

addhook("drop","mydrop")
function mydrop("id,idd,type")
	for _, value in pairs(undropable) do
		if value == player(id,"weapon") then
return 0
end
end
	
	for _, v in pairs(dropable) do
		if v == player(id,"weapon") then
return 1
end
end

local x=player(id,"x") 
local y=player(id,"y") 
local rot=player(id,"rot") 
parse("strip "..id.." "..type.."")
parse("spawnprojectile 0 "..type.." "..x.." "..y.." 100 "..rot.."")
return 1
end

I think, that can be done with ain, but i dont know where i need to put
edited 1×, last 07.12.16 04:24:28 am

old Re: Script request [DROP like csgo]

Cure Pikachu
User Off Offline

Quote
@user boncuk: I did mention this, didn't I?
user Cure Pikachu has written
• Weapons spawned through this command will always be fully loaded. While you can use cs2d cmd setammo to set the dropped weapon's ammo, you need to know where and when the weapon will land

Figuring out where the weapon will land is your first challenge, and will require some math trigonometry functions.

old Re: Script request [DROP like csgo]

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
I don't think you can do it... cs2d cmd spawnprojectile takes time to take place on the map, here's an exemple when you throw an item it takes ~500ms to take place, from long distance ~1s. and the problem is that item(0,"table") updates the new item IID only when it takes place on map.. That's why you can't set the ammo on the perfect time.

Try it and see that what I said is true? well I'm not sure..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
addhook("drop","drop")
function drop(id,idd,type)
	if (type ~= 50 and type ~= 74) and itemtype(type,"slot") > 1 then
		local x=player(id,"x") 
		local y=player(id,"y") 
		local rot=player(id,"rot")
		local ain, aon = item(id, "ammoin"), item(id, "ammo")
		parse("strip "..id.." "..type)
		parse("spawnprojectile 0 "..type.." "..x.." "..y.." 100 "..rot)
		local itemlist = item(0,"table")
		parse("setammo "..itemlist[#itemlist].." 0 "..ain.." "..aon)
		return 1
	end
	return 0
end

old Re: Script request [DROP like csgo]

Masea
Super User Off Offline

Quote
cs2d lua hook projectile hook probably being triggered when projectile has dropped into ground. So set the two parameters(one for is ammo, the other one is for ammoin) once when you pressed G button, and use it at projectile hook.
edited 1×, last 08.12.16 06:38:13 pm

old Re: Script request [DROP like csgo]

RIP-HereRestsPlookerbooy
BANNED Off Offline

Quote
Getting "ammo" with cs2d lua cmd player or cs2d lua cmd item is impossible so I added another script to it.. lag increased a little bit cuz I used cs2d lua hook always hook.. Atleast it works. Also, don't mind the little spam on the console it's necessary...
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
addhook("log","_log")
weapon=weapon or {}
function _log(text)
	if string.sub(text,1,20)=="Tpl.weapon: #0, pl: " then
		a,b,c,d,e,f=string.match(text,"Tpl.weapon: #0, pl: (.*), typ: (.*) (.*), a: (.*)|(.*), m: (.*)")
		weapon[tonumber(a)]={
			["weapontype"]=tonumber(b),
			["weaponname"]=string.sub(c,2,-2),
			["ammoin"]=tonumber(d),
			["ammo"]=tonumber(e),
			["weaponmode"]=tonumber(f)
		}
		return 1
	end
end
parse("items")
_player=_player or player
player2=function(id,value)
	value=string.lower(value)
	local rtn=weapon[id][value]
	if rtn~=nil then
		return rtn
	else
		return _player(id,value)
	end
end

pl = {}
addhook("drop","_drop")
function _drop(id,idd,type)
	if itemtype(type,"slot") == 1 or itemtype(type,"slot") == 2 then
		parse("items")
		local t, ain, aon = 0, player2(id, "ammoin"), player2(id, "ammo")
		parse("strip "..id.." "..type)
		parse("spawnprojectile "..id.." "..type.." "..player(id,"x").." "..player(id,"y").." 100 "..player(id,"rot"))
		for _,p in pairs(projectilelist(0,0)) do if id == p.player then t = p.id end end
		local tab = {projectile(t,id,"flydist"),ain,aon}
		if pl[id] ~= nil then table.insert(pl[id], tab) else pl[id] = {tab} end
		return 1
	end
	return 0
end

addhook("always","_always")
function _always()
	local itemlist = item(0,"table")
	for k,v in pairs(pl) do
		for d,n in pairs(pl[k]) do
			pl[k][d][1] = pl[k][d][1] - 4.9999999999999995
			if pl[k][d][1] <= 0 then
				parse("setammo "..itemlist[#itemlist].." 0 "..pl[k][d][2].." "..pl[k][d][3])
				pl[k][d] = nil
			end	
		end
	end
end

old Re: Script request [DROP like csgo]

Salem97
User Off Offline

Quote
user Rainoth has written
file File does not exist (15592)

Comments say there should be more but I can't find it (probably has a bad name).

Emmm
user Rainoth has written
Already made.


Dude u said that its already made and u don't even know what their names is..... oh my godness.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview