Forum

> > CS2D > Scripts > Mass Removal of Items on Start of Round
Forums overviewCS2D overview Scripts overviewLog in to reply

English Mass Removal of Items on Start of Round

6 replies
To the start Previous 1 Next To the start

old Mass Removal of Items on Start of Round

Mami Tomoe
User Off Offline

Quote
1
2
3
4
5
6
7
local items = item(0, 'table')
	
	for _, id in pairs(items) do
		if item(id, 'player') == 0 and math_random(1, 2) == 1 then
			exec('removeitem ' .. id)
		end
	end

This crashes my game, I tried using the prespawn hook and some timers but nothing worked, I want to be able to remove random items so every match can feel different.

Thanks

old Re: Mass Removal of Items on Start of Round

VADemon
User Off Offline

Quote
There could be an issue with too much game state updating in a single frame.

Count the items you want to remove and output to console to see if it's a reasonable amount.

The only workaround is to only delete N items each frame until the task is finished.

old Re: Mass Removal of Items on Start of Round

DC
Admin Off Offline

Quote
With how many items does it crash?
What's "exec"? Does it do any extra work?

An alternative solution would be to only spawn the items you want to have so you don't have to delete anything. I understand though that you probably want to place the items in the map editor using cs2d entity env_item.

Edit: Lol ninja'd by user Hajt regarding the exec thing
edited 2×, last 30.10.19 07:28:25 pm

old Re: Mass Removal of Items on Start of Round

DC
Admin Off Offline

Quote
As a follow up to my "spawn only what you need" idea: You could still use cs2d entity env_item entities but always set the spawning behavior to "on trigger only".

Then you could use a Lua script to randomly trigger SOME of those entities on round start or shortly after. You can do so using cs2d cmd triggerposition (and of course use cs2d lua cmd entitylist and optionally cs2d lua cmd entity to get the entities and their data)

Of course this is only a valid solution if your script is meant to be used with a specific custom map only.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview