Jump to content

Have a problem with give weapon script


Recommended Posts

Posted

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 ) 

Posted

I wanted to make a simple test script where you write buym4 and if you have enough money it gives you weapon and writes on chat box and if you don't have enough money it only writes that you don't have enough money.

Posted

Well, what you did doesn't make any sense.

You need the following functions:

addCommandHandler 
getPlayerMoney 
takePlayerMoney 
giveWeapon 
outputChatBox 

Posted
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 
) 

Posted

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 ) 
Posted (edited)
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
Posted

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 ) 

Posted
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?

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