Forum

> > CS2D > Scripts > Mass Removal of Items on Start of Round
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch Mass Removal of Items on Start of Round

6 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt Mass Removal of Items on Start of Round

Mami Tomoe
User Off Offline

Zitieren
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

alt Re: Mass Removal of Items on Start of Round

VADemon
User Off Offline

Zitieren
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.

alt Re: Mass Removal of Items on Start of Round

DC
Admin Off Offline

Zitieren
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
2× editiert, zuletzt 30.10.19 19:28:25

alt Re: Mass Removal of Items on Start of Round

DC
Admin Off Offline

Zitieren
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.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht