Jump to content

[ERROR]givePlayerMoney


Recommended Posts

Hello Again Guys, I am learning scripting and i got a problem Really i tried everything i want is when a player buy that the player that is selling get Money i did givePlayerMoney but it didn't work.

Server:

function consoleCreateMarker ( thePlayer, commandName ) 
   if ( thePlayer ) then 
    if getElementModel( thePlayer ) == 28 then  
      local x, y, z = getElementPosition ( thePlayer ) 
      theMarker = createMarker ( x + 0, y + 0, z - 1, "cylinder", 1.5, 255, 0, 0, 170 ) 
      setElementFrozen ( thePlayer, true ) 
          if ( theMarker ) then 
         outputConsole ( "Marker created successfully", thePlayer ) 
      else 
         outputConsole ( "Failed to create marker", thePlayer ) 
      end 
    end 
   end 
end 
addCommandHandler ( "sell", consoleCreateMarker ) 
  
function unfreeze( thePlayer, commandName ) 
  setElementFrozen ( thePlayer, false ) 
  destroyElement ( theMarker ) 
end 
  addCommandHandler ( "stopsell", unfreeze ) 
   
--------------------------------------------------------------------------------------------------------------------------------------  
function comprarr ( hitElement1 ) 
    destroyElement ( theMarker ) 
end 
addEvent( "onGreeting", true ) 
addEventHandler( "onGreeting", root, comprarr ) 
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function cerrarr ( hitElement1 ) 
   destroyElement ( theMarker ) 
end 
addEvent( "onGreetinA", true ) 
addEventHandler( "onGreetinA", root, cerrarr ) 
  
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function arma11 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 2000 )  
   givePlayerMoney ( thePlayer, 1700 ) 
   giveWeapon ( source, 31, 100 ) 
end 
end 
addEvent( "onGreetinB", true ) 
addEventHandler( "onGreetinB", root, arma11 ) 
  
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function arma22 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 2000 ) 
   givePlayerMoney ( thePlayer, 1700 ) 
   giveWeapon ( source, 30, 100 ) 
end 
end 
addEvent( "onGreetinC", true ) 
addEventHandler( "onGreetinC", root, arma22 ) 
  
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function granadaa ( hitElement1 ) 
if ( getPlayerMoney(source) >= 500 ) then   
   takePlayerMoney ( source, 500 ) 
   giveWeapon ( source, 16, 1 ) 
end 
end 
addEvent( "onGreetinD", true ) 
addEventHandler( "onGreetinD", root, granadaa ) 
  
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function arma44 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 1000 ) then 
   takePlayerMoney ( source, 1000 ) 
   giveWeapon ( source, 27, 50 ) 
end 
end 
addEvent( "onGreetinE", true ) 
addEventHandler( "onGreetinE", root, arma44 ) 
  
--------------------------------------------------------------------------------------------------------------------------------------- 
  
function arma55( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 4000 ) 
   giveWeapon ( source, 34, 50 ) 
end 
end 
addEvent( "onGreetinF", true ) 
addEventHandler( "onGreetinF", root, arma55 ) 
--------------------------------------------------------------------------------------------------------------------------------------- 

Link to comment

just replace lines 51-59 with this

function arma22 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 2000 ) 
   givePlayerMoney ( source, 1700 ) 
   giveWeapon ( source, 30, 100 ) 
end 
end 
addEvent( "onGreetinC", true ) 
addEventHandler( "onGreetinC", root, arma22 ) 

Link to comment
  • Moderators
just replace lines 51-59 with this
function arma22 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 2000 ) 
   givePlayerMoney ( source, 1700 ) 
   giveWeapon ( source, 30, 100 ) 
end 
end 
addEvent( "onGreetinC", true ) 
addEventHandler( "onGreetinC", root, arma22 ) 

Not complete there is one at line 42 too.

gghvc: replace thePlayer by source on line 42:

givePlayerMoney ( thePlayer, 1700 ) 

and 54:

givePlayerMoney ( thePlayer, 1700 ) 

and stop copying and pasting without knowing what you are actually doing.

Link to comment

Use "client" instead of "source" in those functions that passes a player from the client script to the server script by triggerServerEvent.

Lines: 24, 31, 39, 51, 63, 74, 85.

Otherwise you will get some issues as soon there are more than 1 players online in your server and someone uses this feature since source may point at the wrong player.

Link to comment
  • Moderators
Use "client" instead of "source" in those functions that passes a player from the client script to the server script by triggerServerEvent.

Lines: 24, 31, 39, 51, 63, 74, 85.

Otherwise you will get some issues as soon there are more than 1 players online in your server and someone uses this feature since source may point at the wrong player.

You are right and wrong at the same time. You are right about using client instead of source but the reason for doing that isn't right.

Source will always be the element you were waiting for, it won't randomly be another player element. But a not nice player can modify his client (the mta's source code) to fake/replace the source argument.

So the hacker can says to the server: "Hey, I'm playing this guy (which can be an admin)" and if the server uses source then he will think that he received that event from that guy (the admin).

So source can not be trusted instead of client (resolved by the server itself so it can be trusted).

Link to comment
just replace lines 51-59 with this
function arma22 ( hitElement1 ) 
if ( getPlayerMoney(source) >= 2000 ) then 
   takePlayerMoney ( source, 2000 ) 
   givePlayerMoney ( source, 1700 ) 
   giveWeapon ( source, 30, 100 ) 
end 
end 
addEvent( "onGreetinC", true ) 
addEventHandler( "onGreetinC", root, arma22 ) 

Not complete there is one at line 42 too.

gghvc: replace thePlayer by source on line 42:

givePlayerMoney ( thePlayer, 1700 ) 

and 54:

givePlayerMoney ( thePlayer, 1700 ) 

and stop copying and pasting without knowing what you are actually doing.

Sorry i just find a line of the bug and solve it My Mistake that i wasen't see and others. Also it Bad Coded you can reduse lot of lines there

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