Jump to content

givePlayerMoney


DRW

Recommended Posts

Posted

Hello, I'm making a kind of script that gives you a random weapon with random ammo and reproduces a sound (Like in Black Ops Zombies, but I'm still working with the GUI.

Alright, the problem is that I created a button that detects if you have less money than 8000 and says you don't have enough and cancels the event, that works, but when you have enough, you are supposed to lose 8000, but you don't, actually it does nothing.

Client:

rRoot = getResourceRootElement(getThisResource()) 
  
function cerrarmystery () 
guiSetVisible(mystery,false) 
showCursor (false) 
end 
  
function abrirmystery () 
guiSetVisible (mystery, true) 
showCursor (true) 
end 
  
function mysterymoney (thePlayer) 
local money = getPlayerMoney(thePlayer) 
if (money < 8000) then cancelEvent () 
if (money < 8000) then outputChatBox ("NO TIENES SUFICIENTE DINERO") 
else  
givePlayerMoney (-8000) 
end 
end 
end 
  
addEvent ("cajamisterio", true) 
addEventHandler ("cajamisterio", localPlayer, abrirmystery) 
  
addEventHandler ("onClientResourceStart", rRoot,cerrarmystery) 
  
local screenW, screenH = guiGetScreenSize() 
mystery = guiCreateWindow((screenW - 699) / 2, (screenH - 152) / 2, 699, 152, "CAJA MISTERIOSA", false) 
guiWindowSetSizable(mystery, false) 
  
mysterylabel = guiCreateLabel(55, 23, 592, 46, "¿Quieres comprar la caja aleatoria?", false, mystery) 
guiSetFont(mysterylabel, "sa-header") 
mysterybutton1 = guiCreateButton(460, 81, 187, 48, "NO.", false, mystery) 
guiSetFont(mysterybutton1, "default-bold-small") 
guiSetProperty(mysterybutton1, "NormalTextColour", "FFFF0000") 
mysterybutton2 = guiCreateButton(55, 81, 187, 48, "SÍ (8.000$)", false, mystery) 
guiSetFont(mysterybutton2, "default-bold-small") 
guiSetProperty(mysterybutton2, "NormalTextColour", "FF84FF00") 
  
addEventHandler ("onClientGUIClick", mysterybutton1, cerrarmystery, false) 
addEventHandler ("onClientGUIClick", mysterybutton2, mysterymoney, false) 

Posted

You have to set money serverside. Client side won't work. Like that

setPlayerMoney ( player, getPlayerMoney ( player ) - amount ) 

Posted

Tried clientside, not working.

Tried serverside, not working.

Client

function mysterymoney (thePlayer) 
local money = getPlayerMoney(thePlayer) 
if (money < 8000) then cancelEvent () 
if (money < 8000) then outputChatBox ("NO TIENES SUFICIENTE DINERO") 
else  
triggerServerEvent ("quitardinero",thePlayer) 
end 
end 
end 

Server

function fueradinero (player) 
takePlayerMoney (player, 8000 ) 
end 
  
addEvent ("quitardinero",true) 
addEventHandler ("quitardinero", fueradinero) 

Posted
Remove player from function's argument and use source instead.
function fueradinero () 
takePlayerMoney (source, 8000 ) 
end 

Still not working, also, nothing in debugscript.

Posted
function mysterymoney (thePlayer) 
local money = getPlayerMoney(thePlayer) 
if (money < 8000) then 
 outputChatBox ("NO TIENES SUFICIENTE DINERO") 
return 
else  
triggerServerEvent ("quitardinero",thePlayer) 
end 
end 
  

Posted
Also add 'root' to event s-side, because as far as I can see you've forgotten about it.
function fueradinero () 
takePlayerMoney (source, 8000 ) 
end 
  
addEvent ("quitardinero",true) 
addEventHandler ("quitardinero", root, fueradinero 

Like this? It's not working...

Posted
1.function mysterymoney () 
2.local money = getPlayerMoney() 
3.if (money < 8000) then 
4. outputChatBox ("NO TIENES SUFICIENTE DINERO") 
5.return 
6.else  
7.triggerServerEvent ("quitardinero",localPlayer) 
8.end 
9.end 
10.  
  

If doesn't work check debugscript.

Posted
1.function mysterymoney () 
2.local money = getPlayerMoney() 
3.if (money < 8000) then 
4. outputChatBox ("NO TIENES SUFICIENTE DINERO") 
5.return 
6.else  
7.triggerServerEvent ("quitardinero",localPlayer) 
8.end 
9.end 
10.  
  

If doesn't work check debugscript.

FINALLY, THANK YOU VERY MUCH!

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