[Help] How to use tigger_use

Have a question about modding, modelling or skinning? Have a tutorial to post? Post here!

Moderator: Core Staff

Post Reply
paintlax21
CJ Donator
CJ Donator
Posts: 52
Joined: August 10th, 2009, 5:20 pm

[Help] How to use tigger_use

Post by paintlax21 » July 1st, 2010, 7:03 pm

can someone give me a base code on how to do something to a player when they press use on a trigger_use

example

if(player presses use)
{
//do stuff here
}

paintlax21
CJ Donator
CJ Donator
Posts: 52
Joined: August 10th, 2009, 5:20 pm

Re: [Help] How to use tigger_use

Post by paintlax21 » July 1st, 2010, 7:37 pm

i have this

Code: Select all

main()
{
	player = getent("weapon","targetname");
	if(isdefined(player))
	{
		for(i=0;i<player.size;i=i+1)
		player[i] thread GIVE();
	}
}

Give()
{
	while(true)
	{
		self waittill("trigger",other);
		wait .1;
		if(!self hasWeapon("ak47_mp"))
		{
			self giveWeapon("ak47_mp");
			self giveMaxAmmo("ak47_mp");
			wait .1;
			self switchToWeapon("ak47_mp");
		}
	}
}
but it doesnt work can you tell me how to fix it

User avatar
Buzzard
CJ Wannabe
CJ Wannabe
Posts: 23
Joined: November 5th, 2009, 7:13 pm

Re: [Help] How to use tigger_use

Post by Buzzard » July 1st, 2010, 7:53 pm

paintlax21 wrote:i have this

Code: Select all

main()
{
	player = getent("weapon","targetname");
	if(isdefined(player))
	{
		for(i=0;i<player.size;i=i+1)
		player[i] thread GIVE();
	}
}

Give()
{
	while(true)
	{
		self waittill("trigger",other);
		wait .1;
		if(!self hasWeapon("ak47_mp"))
		{
			self giveWeapon("ak47_mp");
			self giveMaxAmmo("ak47_mp");
			wait .1;
			self switchToWeapon("ak47_mp");
		}
	}
}
but it doesnt work can you tell me how to fix it
I guess you tried to create a trigger which gives the AK 47 to a player who touch it.

Change some of the "self" to "other" in the Give-Function.

"self" = trigger
"other" = player

Fixed Code:

Code: Select all

main()
{
	player = getent("weapon","targetname");
	if(isdefined(player))
	{
		for(i=0;i<player.size;i=i+1)
		player[i] thread GIVE();
	}
}

Give()
{
	while(true)
	{
		self waittill("trigger",other);
		wait .1;
		if(!other hasWeapon("ak47_mp")) // <--
		{
			other giveWeapon("ak47_mp"); // <--
			other giveMaxAmmo("ak47_mp"); // <--
			wait .1;
			other switchToWeapon("ak47_mp"); // <--
		}
	}
}
"<--" is placed where I changed the "self" to "other".

paintlax21
CJ Donator
CJ Donator
Posts: 52
Joined: August 10th, 2009, 5:20 pm

Re: [Help] How to use tigger_use

Post by paintlax21 » July 1st, 2010, 8:16 pm

Code: Select all

main()
{
	weapons = getEntArray("weapon", "targetname");
	if(isDefined(weapons))
	{
		for(i = 0;i < weapons.size;i++)
			weapons[i] thread give();
	}
}

give()
{
	for(;;)
	{
		self waittill("trigger", player);
		if(!player hasWeapon("ak47_mp"))
		{
			player giveWeapon("ak47_mp");
			player giveMaxAmmo("ak47_mp");
			wait 0.1;
			player switchToWeapon("ak47_mp");
		}
	}
}

that is the final working code

Post Reply

Who is online

Users browsing this forum: No registered users and 51 guests