That's at least a start.
The problem in this case would be that the player, who is being asked to exchange weapons, had only like a millisecond of time to press the F-Button, since you only check once if he pressed the button. That's where while() is used.
Code:
players = getentarray("player", "classname");
aimedplayer = undefined; //undefined yet
selfweapon = self getCurrentWeapon();
otherweapon = undefined;
for(i = 0; i < players.size; i++)
{
if(self islookingat (players[i]) ) //here is used IsLookingAt function... so if player is looking at the target(on other player) then continue also...
{
aimedplayer = players[i];
otherweapon = aimedplayer getCurrentweapon();
aimedplayer iprintlnBold("Press F to exchange weapons with " + players.name); //this text is visible only for aimed player...
}
}
secs = 0.0;
while(secs < 5)
{
if(aimedplayer useButtonPressed())
{
self thread exchangeWeapons(aimedPlayer, selfweapon, otherweapon);
return;
}
wait .05;
secs += 0.05;
}
self iprintlnBold(aimedplayer.name + " did not want to exchange weapons with you"); //A note for the player
Then you will need the exchangeWeapons() function.
Code:
//aimedPlayer = Player who was aimed, selfweapon = weapon of the guy who asked for weaponexchange, otherweapon = weapon of the other guy
exchangeWeapons(aimedPlayer, selfweapon, otherweapon)
{
//give 'selfweapon' to 'aimedPlayer
//give 'otherweapon' to 'self'
}