Jump to content

pickups for teams only


Wisin

Recommended Posts

Posted

hello all, i made a map file which containts pickups and i want to restrict them to a team expecified, so i did,

 <pickup id="pickup (health) (1)" type="health" interior="0" amount="100" respawn="30000" dimension="0" posX="1665.3149414063" posY="-1909.2155761719" posZ="21.954151153564" rotX="0" rotY="0" rotZ="0" team="Chinese" /> 

but now i don't know how to check that team and if matches with player team he can pick it else it will cancel the event, if someone can tell me how.

thanks

Posted
addEventHandler()

OnPickupHit -- event

getElementData()

getPlayerTeam()

getTeamName()

now check if name equals to name from element data

if no - cancelEvent()

ok but from what i get the element data?

Posted

i've found a problem, i got a money drop script but i think this other pickups for teams is messing with it, here is my money drop script

  
function createMoney(player) 
   local x, y, z = getElementPosition(player); 
   local x1, y1, x2, y2; 
   x1 = (x-2)+(math.random()*4); 
   y1 = (y-2)+(math.random()*4); 
   x2 = (x-2)+(math.random()*4); 
   y2 = (y-2)+(math.random()*4); 
   local moneyAmmount = getPlayerMoney(player); 
   -- it is not fair too get all the player money. 
   moneyAmmount = math.floor(moneyAmmount/1); 
  
   takePlayerMoney(player, moneyAmmount); 
  
   -- We are going to create 2 pickups, zo we are just cut the ammount in half 
   moneyAmmount = math.floor(moneyAmmount/2); 
  
   -- Create the pickups 
   setElementData(createPickup(x1, y1, z, 3, 1212), "ammount", moneyAmmount); 
   setElementData(createPickup(x2, y2, z, 3, 1212), "ammount", moneyAmmount); 
end 
  
function moneyPickupHit(player) 
   local money = getElementData(source, "ammount"); 
   if money then 
      givePlayerMoney(player, money); 
      destroyElement(source); 
   end 
end 
  
function playerJustGotDied(ammo, attacker, weapon, bodypart) 
   createMoney(source); 
end 
  
addEventHandler("onPickupUse", getRootElement(), moneyPickupHit); 
addEventHandler("onPlayerWasted", getRootElement(), playerJustGotDied); 

Posted
i've found a problem, i got a money drop script but i think this other pickups for teams is messing with it, here is my money drop script

 ...

Very informative.

Posted
function onUse(hitPlayer) 
local team = getPlayerTeam(hitPlayer) 
local teamName = getTeamName(team) 
local eleData = getElementData(source,"team") 
if eleData == teamName then 
else 
cancelEvent() 
   end 
end 
addEventHandler("onPickupHit",getRootElement(),onUse) 

thats it.

Posted

You can check if the hit pickup is a money pickup before you cancel event.

Something like this:

function onUse(hitPlayer) 
   local teamName = getTeamName( getPlayerTeam( hitPlayer ) ) 
   local eleData = getElementData(source,"team") 
   if ( eleData ~= teamName ) and ( getElementModel( source ) ~= 1212 ) then -- 1212 or whatever model ID is your money pickup 
      cancelEvent() 
   end 
end 
addEventHandler("onPickupHit",getRootElement(),onUse) 

Posted

i dont see any "team" element data in his money pickups script..

shouldnt this eleData == teamName fail when picked up money pickup then? eleData will be false, team name probably something else..

Posted

You can't see it because it's in the map file that he showed in the first post that you probably forgot about.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...