Jump to content

Help pls!


IIYAMA

Recommended Posts

  • Moderators
  
--SERVER SIDE!!! 
alreadyS = 0 
  
function bind () 
        bindkey ( source ,"x", "down",   
function(player, key, state) 
     if currentWeaponID == 34 then 
        if alreadyS == 0 then 
            setPedStat ( player, 79, 300 ) 
            alreadyS = 1 
            outputChatBox("Works", player, 255, 69, 0) 
        else 
            setPedStat ( player, 79, 999 )       
            alreadyS = 0 
            outputChatBox("works!!.", player, 255, 69, 0) 
        end 
     end 
  
end 
) 
  
end 
  
addEventHandler ( "onPlayerJoin", getRootElement(), bind ) 

I am trying to change the stat of a sniper with the button X. (server side)

What did I do wrong?

Link to comment

currentWeaponID is nil.. I think in MTASA you can't see what weapon player are using.

What I can do..

alreadyS = 0 
  
bindKey(source,'x','down', 
 function() 
   if alreadyS == 0 then 
     setPedStat(source,79,300) 
     alreadyS = 1 
     outputChatBox('Works fine!', source, 255, 69, 0) 
   else 
     setPedStat(source,79,999) 
     alreadyS = 0 
     outputChatBox('It works oO',source,255,69,0) 
   end 
end) 

Link to comment
currentWeaponID is nil.. I think in MTASA you can't see what weapon player are using.

What I can do..

alreadyS = 0 
  
bindKey(source,'x','down', 
 function() 
   if alreadyS == 0 then 
     setPedStat(source,79,300) 
     alreadyS = 1 
     outputChatBox('Works fine!', source, 255, 69, 0) 
   else 
     setPedStat(source,79,999) 
     alreadyS = 0 
     outputChatBox('It works oO',source,255,69,0) 
   end 
end) 

it is possible, just use "getPedWeapon".

alreadyS = 0 
  
addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source,"x","down",setStat) 
end) 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in ipairs(getElementsByType("player")) do 
        bindKey(player,"x","down",setStat) 
    end 
end) 
  
function setStat(player) 
    local currentWeaponID = getPedWeapon(player) 
    if (currentWeaponID == 34) then 
        if (alreadyS == 0) then 
            setPedStat ( player, 79, 300 ) 
            alreadyS = 1 
            outputChatBox("Works", player, 255, 69, 0) 
        else 
            setPedStat ( player, 79, 999 )      
            alreadyS = 0 
            outputChatBox("works!!.", player, 255, 69, 0) 
        end 
    end 
end 

Link to comment

Well, it has to work, maybe you put it vice-versa? like this:

alreadyS = 0 
  
addEventHandler("onPlayerJoin",root, 
function () 
    bindKey(source,"x","down",setStat) 
end) 
  
addEventHandler("onResourceStart",resourceRoot, 
function () 
    for index, player in ipairs(getElementsByType("player")) do 
        bindKey(player,"x","down",setStat) 
    end 
end) 
  
function setStat(player) 
    local currentWeaponID = getPedWeapon(player) 
    if (currentWeaponID == 34) then 
        if (alreadyS == 0) then 
            setPedStat ( player, 79, 999 ) 
            alreadyS = 1 
            outputChatBox("Works", player, 255, 69, 0) 
        else 
            setPedStat ( player, 79, 300 )     
            alreadyS = 0 
            outputChatBox("works!!.", player, 255, 69, 0) 
        end 
    end 
end 

Link to comment
local state = { } 
  
function setStat( player ) 
    local currentWeaponID = getPedWeapon( player ) 
    if currentWeaponID == 34 then 
        state[ player ] = not state[ player ] 
        if state[ player ] then 
            setPedStat ( player, 79, 999 ) 
            outputChatBox( "Works", player, 255, 69, 0 ) 
        else 
            setPedStat ( player, 79, 300 )     
            outputChatBox( "works!!.", player, 255, 69, 0 ) 
        end 
    else 
        outputChatBox( 'Weapon should be 34 ID' ) 
    end 
end 
  
addEventHandler( "onPlayerJoin",root, 
    function ( ) 
        bindKey( source,"x","down",setStat ) 
    end 
) 
  
addEventHandler( 'onPlayerQuit',root, 
    function( ) 
        state[ source ] = nil 
    end 
)    
  
addEventHandler( "onResourceStart",resourceRoot, 
    function ( ) 
        for _, v in pairs( getElementsByType 'player' ) do 
            bindKey( v,"x","down",setStat ) 
        end 
    end 
) 
  

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