Jump to content

[Help] Dual UZI script


marty000123

Recommended Posts

Hi lads.

I tried to create a script in where I have to make a command to give players a UZI skill. But now, when I type the command, everyone in the whole server gets the skill, but I am looking for the feature to give the skill to just one person. What do I exactly have to add to the script? I don't have a clue. I made the command to be admin-only.

This is what I have got so far:

function changePedStats(thePlayer, commandName) 
   if setPlayerStat(thePlayer, 75, 1000) then 
        outputChatBox("Congratulations! You have got dual wield UZI stats!") 
    end 
end 
addCommandHandler("givestats", changePedStats, true) 

Any help would be appreciated.

Regards,

Marty

Link to comment

setPedStat/setPlayerStat (use setPedStat as setPlayerStat is deprecated) only work server-side. So make sure your script is set as server-sided in meta.xml.

The first argument in a function with a command handler is the player who executed the command. If you want to specify the dual uzi skill for another player, you'll need to do something like this:

function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function changePedStats(thePlayer, _, name) 
   local plr = getPlayerFromPartialName(name) 
   if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end 
   local stat = setPedStat(plr, 75, 1000) 
   if (stat) then 
        outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) 
    end 
end 
addCommandHandler("givestats", changePedStats, true) 

If you just want it to be for the player who typed the command, do something like this:

function changePedStats(thePlayer, _) 
   local stat = setPedStat(thePlayer, 75, 1000) 
   if (stat) then 
        outputChatBox("Congratulations! You have got dual wield UZI stats!", thePlayer) 
    end 
end 
addCommandHandler("givestats", changePedStats, true) 

Link to comment

Hi Noki. I am going to try and add the following script to my already existing script:

function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) -- get his account 
      if (playerAccount) then -- if we got the account then 
            local playerMoney = getPlayerMoney(source) -- get his money amount 
            setAccountData(playerAccount, "piraterpg.money", playerMoney) -- store his current money amount in his account data 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) -- add an event handler 
  
function onPlayerLogin() 
      -- when a player logins, retrieve his money amount from his account data and set it 
      local playerAccount = getPlayerAccount(source) -- get his account 
      if (playerAccount) then -- if we got the account then 
            local playerMoney = getAccountData(playerAccount, "piraterpg.money") -- get the money amount was store in his account data 
            -- make sure there was actually a value saved under this key (check if playerMoney is not false). 
            -- this will for example not be the case when a player plays the gametype for the first time 
            if (playerMoney) then 
                  setPlayerMoney(source, playerMoney) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) -- add an event handler 

I have found this script on the mta wiki, and will edit it that it will work on my server with the stats saver.

I made this:

function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function changePedStats(thePlayer, _, name) 
   local plr = getPlayerFromPartialName(name) 
   if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end 
   local stat = setPedStat(plr, 75, 1000) 
   if (stat) then 
        outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) 
    end 
end 
addCommandHandler("givestats", changePedStats, true) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local pedStats = getPedStat(source) 
            setAccountData(playerAccount, "zi.pedstats", pedStats) 
      end 
end 
addEventHandler("onPlayerQuit", getRootElement(), onPlayerQuit) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local pedStats = getAccountData(playerAccount, "zi.pedstats") 
            if (pedStats) then 
                  setPedStats(source, pedStats) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Right now I'm actually a noob in scripting, so don't expect too much. I'm learning it. The script above, do you think this will work?

Marty

Edited by Guest
Link to comment
function getPlayerFromPartialName(name) 
    local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil 
    if name then 
        for _, player in ipairs(getElementsByType("player")) do 
            local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() 
            if name_:find(name, 1, true) then 
                return player 
            end 
        end 
    end 
end 
  
function changePedStats(thePlayer, _, name) 
   local plr = getPlayerFromPartialName(name) 
   if (not plr) then outputChatBox("There is no player with this name", thePlayer) return end 
   local stat = setPedStat(plr, 75, 1000) 
   if (stat) then 
        outputChatBox("Congratulations! You have given "..getPlayerName(plr).." dual UZIs!", thePlayer) 
    end 
end 
addCommandHandler("givestats", changePedStats, true) 
  
function onPlayerQuit() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local pedStats = getPedStat(source, 75) 
            setAccountData(playerAccount, "zi.pedstats", pedStats) 
      end 
end 
addEventHandler("onPlayerQuit", root, onPlayerQuit) 
addEventHandler("onPlayerWasted", root, onPlayerQuit) 
  
function onPlayerLogin() 
      local playerAccount = getPlayerAccount(source) 
      if (playerAccount) then 
            local pedStats = getAccountData(playerAccount, "zi.pedstats") 
            if (pedStats) then 
                  setPedStat(source, 75, pedStats) 
            end 
      end 
end 
addEventHandler("onPlayerLogin", getRootElement(), onPlayerLogin) 

Give this a go.

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