Jump to content

[Help]


s1mple

Recommended Posts

function startgm() 
    accountname = getAccountName(getPlayerAccount(thePlayer)) 
    if isObjectInACLGroup("user." .. accountname, aclGetGroup("Admin")) then 
    do 
    if not getElementData(getLocalPlayer(), "onduty") then 
      gmtimer = setTimer(gmforad, 200, 0) 
      outputChatBox ("Admin is now: ON DUTY",150, 6, 8, 255,true) 
      setElementData(getLocalPlayer(), "onduty", true) 
    else 
      killTimer (gmtimer) 
      setElementData(getLocalPlayer(),"blood", 12000) 
      outputChatBox ("Admin is now: OFF DUTY!",150, 6, 8, 255,true) 
      setElementData(getLocalPlayer(), "onduty", false) 
    end 
end 
addEvent("onPlayerOnDuty", true) 
addEventHandler("onPlayerOnDuty", thePlayer, startgm) 
  
function gmforad() 
    if getElementData(getLocalPlayer(),"logedin") then 
        setElementData(getLocalPlayer(),"blood", 500000) 
        setElementData(getLocalPlayer(),"bleeding", 0) 
        setElementData(getLocalPlayer(),"cold", false) 
        setElementData(getLocalPlayer(),"temperature", 36.5) 
        setElementData(getLocalPlayer(),"pain", false) 
        setElementData(getLocalPlayer(),"brokenbone", false) 
        setElementData(getLocalPlayer(),"thirst", 100) 
        setElementData(getLocalPlayer(),"food", 100) 
    end 
end 

Can u make? if player is 10 meters from me, then he can't shoot and aim

Link to comment

A lot of people don't like making only showing you the functions on how it can be done I'll just give you an example on how it could be done.

getElementPosition() - Will get the players position

getElementsByType() - Will check if the player is a player if true then

getDistanceBetweenPoints3D() - Will check where both elements are and you can make it so that if either elements are withing 10m or 10 units of a player then stop them from aiming or shooting!!

LUA is probably one of the most basic languages out there it also has a lot of tutorials online on how you can code with LUA.

Good Luck!

Link to comment

Is it really that important to go off-topic only to point out that it's Lua and not LUA?

@S1mple:

You'll need to try doing things yourself, or you'll never learn. You were already given the basic functions needed to accomplish this, all you need to do now is study these functions - and think of a logical solution.

1. You need to get the position between you and the other player(s).

local allPlayers = getElementsByType("player") 

2. Loop through all the players, and compare the distance between them and you.

for i=1, #allPlayers do 
   local pX, pY, pZ = getElementPosition(allPlayers[i]) 
   local sX, sY, sZ = getElementPosition(localPlayer) 
   local theDistance = getDistanceBetweenPoints3D(pX, pY, pZ, sX, sY, sZ) 
   if(theDistance <= 10) then 
      toggleControl("aim_weapon", false) 
      toggleControl("fire", false) 
   else 
      toggleControl("aim_weapon", true) 
      toggleControl("fire", true) 
      -- We need to reset it to true if the check failed, otherwise they may get stuck with the control disabled. 
   end 
end 

There you have something to start with, go from there.

Link to comment

Simply you can use something like :

function functionName(player) 
    local allPlayers = getElementsByType("player") 
    for i,v in pairs(allPlayers) do 
        local x,y,z = getElementPosition(player) 
        local px,py,pz = getElementPosition(v) 
        local distance = math.floor(getDistanceBetweenPoints3D(x, y, z, px, py, pz)) or 0 
        if (distance < 10 and player ~= v) then 
            return true 
        else  
            return false 
        end 
    end 
end 

use it like an export function

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