Forum

> > CS2D > Maps/Editor > Ammoin/Ammo
Forums overviewCS2D overview Maps/Editor overviewLog in to reply

English Ammoin/Ammo

22 replies
Page
To the start Previous 1 2 Next To the start

old Ammoin/Ammo

Mora
User Off Offline

Quote
Hello us.
I wanna know, how can i spawn the item, when using a trigger or whatever, with ammo 30|0(<-as example) on the map?
for example:
IMG:https://i.imgur.com/jEkWodG.png

Thank you

old Re: Ammoin/Ammo

Seekay
Reviewer Off Offline

Quote
Afaik, you can't. Maybe via lua but I don't know nothing bout that.

old Re: Ammoin/Ammo

Apache uwu
User Off Offline

Quote
This is how I would do it:

> Trigger_Use
• Name:
• Trigger: item,lua

> Env_item
• Name: item
• Trigger:
• Item ID: 32 - M4A1

> Trigger_if
• Name: lua
• Trigger:
• Condition:
(function() for _,id in pairs(item(0,"table")) do if item(id,"x")==11 and item(id,"y")==5 then parse("setammo "..id.." 0 30 0") end end return false end)()


Here's what it looks like in action:

IMG:https://i.stack.imgur.com/JLlH5.gif


The condition is just a lua script that sets the ammo for the weapon on that blue tile.

1
2
3
4
5
6
7
8
9
(function()
    for _, id in pairs(item(0,"table")) do
        if item(id, "x") == 11 and item(id, "y") == 5 then 
            parse("setammo " .. id .. " 0 30 0")
        end
    end

    return false
end)()

old Re: Ammoin/Ammo

Mora
User Off Offline

Quote
@user _oops: i didn't said i wanna drop them or make it for every weapon, i've check it, but it's not a solution! Thank you for trying.
@user Apache uwu: wtf man, thank you very much (nohomo) you are best :d
/ps. what is that "()" for?

old Re: Ammoin/Ammo

Apache uwu
User Off Offline

Quote
It runs the function instead of comparing it to true/false.

If I wrote:

1
2
3
function hello()
    parse("echo hello")
end

Then, I wanted to run hello, I would need to say hello().

In the same fashion, if I wrote:

1
2
3
function()
    parse("setammo "..etc)
end

I would need to add () to actually run the function.

old Re: Ammoin/Ammo

_oops
User Playing CS2D

Quote
You can simply compare same numbers to run scripts

1 is equal as 1. This will return true and will run command.
1
(1==1) msg("Hello world!")

old Re: Ammoin/Ammo

Mora
User Off Offline

Quote
@user VADemon: On the ground.. and in the specific tile is not the same.
You can use startround hook and check for all the item ids, or items on the tile.
..
The code given my @user Apache uwu: is work only for the tile you set, for example x=3 y=10. any other spawned/nonspanwed weapons have default ammo.
/maybe i'm understand your question wrong. sorry me then.

old Re: Ammoin/Ammo

VADemon
User Off Offline

Quote
Well yeah, I actually meant multiple weapons of the same type on a single tile. It turns out I misunderstood the setammo command

cs2d cmd setammo ID parameter takes a dropped item's ID which is unique for any dropped weapon on the map.
We're working with dropped items hence the WEAPON value must be 0

user Apache uwu's code works for all weapons on that specific tile. The weapon type doesn't matter.

If you uncomment line 6, only the first weapon's ammo will be changed
If you add and item(id, "type") == WEAPON_ID to the if-statement, then only weapons with this specific ID will be changed (-> bug-free). In this example it's ID 32 for M4A1
1
2
3
4
5
6
7
8
9
10
11
function ()
	for _, id in pairs(item(0,"table")) do
		if item(id, "x") == TILE_X and item(id, "y") == TILE_Y then 
			parse("setammo " .. id .. " 0 30 0")
			
			--return false	-- Uncomment this line if you want only ONE weapon's ammo on that tile to be changed
		end
	end

	return false
end

old Re: Ammoin/Ammo

Alistaire
User Off Offline

Quote
A problem is that if the player drops an item there it will set the ammo to 30|0 too, and if it's not an M4A1 but rather a P90 the same will happen, so change:

1
if item(id, "x") == TILE_X and item(id, "y") == TILE_Y then

to

1
if item(id, "x") == TILE_X and item(id, "y") == TILE_Y and item(id, "dropped") == false and item(id, "type") == ITEM_TYPE then

with ITEM_TYPE being 32 for the M4A1.

old Re: Ammoin/Ammo

Apache uwu
User Off Offline

Quote
@user Alistaire: You could probably get away with just !item(id, "dropped") and the position of the item.

So any movement of any other item would not be changed in terms of ammo, only the spawned item by the environment.

old Re: Ammoin/Ammo

Mora
User Off Offline

Quote
Should be better if in cs2d editor will be possible to change the value of ammo, instead of thinking what would be happened if...
To the start Previous 1 2 Next To the start
Log in to reply Maps/Editor overviewCS2D overviewForums overview