English Ammoin/Ammo

22 replies
Goto Page
To the start Previous 1 2 Next To the start
17.08.15 08:45:30 pm
Up
Mora_rus
User
Offline Off
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:http://i.imgur.com/jEkWodG.png

Thank you
17.08.15 08:47:26 pm
Up
Seekay
Reviewer
Offline Off
Afaik, you can't. Maybe via lua but I don't know nothing bout that.
Wash your hands! :­)
17.08.15 08:48:34 pm
Up
Talented Doge
User
Offline Off
cs2d cmd setammo can do this. The only problem is to obtain the dropped item id.
Talented Doge
17.08.15 08:51:41 pm
Up
Mora_rus
User
Offline Off
@user Seekay: thanks, ok yu ppro ok
@user Talented Doge: maybe there is a way to change it by trigger_if?
17.08.15 08:55:37 pm
Up
Talented Doge
User
Offline Off
I don't actually know, I haven't even tried to use cs2d cmd setammo alongside with dropped weapon.
Talented Doge
17.08.15 08:58:22 pm
Up
Mora_rus
User
Offline Off
@user Talented Doge: oh, okay, it's shit mi aer scared .
Maybe someone know. Let's wait for replies.
18.08.15 06:00:52 am
Up
_oops
User
Offline Off
18.08.15 06:33:52 am
Up
Apache uwu
User
Offline Off
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:
Code:
(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:http://i.stack.imgur.com/JLlH5.gif


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

Code:
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)()
18.08.15 07:21:22 am
Up
Mora_rus
User
Offline Off
@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?
18.08.15 07:34:34 am
Up
Apache uwu
User
Offline Off
It runs the function instead of comparing it to true/false.

If I wrote:

Code:
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:

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


I would need to add () to actually run the function.
18.08.15 07:52:32 am
Up
Mora_rus
User
Offline Off
@user Apache uwu: o-oh, i understand now, thank you for explain this
18.08.15 07:54:56 am
Up
_oops
User
Offline Off
You can simply compare same numbers to run scripts

1 is equal as 1. This will return true and will run command.
Code:
1
(1==1) msg("Hello world!")
18.08.15 07:59:33 am
Up
Mora_rus
User
Offline Off
@user _oops: Thank you too, m8
18.08.15 10:27:17 am
Up
VADemon
User
Offline Off
What if there're multiple M4A1's on the ground? Will the command cs2d cmd setammo apply to all of them?
18.08.15 11:22:10 am
Up
Mora_rus
User
Offline Off
@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.
18.08.15 01:14:10 pm
Up
VADemon
User
Offline Off
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
Code:
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
18.08.15 01:41:43 pm
Up
Alistaire
User
Offline Off
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:

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


to

Code:
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.
IMG:http://i.imgur.com/5zhwOTP.png
18.08.15 05:43:41 pm
Up
Apache uwu
User
Offline Off
@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.
19.08.15 08:14:55 am
Up
Mora_rus
User
Offline Off
Should be better if in cs2d editor will be possible to change the value of ammo, instead of thinking what would be happened if...
19.08.15 03:28:10 pm
Up
Alistaire
User
Offline Off
The methods listed above all work. There's no speculation.
IMG:http://i.imgur.com/5zhwOTP.png
To the start Previous 1 2 Next To the start