Modme Forums

Removing objects when a player activates a button…

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: XxRaPiDK3LLERxX

Hey, everyone!

I want to add a button in my map (Which I did) which removes object when it's activated by the player. The whole point of this is because my map tbh isn't really optimised due to so many duplicates of grass which I managed to lower down.

But then I noticed that trees are eating some chunk of FPS and judging from other people's video of the map, they getting terrible performance.

Thanks!


ModmeBot:

Reply By: Abnormal202

In script:

in your main function, paste this:

//Delete Models
level thread model_delete();



Then at the bottom of the yourmapname.GSC paste this:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" )
	trig waittill( "trigger", player);
	trig Delete();
	models Delete();
}



I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.


ModmeBot:

Reply By: XxRaPiDK3LLERxX

Abnormal202

In script:

in your main function, paste this:

//Delete Models
level thread model_delete();



Then at the bottom of the yourmapname.GSC paste this:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" )
	trig waittill( "trigger", player);
	trig Delete();
	models Delete();
}



I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!


ModmeBot:

Reply By: Dan9977

XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Models
level thread model_delete();



Then at the bottom of the yourmapname.GSC paste this:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" )
	trig waittill( "trigger", player);
	trig Delete();
	models Delete();
}



I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line


ModmeBot:

Reply By: XxRaPiDK3LLERxX

Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.


ModmeBot:

Reply By: natesmithzombies

XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}


ModmeBot:

Reply By: Abnormal202

natesmithzombies
XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}

I should have known I couldn't delete an array like that! I forgot that foreach existed.


ModmeBot:

Reply By: natesmithzombies

Abnormal202
natesmithzombies
XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}

I should have known I couldn't delete an array like that! I forgot that foreach existed.

alternatively you can use a normal for loop. foreach can not always replace a normal for, but it is rare that you would need to use a normal for. Nice work though!


ModmeBot:

Reply By: XxRaPiDK3LLERxX

natesmithzombies
Abnormal202
natesmithzombies
XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}

I should have known I couldn't delete an array like that! I forgot that foreach existed.

alternatively you can use a normal for loop. foreach can not always replace a normal for, but it is rare that you would need to use a normal for. Nice work though!

Thanks a lot both of you! It worked magnificently! But now the clips are there.

Gave you both a *win*


ModmeBot:

Reply By: Abnormal202

XxRaPiDK3LLERxX
natesmithzombies
Abnormal202
natesmithzombies
XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}

I should have known I couldn't delete an array like that! I forgot that foreach existed.

alternatively you can use a normal for loop. foreach can not always replace a normal for, but it is rare that you would need to use a normal for. Nice work though!

Thanks a lot both of you! It worked magnificently! But now the clips are there.

Gave you both a *win*

Oh just make the clips script_brushmodels and give them the KVP: Targetname: delete_model as well.


ModmeBot:

Reply By: XxRaPiDK3LLERxX

Abnormal202
XxRaPiDK3LLERxX
natesmithzombies
Abnormal202
natesmithzombies
XxRaPiDK3LLERxX
Dan9977
XxRaPiDK3LLERxX
Abnormal202

In script:

in your main function, paste this:

//Delete Modelslevel thread model_delete();

Then at the bottom of the yourmapname.GSC paste this:

function delete_models(){ models = GetEntArray( "delete_model", "targetname"); trig = GetEnt( "button", "targetname"); trig SetHintString( "Press and Hold [use] to delete models (helps FPS)" ) trig waittill( "trigger", player); trig Delete(); models Delete();}

I personally have barely had any experience with arrays, and I haven't tested this script, so if this doesn't work, tell me.

Now in radiant:

1. select all the models you want to delete and make them script_models.

2. Give all the models the KVP: Targetname: delete_model

3. select or create a trigger_use over the "button" and give it the KVP: Targetname: button

4. Compile and link your map.

also feel free to change the hintstring in the second part of the script.

Thanks for the script and the instructions! This error appear which I have no clue how to solve :|

^1 trig waittill

^1-------------^

^1ERR(0) scripts/zm/zm_lostforest.gsc (433,14) in "delete_models()" : syntax error, unexpected TOKEN_WAITTILL, expecting TOKEN_LEFT_PAREN : trig waittill

Thanks again!

put a ; at the end of the SetHintString line

Thanks for your reply, unfortunately this comes up:

**** 1 script error(s):

"model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" at line 77 ****

**** Unresolved external "model_delete" with 0 parameters in "scripts/zm/zm_115_experiment_factory.gsc" ****

So I had to replace level thread model_delete(); with level thread delete_models();

So I tried this in-game, however, the hint string does not appear, and when you actually press the button to activate it, it does nothing.

Edit:

Now the hintstring works but when I use it, the tree does not get deleted.

That is because he treated an array of entities like an entity. This is how I would modify his code for a better result:

function delete_models()
{
	models = GetEntArray( "delete_model", "targetname");
	trig = GetEnt( "button", "targetname");
	trig SetHintString( "Press and Hold ^3&&1^7 to delete models (helps FPS)" ); 
	trig waittill( "trigger", player);
	trig Delete();
	foreach( model in models )
		model Delete();
}

I should have known I couldn't delete an array like that! I forgot that foreach existed.

alternatively you can use a normal for loop. foreach can not always replace a normal for, but it is rare that you would need to use a normal for. Nice work though!

Thanks a lot both of you! It worked magnificently! But now the clips are there.

Gave you both a *win*

Oh just make the clips script_brushmodels and give them the KVP: Targetname: delete_model as well.

Thanks for answering me issue, I can confirm this is now solved :)

Thanks again both of you, when my map gets public, I'll make sure you both get credited!