Jump to content

Cafe System


Recommended Posts

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    setElementData(getLocalPlayer(),"all","0") 
    setElementData(getLocalPlayer(),"tea","0") 
    setElementData(getLocalPlayer(),"water","0") 
    end 
addEventHandler ( "onResourceStart", getRootElement(), ResourceStart ) 
  
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", source, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end 
addEventHandler( "onMarkerHit", marker, MarkerHit ) 
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end 
  
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Its server-side. It doesn't works can you help?

Edited by Guest
Link to comment

1. use [lua.][/lua] tags.

2. tell us what's the problem dont just say "it doesn't work".

 

Its server-side. It doesn't works can you help?

How it's server side when you have

    setElementData(getLocalPlayer(),"all","0") 
    setElementData(getLocalPlayer(),"tea","0") 
    setElementData(getLocalPlayer(),"water","0") 
  

getLocalPlayer() is a client side function,

you should do:

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
    end 
end 
addEventHandler ( "onResourceStart", getRootElement(), ResourceStart ) 

Edited by Guest
Link to comment

See my post again , nvm.

here it is:

Its server-side. It doesn't works can you help?

How it's server side when you have

    setElementData(getLocalPlayer(),"all","0") 
    setElementData(getLocalPlayer(),"tea","0") 
    setElementData(getLocalPlayer(),"water","0") 
  

getLocalPlayer() is a client side function,

you should do:

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
    end 
end 
addEventHandler ( "onResourceStart", getRootElement(), ResourceStart ) 

Also you got getRootElement() in onResourceStart in this way it will trigger it on any resource start should be:

addEventHandler ( "onResourceStart", resourceRoot, ResourceStart ) 

Link to comment
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", source, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 

You are talking to the marker :)

function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 

Link to comment

do this:

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
    end 
      addEventHandler( "onMarkerHit", marker, MarkerHit ) 
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
    end 
addEventHandler ( "onResourceStart", getRootElement(), ResourceStart ) 
  
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end 
end 
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end 
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Link to comment
addEventHandler('onMarkerHit',getRootElement(), 
     function( hitElement, matchingDimension )   
if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", source, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", source, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
  end                                  
end) 

Edited by Guest
Link to comment

volk :),

look at your code again source instead of hitElement and that's not the problem,

he had a bad arguments at the event handlers,

this should work:

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
    end 
      addEventHandler( "onMarkerHit", marker, MarkerHit ) 
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
    end 
addEventHandler ( "onResourceStart", resourceRoot, ResourceStart ) 
  
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end 
end 
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end 
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Link to comment

I use mobile phone dude :) full code

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
    end 
    end 
addEventHandler ( "onResourceStart", resourceRoot, ResourceStart )              
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end          addEventHandler( "onMarkerHit", marker, MarkerHit ) 
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end   addEventHandler( "onMarkerLeave", marker, markerLeave ) 
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Link to comment

Wont work because it will give warnings at the 2 addEventHandlers for markers they must be put inside the onResourceStart function.

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
addEventHandler( "onMarkerHit", marker, MarkerHit ) 
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
    end 
    end 
addEventHandler ( "onResourceStart", resourceRoot, ResourceStart )             
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end           
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end    
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Link to comment
function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
addEventHandler( "onMarkerHit", marker, MarkerHit ) 
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
    end 
    end 
addEventHandler ( "onResourceStart", resourceRoot, ResourceStart )             
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end           
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end   
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..raki.."water"..bira.."tea]", 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Next time use the debugscript to search for errors, you had an error.

Error was: attempt to concatenate global 'tea' (a function value)

Link to comment

Also you made a mistake at outputChatBox

here:

outputChatBox( getPlayerName( thePlayer).."drunk tea.", 255, 255, 0 ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", 255, 255, 0 ) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", 255, 255, 0 ) 

Should be

outputChatBox( getPlayerName( thePlayer).."drunk tea.", root, 255, 255, 0 ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", root, 255, 255, 0 ) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..water.."water"..tea.."tea]", root, 255, 255, 0 ) 

Link to comment

Castillo's one is not working because you had a mistake in the outputChatBox but i fixed it in mine so it should work.

here:

function ResourceStart() 
    marker = createMarker ( 1449.3040771484, -2937.9020996094, 2.9447371959686, "cylinder", 1, 255, 255, 0) 
    for i, v in ipairs(getElementsByType('player')) do 
    setElementData(v,"all","0") 
    setElementData(v,"tea","0") 
    setElementData(v,"water","0") 
addEventHandler( "onMarkerHit", marker, MarkerHit ) 
addEventHandler( "onMarkerLeave", marker, markerLeave ) 
    end 
    end 
addEventHandler ( "onResourceStart", resourceRoot, ResourceStart )             
function MarkerHit( hitElement, matchingDimension ) 
        if getElementType( hitElement ) == "player" then 
          outputChatBox( "You are now in my cafe.", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink water use /water .", hitElement, 255, 255, 0 ) 
          outputChatBox( "If you want drink tea use /tea .", hitElement, 255, 255, 0 ) 
      addCommandHandler ( "water", water ) 
      addCommandHandler ( "tea", tea ) 
end 
end           
  
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( thePlayer).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end   
  
function water ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk water.", root, 255, 255, 0 ) 
setElementData ( thePlayer ,"water",tostring(tonumber(getElementData(thePlayer,"water"))+1)) 
end 
  
function tea ( thePlayer, command ) 
outputChatBox( getPlayerName( thePlayer).."drunk tea.", root, 255, 255, 0 ) 
setElementData ( thePlayer ,"tea",tostring(tonumber(getElementData(thePlayer,"tea"))+1)) 
end 
  
function all ( thePlayer, command ) 
local bira = tostring(tonumber(getElementData(thePlayer,"tea"))) 
local raki = tostring(tonumber(getElementData(thePlayer,"water"))) 
local toplam = tostring(tonumber(getElementData(thePlayer,"tea"))) + tostring(tonumber(getElementData(thePlayer,"water"))) 
outputChatBox( getPlayerName( thePlayer).."drunks"..toplam..".["..raki.."water"..bira.."tea]", root, 255, 255, 0 ) 
end 
addCommandHandler ( "all", all ) 

Link to comment
function markerLeave( leaveElement, matchingDimension ) 
        if getElementType( leaveElement ) == "player" then 
          outputChatBox ( getPlayerName( leaveElement).."has left the cafe.", getRootElement(), 255, 255, 0 ) 
          removeCommandHandler ("water", water) 
          removeCommandHandler ("tea", tea) 
        end 
end 

And please do /debugscript 3 ingame you will figure out the problems yourself.

Link to comment

it will show ur script erros. Try, go in game, login with admin account, and write to chatbox /debugscript 3

Now you can see a small window down your screen, There will come errors, like to console ( black window, deffault ) but debugscript can show you errors what console cant.

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