UGX-Mods

Call of Duty: Black Ops 3 => Help Desk => Scripting => Topic started by: DeletedUser on January 08, 2017, 02:09:00 pm

Title: How to make a trigger remove objects when player uses it?
Post by: DeletedUser on January 08, 2017, 02:09:00 pm
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!
Title: Re: How to make a trigger remove objects when player uses it?
Post by: All0utWar on January 08, 2017, 08:57:29 pm
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.
Title: Re: How to make a trigger remove objects when player uses it?
Post by: DeletedUser on January 09, 2017, 05:18:54 am
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?
Title: Re: How to make a trigger remove objects when player uses it?
Post by: buttkicker845 on January 09, 2017, 02:51:19 pm
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
}
}
}
Title: Re: How to make a trigger remove objects when player uses it?
Post by: MakeCents on January 09, 2017, 02:58:29 pm
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 (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
}
}
}
Title: Re: How to make a trigger remove objects when player uses it?
Post by: buttkicker845 on January 09, 2017, 03:09:34 pm

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
}
}
}
Title: Re: How to make a trigger remove objects when player uses it?
Post by: MakeCents on January 09, 2017, 03:21:01 pm
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;
}    
}
}
Title: Re: How to make a trigger remove objects when player uses it?
Post by: buttkicker845 on January 09, 2017, 04:17:55 pm
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 :)
Title: Re: How to make a trigger remove objects when player uses it?
Post by: DeletedUser on January 10, 2017, 04:04:52 am
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.