Jump to content

Help,I am want only Admin can use minigun script.


alex11

Recommended Posts

This Script got from MTA-Wiki,and I am try to Add Only Admin can use minigun.

  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if currentWeaponID == 38 then --if the weapon ID is minigun 
        toggleControl ( source, "fire", false ) --disable the fire button 
    else --otherwise 
        toggleControl ( source, "fire", true )  --enable it 
    end 
     
    if getClientName(thePlayer) == "MyNickname" then                
            toggleControl ( source, "fire", true )  --enable it 
    end  
         
end 
--add an event handler for onPlayerWeaponSwitch 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun ) 
  

I try write this script get PlayerName is Admin Name can use minigun,but it was not work.

I want to write it,Only AdminGroup Can use minigun.

Please,Help me~

Link to comment

i would create ma own xml file with my own admin list, then loop through the admin node and see if the players serial is in the xml if it is then do the minigun thing.

  

            "0000-0000-0000-0000"/> 
            "0000-0000-0000-0000"/> 

  

but the serial thing is broken and i allways do it the wrong way accoring to most people :(

Link to comment

Performing authentication based on nicknames is not a good idea. You should really learn how to use the Client, Account and ACL scripting functions imo.

You could try something like this (provided that you have some kind of function that allows players to login to an account).

  
function isAdminAccount(account) 
  local nick = "" 
  local group = aclGetGroup("Admin") 
  if (account and group) then 
    nick = string.lower(getAccountName(account) or "") 
    for _, object in ipairs(aclGroupListObjects(group) or {}) do 
      if (gettok(object, 1, string.byte('.')) == "user") then 
        if (nick == string.lower(gettok(object, 2, string.byte('.')))) then 
          return true 
        end 
      end 
    end 
  end 
  return false 
end 
  

Link to comment
Performing authentication based on nicknames is not a good idea. You should really learn how to use the Client, Account and ACL scripting functions imo.

You could try something like this (provided that you have some kind of function that allows players to login to an account).

i wasnt using nicks i was using serials, but its broken in this version which i stated.

Link to comment

My server have Install logingui resources.Every One have they own Account.

  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if currentWeaponID == 38 then --if the weapon ID is minigun 
        toggleControl ( source, "fire", false ) --disable the fire button 
    else --otherwise 
        toggleControl ( source, "fire", true )  --enable it 
    end 
     
    local taccount = getClientAccount ( thePlayer ) 
    if isAdminAccount(taccount) then                
            toggleControl ( source, "fire", true )  --enable it 
    end  
         
end 
  
function isAdminAccount(account) 
  local nick = "" 
  local group = aclGetGroup("Admin") 
  if (account and group) then 
    nick = string.lower(getAccountName(account) or "") 
    for _, object in ipairs(aclGroupListObjects(group) or {}) do 
      if (gettok(object, 1, string.byte('.')) == "user") then 
        if (nick == string.lower(gettok(object, 2, string.byte('.')))) then 
          return true 
        end 
      end 
    end 
  end 
  return false 
end 
  
  
--add an event handler for onPlayerWeaponSwitch 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun ) 
  

It's can't work.

Link to comment

try this a think it will work a just edited it a bit :) unfortunatly i cannot test cause my gta wont install :(

  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if (currentWeaponID == 38)  then --if the weapon ID is minigun 
      elseif ( isAdminAccount( getClientAccount ( thePlayer ) ) == true ) then                
               toggleControl ( source, "fire", true )  --enable it 
      elseif  ( isAdminAccount( getClientAccount ( thePlayer ) ) == false ) then  
               toggleControl ( source, "fire", false ) --disable the fire button 
      else --otherwise 
    if ( currentWeaponID ~= 38 ) then  
                toggleControl ( source, "fire", true )  --enable it 
          end 
     end 
end 
  

Link to comment
try this a think it will work a just edited it a bit :) unfortunatly i cannot test cause my gta wont install :(
  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if (currentWeaponID == 38)  then --if the weapon ID is minigun 
      elseif ( isAdminAccount( getClientAccount ( thePlayer ) ) == true ) then                
               toggleControl ( source, "fire", true )  --enable it 
      elseif  ( isAdminAccount( getClientAccount ( thePlayer ) ) == false ) then  
               toggleControl ( source, "fire", false ) --disable the fire button 
      else --otherwise 
    if ( currentWeaponID ~= 38 ) then  
                toggleControl ( source, "fire", true )  --enable it 
          end 
     end 
end 
  

myrules.lua

  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if currentWeaponID == 38 then --if the weapon ID is minigun 
            toggleControl ( source, "fire", false ) --disable the fire button 
        else --otherwise 
            toggleControl ( source, "fire", true )  --enable it 
        end 
     
     
    if (isAdminAccount(getClientAccount ( thePlayer )) == true) then                
            toggleControl ( source, "fire", true )  --enable it 
    end  
  
end 
  
  
function isAdminAccount(account) 
  local nick = "" 
  local group = aclGetGroup("Admin") 
  if (account and group) then 
    nick = string.lower(getAccountName(account) or "") 
    for _, object in ipairs(aclGroupListObjects(group) or {}) do 
      if (gettok(object, 1, string.byte('.')) == "user") then 
        if (nick == string.lower(gettok(object, 2, string.byte('.')))) then 
          return true 
        end 
      end 
    end 
  end 
  return false 
end 
  
  
--add an event handler for onPlayerWeaponSwitch 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMinigun ) 
  

myrules.lua and [uVA]Bart Give me his lua will Show same error messages.

ERROR MESSAGE SHOW ON CONSOLE [23:50:48] WARNING: myrules.server.lua: Bad argument @ 'getClientAccount' - Line: 9

what's happen?

Link to comment
  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID, thePlayer ) --when a player switches his weapon 
    if currentWeaponID == 38 then --if the weapon ID is minigun 
            toggleControl ( source, "fire", false ) --disable the fire button 
        else --otherwise 
            toggleControl ( source, "fire", true )  --enable it 
        end 
     
     
    if (isAdminAccount(getClientAccount ( thePlayer )) == true) then                
            toggleControl ( source, "fire", true )  --enable it 
    end  
  
end 
  

Should be:

  
function weaponSwitchDisableMinigun ( previousWeaponID, currentWeaponID) --when a player switches his weapon 
    if currentWeaponID == 38 then --if the weapon ID is minigun 
            toggleControl ( source, "fire", false ) --disable the fire button 
        else --otherwise 
            toggleControl ( source, "fire", true )  --enable it 
        end 
     
     
    if (isAdminAccount(getClientAccount ( source )) == true) then                
            toggleControl ( source, "fire", true )  --enable it 
    end  
  
end 
  

Link to comment
  
local spawnX = 2496 
local spawnY = -1684 
local spawnZ = 14 
function weaponSwitchDisableMyWeapon ( previousWeaponID, currentWeaponID) --when a player switches his weapon 
    if currentWeaponID == 38 or currentWeaponID == 36 then --if the weapon ID is minigun 
            toggleControl ( source, "fire", false ) --disable the fire button 
        toggleControl ( source, "action", false ) --disable the fire button 
        else --otherwise 
            toggleControl ( source, "fire", true )  --enable it 
        toggleControl ( source, "action", true ) --disable the fire button 
        end 
     
     
    if (isAdminAccount(getClientAccount ( source )) == true) then                
            toggleControl ( source, "fire", true )  --enable it 
        toggleControl ( source, "action", true ) --disable the fire button 
    end  
  
end 
  
  
--add an event handler for onPlayerWeaponSwitch 
addEventHandler ( "onPlayerWeaponSwitch", getRootElement(), weaponSwitchDisableMyWeapon ) 
  
function isAdminAccount(account) 
  local nick = "" 
  local group = aclGetGroup("Admin") 
  if (account and group) then 
    nick = string.lower(getAccountName(account) or "") 
    for _, object in ipairs(aclGroupListObjects(group) or {}) do 
      if (gettok(object, 1, string.byte('.')) == "user") then 
        if (nick == string.lower(gettok(object, 2, string.byte('.')))) then 
          return true 
        end 
      end 
    end 
  end 
  return false 
end 
  
function giveWeaponsOnMyEvent ( ) 
    giveWeapon ( source, 5, 1 ) 
    giveWeapon ( source, 22, 35 ) 
    giveWeapon ( source, 25, 32 ) 
    giveWeapon ( source, 29, 200 ) 
    giveWeapon ( source, 31, 100 ) 
    --giveWeapon ( source, 17, 25 ) 
    --giveWeapon ( source, 42, 500 ) 
end 
addEventHandler ( "onPlayerJoin", getRootElement(), giveWeaponsOnMyEvent ) -- attach the event handler 
addEventHandler ( "onPlayerWasted", getRootElement(), giveWeaponsOnMyEvent ) -- attach the event handler 
addEventHandler ( "onPlayerSpawn", getRootElement(), giveWeaponsOnMyEvent ) 
  
function Wait_Timer ( ) 
end 
  
function player_Wasted_Spawn () 
    setTimer ( Wait_Timer, 3000, 1, "Hello, World!" ) 
    spawnPlayer(source,spawnX,spawnY,spawnZ) 
     
end 
addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted_Spawn )    
  

This is Finish...but Player be kill,that's no delay goto CJ old safe hose.

And lock Action(TAB),if player use minigun,Press Mouse Right button,and Press TAB(Action),it will fire...

so lock TAB(Action)

Link to comment
  • 4 months later...
  
local spawnX = 2496 
local spawnY = -1684 
local spawnZ = 14 
  
function Wait_Timer ( thePlayer ) 
    spawnPlayer(thePlayer ,spawnX,spawnY,spawnZ) 
end 
  
function player_Wasted_Spawn () 
    setTimer ( Wait_Timer, 3000, 1, source )  
end 
addEventHandler ( "onPlayerWasted", getRootElement(), player_Wasted_Spawn )    
  

That's what I would do, or alternativly do

     setTimer ( spawnPlayer, 3000, 1, source, spawnX, spawnY, spawnZ )  

in the place of the other timer

Link to comment
would this work? (if i put it in acl, group default)

No it wouldn't. First of all, "function.name" is used for scripting functions like killPlayer(), not console commands - for those you use "command.name". Also, I'm pretty sure that a "command.give 38" right will not work.

if not, can someone how i diable spawning of minigun?

If you are using the freeroam resource, you can specify disabled weapons in meta.xml. For other resources there might be a setting like this, but it's more likely you will have to edit the code of the command handler.

Link to comment

If you are using the freeroam resource, you can specify disabled weapons in meta.xml. For other resources there might be a setting like this, but it's more likely you will have to edit the code of the command handler.

I removed that one when i made it, can someone post it, the anti-minigun?

Link to comment

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