Modme Forums

how to add an object similar to the PES

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


ModmeBot:

Thread By: maxman5050
How would i implement something that the player would need to go into a certain zone. Like on moon with the PES, if you go outside without it you die


ModmeBot:

Reply By: modric
Using a trig multiple scripted to apply damage to players in that trig would be a good start


ModmeBot:

Reply By: KillJoyYT
I can give some assistance but you have to be a lot more specific about what you're trying to accomplish


ModmeBot:

Reply By: maxman5050

KillJoyYT
I can give some assistance but you have to be a lot more specific about what you're trying to accomplish

So if i wanted to make an area that has poisonous gas, so I'd add trigger_hurts to that area, how can i make it that if you are in possession of something like a gas mask, the triggers don't affect you.


ModmeBot:

Reply By: tom5300

maxman5050
KillJoyYT I can give some assistance but you have to be a lot more specific about what you're trying to accomplish So if i wanted to make an area that has poisonous gas, so I'd add trigger_hurts to that area, how can i make it that if you are in possession of something like a gas mask, the triggers don't affect you.

I would use a trig multiple, covering the said area.
Maybe try something like the following:

function gas_mask_init()
{
	players = GetPlayers();
	foreach(player in players)
	{
		player.hasGasMask = false; //default players start without mask. when picked up, field is changed to true
		player thread hurt_players_in_bad_area();
		player thread gas_mask_pickup();
	}
}
function hurt_players_in_bad_area()
{
	level endon("end_game");
	damage_trigger = GetEnt("hurt_player_trig_targetname_from_radiant", "targetname"); //trigger mult where you want players to be hurt
	while(!self.hasGasMask) //loop ends when player picks up gas mask
	{
		if(self isTouching(damage_trigger))
		{
			self DoDamage(10, self.origin); //deals 10 damage to player every second when they are touching the trigger
			wait(1);
		}
		else
		{
			wait(0.1);
		}
	}
}
function gas_mask_pickup()
{
	level endon("end_game");
	gas_mask_trig = GetEnt("gas_mask_trig_from_radiant", "targetname"); //trigger at location to pickup a gas mask
	while(!self.hasGasMask)
	{
		gas_mask_trig waittill("trigger", player);
		if(player != self)
		{
			wait(0.1);
			continue;
		}
		self.hasGasMask = true;
	}
}

Not sure if the above code works... or is the most efficient lol. Be sure to insert your own kvp's :p


ModmeBot:

Reply By: maxman5050

tom5300
maxman5050 KillJoyYT I can give some assistance but you have to be a lot more specific about what you're trying to accomplish So if i wanted to make an area that has poisonous gas, so I'd add trigger_hurts to that area, how can i make it that if you are in possession of something like a gas mask, the triggers don't affect you. I would use a trig multiple, covering the said area. Maybe try something like the following: function gas_mask_init() { players = GetPlayers(); foreach(player in players) { player.hasGasMask = false; //default players start without mask. when picked up, field is changed to true player thread hurt_players_in_bad_area(); player thread gas_mask_pickup(); } } function hurt_players_in_bad_area() { level endon("end_game"); damage_trigger = GetEnt("hurt_player_trig_targetname_from_radiant", "targetname"); //trigger mult where you want players to be hurt while(!self.hasGasMask) //loop ends when player picks up gas mask { if(self isTouching(damage_trigger)) { self DoDamage(10, self.origin); //deals 10 damage to player every second when they are touching the trigger wait(1); } else { wait(0.1); } } } function gas_mask_pickup() { level endon("end_game"); gas_mask_trig = GetEnt("gas_mask_trig_from_radiant", "targetname"); //trigger at location to pickup a gas mask while(!self.hasGasMask) { gas_mask_trig waittill("trigger", player); if(player != self) { wait(0.1); continue; } self.hasGasMask = true; } } Not sure if the above code works... or is the most efficient lol. Be sure to insert your own kvp's :p

When i go over the trigger it says, "not available"


ModmeBot:

Reply By: tom5300

maxman5050
tom5300 maxman5050 KillJoyYT I can give some assistance but you have to be a lot more specific about what you're trying to accomplish So if i wanted to make an area that has poisonous gas, so I'd add trigger_hurts to that area, how can i make it that if you are in possession of something like a gas mask, the triggers don't affect you. I would use a trig multiple, covering the said area. Maybe try something like the following: function gas_mask_init() { players = GetPlayers(); foreach(player in players) { player.hasGasMask = false; //default players start without mask. when picked up, field is changed to true player thread hurt_players_in_bad_area(); player thread gas_mask_pickup(); } } function hurt_players_in_bad_area() { level endon("end_game"); damage_trigger = GetEnt("hurt_player_trig_targetname_from_radiant", "targetname"); //trigger mult where you want players to be hurt while(!self.hasGasMask) //loop ends when player picks up gas mask { if(self isTouching(damage_trigger)) { self DoDamage(10, self.origin); //deals 10 damage to player every second when they are touching the trigger wait(1); } else { wait(0.1); } } } function gas_mask_pickup() { level endon("end_game"); gas_mask_trig = GetEnt("gas_mask_trig_from_radiant", "targetname"); //trigger at location to pickup a gas mask while(!self.hasGasMask) { gas_mask_trig waittill("trigger", player); if(player != self) { wait(0.1); continue; } self.hasGasMask = true; } } Not sure if the above code works... or is the most efficient lol. Be sure to insert your own kvp's :p When i go over the trigger it says, "not available"

You have to set a hint string for a trigger_use:
gas_mask_trig SetHintString("Press and hold &&1 to pick up gas mask");
gas_mask_trig SetCursorHint("HINT_NOICON");


ModmeBot:

Reply By: maxman5050
does there have to be a thread in the main function?


ModmeBot:

Reply By: KillJoyYT
yeah under your usermap main put

level thread gas_mask_init();



haven't had time to test will take a look later tonight


ModmeBot:

Reply By: KillJoyYT
changed a couple things and added a few notes


function gas_mask_init()
{

	level flag::wait_till( "all_players_connected" );
	players = GetPlayers();
	foreach(player in players)
	{
		player.hasGasMask = false; //default players start without mask. when picked up, field is changed to true
		player thread hurt_players_in_bad_area();
		player thread gas_mask_pickup();
	}
}
function hurt_players_in_bad_area()
{
	level endon("end_game");
	damage_trigger = GetEnt("damage_trigger", "targetname"); //trigger mult where you want players to be hurt enable ai allies and ai axis kvps
    damage_trigger SetHintString("Hold &&1");
    damage_trigger SetCursorHint("HINT_NOICON");
	while(!self.hasGasMask) //loop ends when player picks up gas mask
	{
		if(self isTouching(damage_trigger))
		{
			self DoDamage(10, self.origin); //deals 10 damage to player every second when they are touching the trigger
			wait(1);
		}
		else
		{
			wait(0.1);
		}
	}
}
function gas_mask_pickup()
{
	level endon("end_game");
	gas_mask_trig = GetEnt("gas_mask_trig", "targetname"); //trigger at location to pickup a gas mask
    gas_mask_trig SetHintString("Hold &&1");
    gas_mask_trig SetCursorHint("HINT_NOICON");
	while(!self.hasGasMask)
	{
		gas_mask_trig waittill("trigger", player);
		if(player != self)
		{
			wait(0.1);
			continue;
		}
		self.hasGasMask = true;
	}
}


ModmeBot:

Reply By: mathfag
I changed a few things up from toms post because much of it wont work (walkthrough below).
Didn't test this though so no promises.

#define GAS_MASK_DAMAGE 10 //per second
#define NO_MASK_DAMAGE 50 //per second

callback::on_connect(&gas_mask_init); //before usermap::main

thread hurt_players_in_bad_area();



function gas_mask_init() //self = player
{
self.hasGasMask = false; //default players start without mask. when picked up, field is changed to true
self thread gas_mask_pickup();
}


function hurt_players_in_bad_area()
{
level endon("end_game");

while(1) 
	{
	foreach(player in GetPlayers())
		{
		if(player is_touching_gas_mask_trig())
			{
			if(isdefined(player.hasGasMask) && player.hasGasMask == 1)
				{
				player DoDamage(GAS_MASK_DAMAGE, player.origin);
				}
			else
				{
				player DoDamage(NO_MASK_DAMAGE, player.origin);
				}
			}
		}

	wait 1;
	}
}


function is_touching_gas_mask_trig() //self = player
{
damage_triggers = GetEntArray("gas_damage_trigger", "targetname"); //trigger mult

foreach(trig in damage_triggers)
	if(self IsTouching(trig))
		return 1;
return 0;
}


//im guessing this is a 1 location thing like a buildable or the bow on der eisendrache
function gas_mask_pickup() //self = player
{
	level endon("end_game");
	gas_mask_trig = GetEnt("gas_mask_trig", "targetname"); //trigger at location to pickup a gas mask
    gas_mask_trig SetCursorHint("HINT_NOICON");

	while(1)
	{
	gas_mask_trig SetHintString("Hold &&1 to pickup mask");

	gas_mask_trig waittill("trigger", player);
	if(isdefined(self.hasGasMask) && self.hasGasMask == 0)
		{
		self.hasGasMask = 1;
		}
	else if(isdefined(self.hasGasMask) && self.hasGasMask == 1)
		{
		gas_mask_trig SetHintString("Already have gas mask");
		wait 1;
		}
	else
		{
		IPrintLnBold("you done fucked up somewhere (or i did)");
		}
	wait 0.05;
	}
}




<hr><hr><hr>

Walkthrough toms mistakes (not trying to discourage or anything, just doing it so you learn a bit)


this wont work for anyone who joins later.
using callback::on_connect(&function);
runs function every time a player connects
level flag::wait_till( "all_players_connected" );
	players = GetPlayers();
	foreach(player in players)
	{
		player.hasGasMask = false; //default players start without mask. when picked up, field is changed to true
		player thread hurt_players_in_bad_area();
		player thread gas_mask_pickup();
	}




What if there are multiple triggers and what if you lose your mask?
Check my code for checking multiple triggers
function hurt_players_in_bad_area()
{
damage_trigger = GetEnt("damage_trigger", "targetname"); 
damage_trigger SetHintString("Hold &amp;&amp;1");


while(!self.hasGasMask)
{


Not wrong but kind of pointless:
why if(player != self)
if there are 4 players in the game then there will be 4 functions threaded anyway
function gas_mask_pickup()
{
	level endon("end_game");
	gas_mask_trig = GetEnt("gas_mask_trig", "targetname"); //trigger at location to pickup a gas mask
    gas_mask_trig SetHintString("Hold &amp;&amp;1");
    gas_mask_trig SetCursorHint("HINT_NOICON");
	while(!self.hasGasMask)
	{
		gas_mask_trig waittill("trigger", player);
		if(player != self)
		{
			wait(0.1);
			continue;
		}
		self.hasGasMask = true;
	}
}


ModmeBot:

Reply By: tom5300
Technically my mistakes, I posted that code.
But yeah, I just threw together a bit of code to get the op started. Thanks for fixing it!


ModmeBot:

Reply By: KillJoyYT
thank you :-)