Page 1 of 1
[Help] How to use tigger_use
Posted: July 1st, 2010, 7:03 pm
by paintlax21
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
}
Re: [Help] How to use tigger_use
Posted: July 1st, 2010, 7:37 pm
by paintlax21
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
Re: [Help] How to use tigger_use
Posted: July 1st, 2010, 7:53 pm
by Buzzard
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".
Re: [Help] How to use tigger_use
Posted: July 1st, 2010, 8:16 pm
by paintlax21
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