Jump to content

Help with canceling an event


Dazee

Recommended Posts

Posted

Ok so I created a script for teams criminals,civilians I made it so civilians can't aim or shoot, and made it so criminals can aim and shoot but when i call an eventhandler that checks restrictions for criminals that enables them to shoot and I do that while I am in a civilian team I get allowed to shoot, so I was wondering if I could

cancelEvent() 

only for a certain team and how.

BTW here is my script

function createTeamsOnStart () 
  
      civilTeam = createTeam ( "Civilians", 0, 153, 0 ) 
      criminalTeam = createTeam ( "Criminals", 255, 0, 0 ) 
       
       
end 
  
addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart ) 
  
function becomeCivil ( thePlayer ) 
  
      setPlayerTeam ( thePlayer, civilTeam ) 
      outputChatBox ("You are now a Civilian!",thePlayer,0, 153, 0 ) 
      if ( civilTeam ) then 
      toggleControl (thePlayer, "fire", false ) 
      toggleControl (thePlayer, "aim_weapon", false ) 
      else 
      toggleControl (thePlayer, "fire", true ) 
      toggleControl (thePlayer, "aim_weapon", true ) 
   end 
end 
end 
function becomeCriminal ( thePlayer ) 
     setPlayerTeam ( thePlayer, criminalTeam ) 
     outputChatBox ("You are now a Criminal!", thePlayer, 255, 0, 0 ) 
     if ( getTeamFriendlyFire ( criminalTeam ) == false ) then 
     setTeamFriendlyFire (criminalTeam, true) 
    end 
  end  
function checkRestrictions( ) 
     if (criminalTeam) then 
     toggleControl ( source, "fire", true ) 
     toggleControl ( source, "aim_weapon", true ) 
  end 
 end 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement (), checkRestrictions ) 
  
addCommandHandler( "criminal", becomeCriminal ) 
addCommandHandler( "quitjob", becomeCivil ) 

Posted (edited)
  
function createTeamsOnStart () 
  
      civilTeam = createTeam ( "Civilians", 0, 153, 0 ) 
      criminalTeam = createTeam ( "Criminals", 255, 0, 0 ) 
      
      
end 
  
addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart ) 
  
function becomeCivil ( thePlayer ) 
  
      setPlayerTeam ( thePlayer, getTeamFromName(civilTeam) ) 
      outputChatBox ("You are now a Civilian!",thePlayer,0, 153, 0 ) 
      if ( civilTeam ) then 
      toggleControl (thePlayer, "fire", false ) 
      toggleControl (thePlayer, "aim_weapon", false ) 
      else 
      toggleControl (thePlayer, "fire", true ) 
      toggleControl (thePlayer, "aim_weapon", true ) 
   end 
end 
function becomeCriminal ( thePlayer ) 
     setPlayerTeam ( thePlayer, getTeamFromName(criminalTeam) ) 
     outputChatBox ("You are now a Criminal!", thePlayer, 255, 0, 0 ) 
     if ( getTeamFriendlyFire ( criminalTeam ) == false ) then 
     setTeamFriendlyFire (getTeamFromName(criminalTeam), true) 
    end 
  end 
  
addEventHandler("onPlayerDamage", root, function(a) 
     if getTeamName(getPlayerTeam(a)) == "Criminals" and getTeamName(getPlayerTeam(source)) == "Civilians" then 
          cancelEvent()    
 end 
end 
) 
function checkRestrictions( ) 
     if getTeamName(getPlayerTeam(source) == "Criminals" then 
     toggleControl ( source, "fire", true ) 
     toggleControl ( source, "aim_weapon", true ) 
  end 
 end 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement (), checkRestrictions ) 
  
addCommandHandler( "criminal", becomeCriminal ) 
addCommandHandler( "quitjob", becomeCivil ) 
  

Edited by Guest
Posted

Your code has an extra 'end' at line 23.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
  
function createTeamsOnStart () 
  
      civilTeam = createTeam ( "Civilians", 0, 153, 0 ) 
      criminalTeam = createTeam ( "Criminals", 255, 0, 0 ) 
      
      
end 
  
addEventHandler("onResourceStart", resourceRoot, createTeamsOnStart ) 
  
function becomeCivil ( thePlayer ) 
  
      setPlayerTeam ( thePlayer, getTeamFromName(civilTeam) ) 
      outputChatBox ("You are now a Civilian!",thePlayer,0, 153, 0 ) 
      if ( civilTeam ) then 
      toggleControl (thePlayer, "fire", false ) 
      toggleControl (thePlayer, "aim_weapon", false ) 
      else 
      toggleControl (thePlayer, "fire", true ) 
      toggleControl (thePlayer, "aim_weapon", true ) 
   end 
end 
function becomeCriminal ( thePlayer ) 
     setPlayerTeam ( thePlayer, getTeamFromName(criminalTeam) ) 
     outputChatBox ("You are now a Criminal!", thePlayer, 255, 0, 0 ) 
     if ( getTeamFriendlyFire ( criminalTeam ) == false ) then 
     setTeamFriendlyFire (getTeamFromName(criminalTeam), true) 
    end 
  end 
  
addEventHandler("onPlayerDamage", root, function(a) 
     if getTeamName(getPlayerTeam(a)) == "Criminals" and getTeamName(getPlayerTeam(source)) == "Civilians" then 
          cancelEvent()    
 end 
end 
) 
function checkRestrictions( ) 
     if getTeamName(getPlayerTeam(source) == "Criminals" then 
     toggleControl ( source, "fire", true ) 
     toggleControl ( source, "aim_weapon", true ) 
  end 
 end 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement (), checkRestrictions ) 
  
addCommandHandler( "criminal", becomeCriminal ) 
addCommandHandler( "quitjob", becomeCivil ) 
  

You just broke the script btw I figured it out on my own thanks for trying :P

Posted

All that i know getTeamFromName needs a string containing the tem name and createTeam already returns the team element so i dont understand why u used getTeamFromName to get the team element if u have it already.

setPlayerTeam(thePlayer, civilTeam 

350x20_FFFFFF_FFFFFF_000000_000000.png

http://i.imgur.com/CSE28MJ.png

Don't hesitate to contact me for anything! If I can help, I will for sure!

Education is the most powerful weapon which you can use to change the world. - Castillo

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...