Jump to content

[HELP] Weapon problem


Recommended Posts

Hi , i wanted to make a script that gives to the player an RPG when he types /rpg and he will loose 6000$.

idk why it doesn't wprk , anyways , here's my code.

Client-Side.

function consoleGive ( thePlayer, rpg, 35, 1 ) 
    local status = giveWeapon ( thePlayer, 35, 1, true )   -- attempt to give the weapon, forcing it as selected weapon 
    if ( not status ) then                                          -- if it was unsuccessful 
        outputConsole ( "Failed to give weapon.", thePlayer )   -- tell the player 
    end 
end 
addCommandHandler ( "rpg", consoleGive ) 

Server-Side.

function payme() 
takePlayerMoney (6000 ,player) 
end 
addEventHandler ("OnPlayerCommand", player) 

Any help wuld be welcomed.

Link to comment

-- # Server Side 
function consoleGive ( thePlayer )   
    if getPlayerMoney ( thePlayer ) >= 6000 then 
        takePlayerMoney ( thePlayer,6000 ) 
        giveWeapon ( thePlayer, 35, 1, true )    
  else                                   
       outputChatBox(" You don't have money",thePlayer) 
    end 
end 
addCommandHandler ( "rpg", consoleGive ) 

Not tested yet .

Link to comment

Ok , /debugscript 3 don't tell me any error anyways here are my server/client side codes.

Serverside.

  
function consoleGive ( thePlayer )  
    if getPlayerMoney ( thePlayer ) >= 6000 then 
        takePlayerMoney ( thePlayer,6000 ) 
    if not  getPlayerMoney ( thePlayer ) >= 6000 then 
        outputChatBox ("You do not have enough money!") 
        giveWeapon ( thePlayer, 35, 1, true )   
  else                                   
       outputChatBox(" You don't have money",thePlayer) 
    end 
end 
addCommandHandler ( "rpg", consoleGive ) 

And the Clientside

function consoleGive ( thePlayer, rpg, 35, 1 ) 
    local status = giveWeapon ( thePlayer, 35, 1, true )   
    if ( not status ) then                                          
        outputConsole ( "Failed to give weapon.", thePlayer )    
    end 
end 
addCommandHandler ( "rpg", consoleGive ) 

Link to comment

giveWeapon function server side only any way try this server side :

function consoleGive ( thePlayer )  
    if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then 
        outputChatBox ("You do not have enough money!") return end 
        giveWeapon ( thePlayer, 35, 1, true )   
        takePlayerMoney ( thePlayer,6000 ) 
end 
addCommandHandler ( "rpg", consoleGive ) 
Link to comment
giveWeapon function server side only any way try this server side :

function consoleGive ( thePlayer )  
    if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then 
        outputChatBox ("You do not have enough money!") return end 
        giveWeapon ( thePlayer, 35, 1, true )   
        takePlayerMoney ( thePlayer,6000 ) 
end 
addCommandHandler ( "rpg", consoleGive ) 

There's no need to convert a number to a number.

Link to comment
giveWeapon function server side only any way try this server side :

function consoleGive ( thePlayer )  
    if getPlayerMoney ( thePlayer ) < tonumber( 6000 ) then 
        outputChatBox ("You do not have enough money!") return end 
        giveWeapon ( thePlayer, 35, 1, true )   
        takePlayerMoney ( thePlayer,6000 ) 
end 
addCommandHandler ( "rpg", consoleGive ) 

There's no need to convert a number to a number.

But why some times i get a error something say attempt to something to string a number ? And when i use tonumber every thing fine ?

Link to comment

It's obviously with a different script, since with that one is not required.

addCommandHandler ( "money", 
    function ( thePlayer, _, amount ) 
        if ( getPlayerMoney ( thePlayer ) >= amount ) then -- Here it'll cause an error because 'amount' is a string and not a number. 
            takePlayerMoney ( thePlayer, amount ) 
        end 
    end 
) 

Read the comment, there you must use tonumber to convert 'amount' which is a string to a number.

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