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 ) 

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

Posted

That script doesn't make any sense.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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.

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

Posted

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

You need the following functions:

addCommandHandler 
getPlayerMoney 
takePlayerMoney 
giveWeapon 
outputChatBox 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

So what to write ??because i don't know what other to write with those "If" functions

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

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 
) 

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

Posted

That's wrong Max, he should use addCommandHandler.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Why it's worng ?

- New , Kill System

- New, GameMode Intro

- Leve / Exp System

- New nametag showing style

- New , Hud For Players

- Skin Selection from SA-MP

- Money System / Buy Weapons

- Drop Weapons

- New, Flood System

- New , Group Assign

- Gun license For Weapons

- Random Rule System For Money

  • Moderators
Posted

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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

Thank you Mr.Pres[T]ege Verry Much! :D

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

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

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

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?

  

Posted

Eh guys i don't need those if and then tutorials i already readed some in lua and tested on lua demo and then i tried on mta lua :D

  • "Lua" means "Moon" in Portuguese. More specifically, "Lua" is a name, the name of the Earth's moon and the name of the language. Like most names, it should be written in lower case with an initial capital, that is, "Lua". Please do not write it as "LUA", which is both ugly and confusing, because then it becomes an acronym with different meanings for different people. So, please, write "Lua" right!

- http://www.lua.org/about.html

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