UGX-Mods Login

or login with an authentication provider below
Sign In with Google
Sign In with Twitter
Sign In with Discord
Sign In with Steam
Sign In with Facebook
Sign In with Twitch

How to make a trigger remove objects when player uses it?

broken avatar :(
Created 7 years ago
by Deleted User
0 Members and 1 Guest are viewing this topic.
3,880 views
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
The whole idea is to have a button on my map so that the player can interact with it and some object would just get removed or deleted from the map. Is there any way to do that?
Thanks!
broken avatar :(
×
broken avatar :(
Location: us?
Date Registered: 21 August 2016
Last active: 2 years ago
Posts
80
Respect
Forum Rank
Rotting Walker
Primary Group
Member
×
All0utWar's Groups
All0utWar's Contact & Social Links
Code Snippet
Plaintext
function objectUse()
{
level.object = GetEnt( "object_name", "targetname" );
level.object_trigger = GetEnt( "object_trigger_name" , "targetname" );
level.object_trigger SetHintString( "Press ^3&&1^7 to do whatever" );

level.object_trigger waittill("trigger", trigger);
level.object_trigger Delete();
level.object Delete();
}

This should work. You can name the variables whatever you want. Just make sure that the targetnames match with Radiant.
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
Code Snippet
Plaintext
function objectUse()
{
level.object = GetEnt( "object_name", "targetname" );
level.object_trigger = GetEnt( "object_trigger_name" , "targetname" );
level.object_trigger SetHintString( "Press ^3&&1^7 to do whatever" );

level.object_trigger waittill("trigger", trigger);
level.object_trigger Delete();
level.object Delete();
}

This should work. You can name the variables whatever you want. Just make sure that the targetnames match with Radiant.
Thanks for your solution but it didn't work. I added a trigger_use on the button, edited trigger_use target name as remove_tree (Since I'm removing tree as a object). I replaced target name of the button as remove_tree_button. I've also renamed targetnames of trees to tree.

On the script side I was confused, I renamed object_name as remove_tree_button, on the second line, I replaced object_trigger_name as remove_tree and that was it. Do I have to edit the targetname of the trigger to match the tree's targetname?
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
Signature
"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
×
buttkicker845's Groups
buttkicker845's Contact & Social Links
this would only work on one trigger and one object.
something like this would work better,

Code Snippet
Plaintext
function initRemoveTrees()
{
level.treesCostMoney = true;
level.defaultTreesCost = 1000;
triggers = GetEntArray("treesTrigs", "targetname");
for(i = 0; i < triggers.size(); i++)
{
triggers[i] thread waitForTrigger();
}
}

//have to make trigger watch function for arrays of triggers
function waitForTrigger()
{
cost = level.defaultTreesCost;
if(isDefined(self.zombie_cost)
{
cost = self.zombie_cost;
}
self waittill("trigger", who);
//to check for cost
if(level.treesCostMoney)
{
if(isPlayer(who) && who.score >= cost)
{
//totally removes tree from world
self delete();
//can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
else
{
if(isPlayer(who))
{
//totally removes tree from world
self delete();
//can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
}
Last Edit: January 09, 2017, 02:52:37 pm by buttkicker845
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
Signature
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
I made a tutorial series that will work for this. In the tutorial it is for shootables, but if you use trigger uses, and add a hintstring and hintcursor, it will work the same.

http://ugx-mods.com/forum/index.php/topic,14471.0.html



As far as the first answer, firstly, get rid of all the "level."'s. There is no need for that. But he set up level.object as the tree, and level.object_trigger as the trigger. You need to add to level.object_trigger the targetname value you used on your trigger use and add to level.object the targetname value you added to the tree.

If you watch the tut, you'll see a more dynamic way of doing this, plus it should help you with multiple trees, using an array instead of just getent.



And buttkicker I think you forgot to delete the tree or object, you deleted the trigger
this would only work on one trigger and one object.
something like this would work better,

Code Snippet
Plaintext
function initRemoveTrees()
{
level.treesCostMoney = true;
level.defaultTreesCost = 1000;
triggers = GetEntArray("treesTrigs", "targetname");
for(i = 0; i < triggers.size(); i++)
{
triggers[i] thread waitForTrigger();
}
}

//have to make trigger watch function for arrays of triggers
function waitForTrigger()
{
cost = level.defaultTreesCost;
if(isDefined(self.zombie_cost)
{
cost = self.zombie_cost;
}
self waittill("trigger", who);
//to check for cost
if(level.treesCostMoney)
{
if(isPlayer(who) && who.score >= cost)
{
//totally removes tree from world
self delete();
//can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
else
{
if(isPlayer(who))
{
//totally removes tree from world
self delete();
//can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
}
Last Edit: January 09, 2017, 02:59:18 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
×
buttkicker845's Groups
buttkicker845's Contact & Social Links

And buttkicker I think you forgot to delete the tree or object, you deleted the trigger

your right about that, i guess thats what happens when you walk away from the computer while writing code that youre not commenting

fixed it here
Code Snippet
Plaintext
function initRemoveTrees()
{
level.treesCostMoney = true;
level.defaultTreesCost = 1000;
triggers = GetEntArray("treesTrigs", "targetname");
for(i = 0; i < triggers.size(); i++)
{
triggers[i] thread waitForTrigger();
}
}

//have to make trigger watch function for arrays of triggers
function waitForTrigger()
{
cost = level.defaultTreesCost;
if(isDefined(self.zombie_cost)
{
cost = self.zombie_cost;
}
self waittill("trigger", who);
//to check for cost
        models = getEntArray(self.target, "targetname");
if(level.treesCostMoney)
{
if(isPlayer(who) && who.score >= cost)
{

//totally removes tree from world
                        for(i = 0; i < models.size(); i++)
                        {
                                models[i] delete();
                         }    
             self delete();
     //can use hide(); instead to just hide the tree and show(); to make it visible again
                 }
}
else
{
if(isPlayer(who))
{
        //totally removes tree from world
                        for(i = 0; i < models.size(); i++)
                        {
                                models[i] delete();
                         }    
             self delete();
     //can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
}
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 14 September 2013
Last active: 4 years ago
Posts
1,895
Respect
Forum Rank
Zombie Destroyer
Primary Group
Community Scripter
My Groups
More
My Contact & Social Links
More
Personal Quote
BE ORIGINAL
×
MakeCents's Groups
Community Mapper Has released one or more maps to the UGX-Mods community which have been added to the UGX Map Manager.
Community Scripter Has shown effort and knowledge in the area of scripting while being a part of the UGX-Mods community.
BO3 Modtools Alpha
BO3 Modtools Alpha
This user has access to the Black Ops 3 Modtools Alpha
your right about that, i guess thats what happens when you walk away from the computer while writing code that youre not commenting

fixed it here
Code Snippet
Plaintext
function initRemoveTrees()
{
level.treesCostMoney = true;
level.defaultTreesCost = 1000;
triggers = GetEntArray("treesTrigs", "targetname");
for(i = 0; i < triggers.size(); i++)
{
triggers[i] thread waitForTrigger();
}
}

//have to make trigger watch function for arrays of triggers
function waitForTrigger()
{
cost = level.defaultTreesCost;
if(isDefined(self.zombie_cost)
{
cost = self.zombie_cost;
}
self waittill("trigger", who);
//to check for cost
        models = getEntArray(self.target, "targetname");
if(level.treesCostMoney)
{
if(isPlayer(who) && who.score >= cost)
{

//totally removes tree from world
                        for(i = 0; i < models.size(); i++)
                        {
                                models[i] delete();
                         }    
             self delete();
     //can use hide(); instead to just hide the tree and show(); to make it visible again
                 }
}
else
{
if(isPlayer(who))
{
        //totally removes tree from world
                        for(i = 0; i < models.size(); i++)
                        {
                                models[i] delete();
                         }    
             self delete();
     //can use hide(); instead to just hide the tree and show(); to make it visible again
}
}
}

Cool, but there is still a slight issue with your code, such as if the player does not have enough points the script will end anyway, and i think a typo on your .size(). And If may make a slight adjustment...

Code Snippet
Plaintext
function initRemoveTrees()
{
level.treesCostMoney = true;
level.defaultTreesCost = 1000;
triggers = GetEntArray("treesTrigs", "targetname");
for(i = 0; i < triggers.size(); i++)
{
triggers[i] thread waitForTrigger();
}
}

//have to make trigger watch function for arrays of triggers
function waitForTrigger()
{
cost = level.defaultTreesCost;
if(isDefined(self.zombie_cost))//edit, missing bracket
{
cost = self.zombie_cost;
}
if(!isdefined(cost))
{
cost = 0;
}
while(isdefined(self))
{
wait(1);//so they can't spam the trigger
self waittill("trigger", who);
//to check for cost
if(isPlayer(who) && who.score >= cost)
{
models = getEntArray(self.target, "targetname");
//totally removes tree from world
foreach(model in models)
{
model delete();
}    
self delete();
//can use hide(); instead to just hide the tree and show(); to make it visible again
return;
}    
}
}
Last Edit: January 09, 2017, 03:24:03 pm by MakeCents
broken avatar :(
×
broken avatar :(
Location: us
Date Registered: 11 March 2014
Last active: 3 years ago
Posts
264
Respect
Forum Rank
Mr. Elemental
Primary Group
Member
×
buttkicker845's Groups
buttkicker845's Contact & Social Links
yeah no problem, im glad you checked it. i havent scripted in cod for way too long and made some very stupid mistakes on that one. Thanks :)
broken avatar :(
  • DeletedUser
  • Deleted Member
×
broken avatar :(
DeletedUser
This user is deleted :(
Thanks for you all for helping, I have got the script in my gsc, however how do I get this to work on Radient side? I renamed trigger_use on the elevator button, added hint_string (Which doesn't display in-game) and added a target on trigger_use to target the trees.

Sorry I am quite new to scripting, majority of gsc scripts are from tutorials etc.

 
Loading ...