Jump to content

[HELP] What wrong in this pay script??


Turbe$Z

Recommended Posts

This is the code:

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
    else
    return false
    end
end

function payScript(player,cmd,other,amount)     
   local name = getPlayerFromPartialName(other)
   local atg
   local rpm = getPlayerMoney(player)
   local err = {}

   local penz = getElementData(player,"char:money") or 0
    
   if name == false then
   err[#err+1] = "#FFffFFA név nem található!"
   end
   
   if tonumber(amount) < 0 then
   err[#err+1] = "#FFffFFNegatív szám nem lehet!"
   end
 
   atg = tonumber(amount)
   
   if (penz-atg) < 0 then
   err[#err+1] = "#FFffFFNincs elég pénzed!"
   end
   
   if(player == name) then
   err[#err+1] = "# nem tudsz."
   end
   
   if #err == 0 then
   setElementData(player,"char:money",penz-atg)
   setElementData(name,"char:money",atg+penz)
   else
   for i=1,#err do 

   end
   end
   
end
addCommandHandler( "pay", payScript ) 

the other and the local player's money changes to the same... how to fix this??

Edited by Turbe$Z
Link to comment
18 hours ago, Shux said:

You're setting the target's amount of money to the player's (who's using the command) money + amount. You should set the target's money to the money that he has + amount. Therefore..

Add:


local penz2 = getElementData(name,"char:money") or 0

And change:
 


setElementData(name,"char:money",atg+penz)

To


setElementData(name,"char:money",atg+penz2)

 

Other player get the money twice, for example i type "/pay xy 3000", the player get 6000 money o.O Why??

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