Team & class Pickup
#1

Hi guys, i have few questions about pickups, team and classes.
Alright, here i describe what i have to do:
i have a GM that manage Teams like USA and Russia, and classes like Recon, Support, Medic ecc...
Every Team has the same classes, so i want that the medic class, when it hits the middle mouse button creates a Medikit, that's the hearth pickup icon, and lock that pickup, if the Medic is in Team USA then only players in Team USA can pickup it, else if the medic is in Team Russia only russian can pickup it. Now i thought to use an Array list of all the Medikit created by USA team and Russia team, and when an american medic create a new medikit, the old one get destroyed. Ok now all teams and classes are setted up the right way BUT...when i'm USA team and i create a medikit then the medikit appears, and when i lose health and pick it up, it destroy itself, and here comes the annoing things.
1-Other players can still see the pickup, no matter if for me is destroyed, they can still see it;
2-Russia Team's players can pick up USA Team's pickup;

Here is the parts of the code that manage this thing:

At the top i added this:
Код:
new Medikit[MAX_PLAYERS];
new MedikitTeam[MAX_OBJECTS];
then For the key detection :
Код:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
     if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
     {
            new Float:PlayerPos[3];
            GetPlayerPos(playerid,PlayerPos[0],PlayerPos[1],PlayerPos[2]);
		
            if(GetPlayerState(playerid) == 1)
            {
                  if(playerClass[playerid] == TeamClassType[Medic]) //Is a Medic Class
                  {
                        if(gTeam[playerid] == 1)
                        {
                              if(Medikit[playerid] == 0)
                              {
                                    Medikit[0] = CreatePickup(1240,3,PlayerPos[0],PlayerPos[1]-2,PlayerPos[2],-1);
                                    MedikitTeam[Medikit[0]] = 1;
                                    return 1;
                              }
                              else if(Medikit[playerid] > 0)
                              {
                                    DestroyObject(Medikit[0]);
                                    Medikit[0] = CreatePickup(1240,3,PlayerPos[0],PlayerPos[1]-2,PlayerPos[2],-1);
                                    MedikitTeam[Medikit[0]] = 1;
                                    return 1;
                              }
                        }
                        else if(gTeam[playerid] == 2)
                        {
                              if(Medikit[playerid] == 0)
                              {
                                    Medikit[0] = CreatePickup(1240,3,PlayerPos[0],PlayerPos[1]-2,PlayerPos[2],-1);
                                    MedikitTeam[Medikit[0]] = 2;
                                    return 1;
                              }
                              else if(Medikit[playerid] > 0)
                              {
                                    DestroyObject(Medikit[1]);
                                    Medikit[0] = CreatePickup(1240,3,PlayerPos[0],PlayerPos[1]-2,PlayerPos[2],-1);
                                    MedikitTeam[Medikit[0]] = 2;
                                    return 1;
                              }
                        }
                  }
            }
      }
      return 1;
And last part is for when a player pick up the pickup :
Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(pickupid == Medikit[playerid])
      {
            if(gTeam[playerid] == MedikitTeam[Medikit[0]])
            {
                  SetPlayerHealth(playerid,100);
                  DestroyObject(Medikit[0]);
                  return 1;
            }
      }
      return 1;
}
I hope that you guys can help me, i'm stuck at this point for 2 days and my server isn't proceding as i was hoping, so any help is appreciated.
Thanks in advance
RebelWolf
Reply
#2

https://sampwiki.blast.hk/wiki/DestroyPickup
Sure this does not work?

Edit:
In the case where it destroys for you is that, when it is picked up it destroys automatically (GTA Side - without code) due to the type and / or may respawn after a while or some actions.
https://sampwiki.blast.hk/wiki/PickupTypes

If not yet understood:
Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
      if(pickupid == Medikit[playerid])
      {
            if(gTeam[playerid] == MedikitTeam[Medikit[0]])
            {
                  SetPlayerHealth(playerid,100);
                  DestroyPickup(Medikit[0]);
                  return 1;
            }
      }
      return 1;
}
Reply
#3

Ok, i understand.
If i'm not wrong gta is "automatically destroying the pickup for all the players connected"? And if so, i have 2 question:
1-i want to track WHO create that pickup, so that when other players get healed by my pickup, i get score, like a text with Team healing +50, or something similar;
2-What's the pickup type number for the pickup that get destroyied (and doesn't respawn) if picked up?

thanks for your quick answer, it helps me understanding how samp works (and also how pawno works).
Reply
#4

Use the type "2" when creating pickup.
https://sampwiki.blast.hk/wiki/CreatePickup

DestroyObject is for objects only;
DestroyPickup is for pickups only;
DestroyWHATEVERELSE for WHATEVERELSE only.

Make the use of wiki, also when looking into functions seek for Related Functions list, the easiest and quickest way to learn sa-mp's library.

Should work: May need some minnor tweaks.

Код:
new Medikit[MAX_PLAYERS];
new MedikitTeam[MAX_PICKUPS];
new PickupUse[MAX_PICKUPS];
	/*
		1 - medkits
		2 - guns
		3 - bandages
		4 - whateverELSE
		5 - .... 
	*/

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
     if((newkeys & KEY_SUBMISSION) && !(oldkeys & KEY_SUBMISSION))
     {		
            if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
            {
                  if(playerClass[playerid] == TeamClassType[Medic]) //Is a Medic Class
                  {
						new Float:PlayerPos[3];
						GetPlayerPos(playerid, PlayerPos[0], PlayerPos[1], PlayerPos[2]);
                        if(Medikit[playerid] > 0)
                        {
                            DestroyPickup(Medikit[playerid]);
							PickupUse[Medikit[playerid]] = 0;
							MedikitTeam[Medikit[playerid]] = 0;
							Medikit[playerid] = 0;
                        }
                        Medikit[playerid] = CreatePickup(1240, 2, PlayerPos[0], PlayerPos[1]-2, PlayerPos[2], -1);
                        MedikitTeam[Medikit[playerid]] = gTeam[playerid];
						PickupUse[Medikit[playerid]] = 1;
                  }
            }
      }
      return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(gTeam[playerid] == MedikitTeam[pickupid]) // Team can pick up only their team pickups
    {
		if(PickupUse[pickupid] == 1) // Medkits
		{
			SetPlayerHealth(playerid,100);
			DestroyPickup(pickupid);
			Medikit[playerid] = 0;
			PickupUse[pickupid] = 0;
			MedikitTeam[pickupid] = 0;
			return 1;
		}
		else if(PickupUse[pickupid] == 2) // other team only pickups
		{
			// Do your code
			return 1;
		}
		else if(PickupUse[pickupid] == 3)
		{
			// Do your code
			return 1;
		}
		else if(PickupUse[pickupid] == 4)
		{
			// Do your code
			return 1;
		}
		else
		{
			// Wrong use? 
			return 1;
		}
    }
    return 1;
}
For the function when someone accepts medkit from team member simply create another Array like `PickupUse` and when creating pickup equal it to playerid. Then OnPickup assign the score using YourNewARRAY[pickupid].
Reply
#5

Thanks Hanger, i've putted this into the GM, tomorrow i'll try it with some friends to test it out, i'll put your name into my server credits, if i have your permiss. Thanks another time, and the last question:
that sheriff star gives you a reputation point? Only for knowledge
Thanks a lot, if i can (without blow that code up) i'll implement that so it can fit my needs.
And sorry if i make words mistakes, i'm not english soo... When it's completed, I'll invite you in my server to give it a try, it's on BF3 style

For now i thank you another time and goodnight
Cheers
Rebel Wolf
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)