Jump to content

[HELP] Simple Error


Recommended Posts

Posted

Hi, i forgot how to use triggerClientEvent and triggerServerEvent

I've read the wiki 2 times, But it didnt worked.

Heres my code:

[sERVER SIDE]

  
addEvent("giveM4", true)   
function giveMeM4(client)   
if getPlayerMoney (client) >= 1400 then 
giveWeapon(client, 31, 100) 
takePlayerMoney(client, 1400) 
-- outputChatBox("Ka ching!", client, 0, 255, 0) -- TEST MESSAGE 
triggerClientEvent (thePlayer, "onEnoughMoney", getLocalPlayer()) 
else 
local thePlayer = getPlayerFromName ( client ) 
outputChatBox("You dont have enough money!", client, 255, 0, 0) 
triggerClientEvent (thePlayer, "onNotEnoughMoney", getPlayerFromName(client)) 
end 
end 
addEventHandler ( "giveM4", getRootElement(), giveMeM4 ) 
  

[CLIENT SIDE]

  
wepcol = createColCuboid ( 1495.6212158203, -3100.0891113281, 87.07982635498, 2, 5, 2 ) 
root = getRootElement() 
  
 function render() 
  dxDrawText("Press O to buy M4 [Cost: 1400]",329.0,412.0,482.0,425.0,tocolor(255,200,0,255),0.9,"default-bold","left","top",false,false,false) 
 end 
  
function enter() 
 addEventHandler("onClientRender", root, render) 
 bindKey( "O", "down", m4) 
-- outputChatBox("O BINDED", root, 255, 0, 0) 
end 
addEventHandler("onClientColShapeHit", wepcol, enter) 
  
function leave() 
   removeEventHandler("onClientRender", root, render) 
   unbindKey( "O", "down", m4) 
--   outputChatBox("O UNBINDED", root, 255, 0, 0) -- TEST MESSAGE 
end 
addEventHandler("onClientColShapeLeave", wepcol, leave) 
  
  
function m4(theElement, matchingDimension) 
 triggerServerEvent( "giveM4", getLocalPlayer(),getLocalPlayer()) 
end 
  
local soundsTable = {} 
 soundsTable[1] = "nocash1.mp3" 
 soundsTable[2] = "nocash2.mp3" 
 soundsTable[3] = "nocash3.mp3" 
  
function playThaSound() 
 local rand = math.random ( 1, #soundsTable ) 
 playSound ( soundsTable[rand], false ) 
 setSoundVolume(sounds, 0.9) 
end 
addEvent( "onNotEnoughMoney", true ) 
addEventHandler( "onNotEnoughMoney", getRootElement(), playThaSound ) 
  
  
local soundsTable = {} 
 soundsTable[1] = "buyedgun1.mp3" 
 soundsTable[2] = "buyedgun2.mp3" 
 soundsTable[3] = "buyedgun3.mp3" 
 soundsTable[4] = "buyedgun4.mp3" 
 soundsTable[5] = "buyedgun5.mp3" 
  
function playThaBuySound() 
 local rand = math.random ( 1, #soundsTable ) 
 playSound ( soundsTable[rand], false ) 
 setSoundVolume(sounds, 0.9) 
end 
addEvent( "onEnoughMoney", true ) 
addEventHandler( "onEnoughMoney", getRootElement(), playThaBuySound ) 

The error(s):

  
[15:15:25] WARNING: weaponbuy\server.lua:9: Bad argument @ 'getPlayerFromName' 
[15:15:25] WARNING: weaponbuy\server.lua:11: Bad argument @ 'getPlayerFromName' 
[15:15:25] WARNING: weaponbuy\server.lua:11: Bad argument @ 'triggerClientEvent' 

Regards,

Jesseunit

Posted

You have too obiously errors...

addEvent("giveM4", true) 
function giveMeM4(client)   
if getPlayerMoney (client) >= 1400 then 
giveWeapon(client, 31, 100) 
takePlayerMoney(client, 1400) 
-- outputChatBox("Ka ching!", client, 0, 255, 0) -- TEST MESSAGE 
triggerClientEvent (client, "onEnoughMoney", client) -- getLocalPlayer() is only CLIENT SIDE 
else 
outputChatBox("You dont have enough money!", client, 255, 0, 0) 
triggerClientEvent (client, "onNotEnoughMoney", client) 
end 
end 
addEventHandler ( "giveM4", getRootElement(), giveMeM4 ) 

Seriously, take some REAL time to read the wiki.

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