Jump to content

Have a problem with give weapon script


Recommended Posts

Can somoene explain what's the problem? :shock:

local player = getLocalPlayer 
function buyweapon (player,command) 
takePlayerMoney ( player, 2000 ) 
        if true then outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", getRootElement(), 255, 255, 255, true ) 
        giveWeapon ( player, 31, 200 ) 
  end 
        else if false then outputChatBox ( "#00FF00You Don't Have Enough Money!", getRootElement(), 255, 255, 255, true ) 
    end 
addCommandHandler ( "buym4", buyweapon ) 

Link to comment
addEventHandler('onPlayerCommand', root, 
function (cmd) 
    if (cmd == 'buym4' ) then 
    if(getPlayerMoney(source) >=2000 ) then 
    takePlayerMoney(source, 2000) 
    giveWeapon(source, 31, 200 ) 
     outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", source, 255, 255, 0) 
     else 
      outputChatBox ( "#00FF00You Don't Have Enough Money!", source, 255, 255, 0) 
  end 
  end 
end 
) 

Link to comment

function buyweapon (player) 
            if getPlayerMoney(player) >= 2000 then 
        takePlayerMoney ( player, 2000 ) 
            outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!",player, 255, 255, 255, true ) 
        giveWeapon ( player, 31, 200 ) 
      else  
                outputChatBox ( "#00FF00You Don't Have Enough Money!",player, 255, 255, 255, true ) 
            end 
    end 
addCommandHandler ( "buym4", buyweapon ) 
Link to comment
Thank you Mr.Pres[T]ege Verry Much! :D

Have you learned something from it? Cause this is kinda... first day of programming that people are learning you that this wont work;

 if true then 

What has to be true, what is true? Whats going on? O_O

A true/false is a returned bool value. So if you got a function that returns a boolean you can get 2 things back; True or False. So lets make a little script with it;

local pedInVehicle = isPedInVehicle(source); 
if (pedInVehicle) then -- if its true 
   outputChatBox("In a car!", source); 
else 
   outputChatBox("FALSE!, aint in a car brotha!", source); 
end 

Get it?:) (aint trying to be a btch or so, just want people to learn from their mistakes cause of my mistakes, I gained alot of knowledge)

Edited by Guest
Link to comment

Try this:

local player = getLocalPlayer 
function buyweapon (player,command) 
    if (getPlayerMoney(player) > 1999) then  -- 1999 will acculy be 200 
        outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", 255, 255, 255, true ) 
        giveWeapon ( player, 31, 200 ) 
        takePlayerMoney ( player, 2000 ) 
    else 
        outputChatBox ( "#00FF00You Don't Have Enough Money!", 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "buym4", buyweapon ) 

Link to comment
Try this:
local player = getLocalPlayer 
function buyweapon (player,command) 
    if (getPlayerMoney(player) > 1999) then  -- 1999 will acculy be 200 
        outputChatBox ( "#00FF00Congratulations You Buyed M4 for 2000!", 255, 255, 255, true ) 
        giveWeapon ( player, 31, 200 ) 
        takePlayerMoney ( player, 2000 ) 
    else 
        outputChatBox ( "#00FF00You Don't Have Enough Money!", 255, 255, 255, true ) 
    end 
end 
addCommandHandler ( "buym4", buyweapon ) 

The problem solved in the first page but i have a question why you use localPlayer server side?

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