Jump to content

My frist script


Recommended Posts

i am creating my first script and i got a problem i scripted a gui appears when i hit the marker and its appear and scripted the exit button and it hide the gui but when i hit the marker again it doesn't appear again unless i restart the resource .....Help please

Link to comment
i am creating my first script and i got a problem i scripted a gui appears when i hit the marker and its appear and scripted the exit button and it hide the gui but when i hit the marker again it doesn't appear again unless i restart the resource .....Help please

Could you either, post your code here, or PM it to me!

Link to comment
function gui () 
            gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
            guiSetInputEnabled ( false ) 
            guiWindowSetMovable( gui, false ) 
            guiWindowSetSizable( gui, false ) 
            List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
            column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
                btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
                guiSetFont( btn1, "default-bold-small" )         
        List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
        column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
        btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
        guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
        guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
        row = guiGridListAddRow (List) 
    guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
      row2 = guiGridListAddRow (List) 
      guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
       row3 = guiGridListAddRow (List) 
       guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
     
         
    addEventHandler("onClientGUIClick", btn1, close, false) 
    addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
  
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( thePlayer, amount )      
     takePlayerMoney ( thePlayer, 100 )  
end 
end 
  
           
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
  
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
        gui() 
    if ( hitPlayer == localPlayer ) then 
        guiSetVisible( gui, true) 
        showCursor( true) 
        outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
    end 
end ) 
  
   function close(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible ( lol, false) 
        guiSetInputEnabled(false) 
        guiSetVisible(gui, false) 
        showCursor(false) 
    end 
end 
  

Link to comment
function gui () 
gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
guiSetInputEnabled ( false ) 
guiWindowSetMovable( gui, false ) 
guiWindowSetSizable( gui, false ) 
guiSetVisible ( gui, false) 
List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
guiSetFont( btn1, "default-bold-small" ) 
List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
row = guiGridListAddRow (List) 
guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
row2 = guiGridListAddRow (List) 
guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
row3 = guiGridListAddRow (List) 
guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
  
  
addEventHandler("onClientGUIClick", btn1, close, false) 
addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
  
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( thePlayer, amount ) 
takePlayerMoney ( thePlayer, 100 ) 
end 
end 
  
  
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
  
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
gui() 
if ( hitPlayer == localPlayer ) then 
guiSetVisible( gui, true) 
showCursor( true) 
outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
end 
end ) 
  
function close(button,state) 
if button == "left" and state == "up" then 
guiSetVisible ( lol, false) 
guiSetInputEnabled(false) 
guiSetVisible(gui, false) 
showCursor(false) 
end 
end 

Should work now (I added guiSetVisible in line 5)

Link to comment
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
function gui () 
gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
guiSetInputEnabled ( false ) 
guiWindowSetMovable( gui, false ) 
guiWindowSetSizable( gui, false ) 
guiSetVisible ( gui, false) 
List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
guiSetFont( btn1, "default-bold-small" ) 
List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
row = guiGridListAddRow (List) 
guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
row2 = guiGridListAddRow (List) 
guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
row3 = guiGridListAddRow (List) 
guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
  
  
addEventHandler("onClientGUIClick", btn1, close, false) 
addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
  
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( thePlayer, amount ) 
takePlayerMoney ( thePlayer, 100 ) 
end 
end 
   
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
gui() 
if ( hitPlayer == localPlayer ) then 
guiSetVisible( gui, true) 
showCursor( true) 
outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
end 
end ) 
  
function close(button,state) 
if button == "left" and state == "up" then 
guiSetVisible ( lol, false) 
guiSetInputEnabled(false) 
guiSetVisible(gui, false) 
showCursor(false) 
end 
end 

Try this..

Link to comment
  • Moderators
still appears one time........

Try this:

function gui () 
            gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
            guiSetInputEnabled ( false ) 
            guiSetVisible(gui, false) 
            guiWindowSetMovable( gui, false ) 
            guiWindowSetSizable( gui, false ) 
            List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
            column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
                btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
                guiSetFont( btn1, "default-bold-small" )        
        List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
        column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
        btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
        guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
        guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
        row = guiGridListAddRow (List) 
    guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
      row2 = guiGridListAddRow (List) 
      guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
       row3 = guiGridListAddRow (List) 
       guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
    
        
    addEventHandler("onClientGUIClick", btn1, close, false) 
    addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
  
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( thePlayer, amount )     
     takePlayerMoney ( thePlayer, 100 ) 
end 
end 
  
          
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
  
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
    if ( hitPlayer == localPlayer ) then 
        guiSetVisible( gui, true) 
        showCursor( true) 
        outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
    end 
end ) 
  
   function close(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible ( lol, false) 
        guiSetInputEnabled(false) 
        guiSetVisible(gui, false) 
        showCursor(false) 
    end 
end 
  

Link to comment
still appears one time........

Try this:

function gui () 
            gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
            guiSetInputEnabled ( false ) 
            guiSetVisible(gui, false) 
            guiWindowSetMovable( gui, false ) 
            guiWindowSetSizable( gui, false ) 
            List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
            column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
                btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
                guiSetFont( btn1, "default-bold-small" )        
        List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
        column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
        btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
        guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
        guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
        row = guiGridListAddRow (List) 
    guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
      row2 = guiGridListAddRow (List) 
      guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
       row3 = guiGridListAddRow (List) 
       guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
    
        
    addEventHandler("onClientGUIClick", btn1, close, false) 
    addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
  
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( thePlayer, amount )     
     takePlayerMoney ( thePlayer, 100 ) 
end 
end 
  
          
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
  
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
    if ( hitPlayer == localPlayer ) then 
        guiSetVisible( gui, true) 
        showCursor( true) 
        outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
    end 
end ) 
  
   function close(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible ( lol, false) 
        guiSetInputEnabled(false) 
        guiSetVisible(gui, false) 
        showCursor(false) 
    end 
end 
  

this time the cursor appears only...

Link to comment
  • Moderators
function createGui () 
            gui = guiCreateWindow( 300, 100, 265, 500, "Bike Rent Shop", false) 
            guiSetInputEnabled ( false ) 
            guiSetVisible(gui, false) 
            guiWindowSetMovable( gui, false ) 
            guiWindowSetSizable( gui, false ) 
            List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, false, gui ) 
            column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
  
                btn1 = guiCreateButton( 149, 430, 99, 45, "Leave", false, gui ) 
                guiSetFont( btn1, "default-bold-small" )       
        List = guiCreateGridList ( 0.04, 0.05, 0.95, 0.75, true, gui ) 
        column = guiGridListAddColumn( List, "Bikes", 0.85 ) 
        btn2 = guiCreateButton(18,430,99,45,"Rent 50$",false, gui) 
        guiSetProperty( btn1, "HoverTextColour", "FFFF0000" ) 
        guiSetProperty( btn2, "HoverTextColour", "FFFFFF00" ) 
        row = guiGridListAddRow (List) 
    guiGridListSetItemText ( List, row, column, "Mountain Bike", false, false ) 
      row2 = guiGridListAddRow (List) 
      guiGridListSetItemText (List, row2, column, "BMX", false, false ) 
       row3 = guiGridListAddRow (List) 
       guiGridListSetItemText (List, row3, column, "Bike", false, false ) 
    
        
    addEventHandler("onClientGUIClick", btn1, close, false) 
    addEventHandler("onClientGUIClick", btn2, rent, false) 
end 
addEventHandler("onClientResourceStart", resourceRoot, createGui) 
  
function rent (button,state) 
if button == "left" and state == "up" then 
takeCash ( amount )     
     takePlayerMoney ( 100 ) 
end 
end 
  
          
  
local marker = createMarker (1220, -1415.5,12, "cylinder", 1.5, 0, 0, 225, 225) 
  
addEventHandler("onClientMarkerHit", marker, 
function ( hitPlayer ) 
    if ( hitPlayer == localPlayer ) then 
        guiSetVisible( gui, true) 
        showCursor( true) 
        outputChatBox( "Bike shop : Welcome to the Rent Shop", 255, 255, 5) 
    end 
end ) 
  
   function close(button,state) 
    if button == "left" and state == "up" then 
        guiSetVisible ( lol, false) 
        guiSetInputEnabled(false) 
        guiSetVisible(gui, false) 
        showCursor(false) 
    end 
end 

Link to comment

https://wiki.multitheftauto.com/wiki/OnClientPedDamage

function cancelPedDamage ( attacker ) 
    cancelEvent() -- cancel any damage done to peds 
end 
addEventHandler ( "onClientPedDamage", getRootElement(), cancelPedDamage ) 

(© wiki :P)

edit: If you only want it for one ped use:

  
addEventHandler ( "onClientPedDamage", getRootElement(), 
function ( attacker ) 
if source == pedElement then 
    cancelEvent() 
end 
end) 

Link to comment
  • Moderators

Client:

addEventHandler 
"onClientGUIClick" 
guiGridListGetSelectedItem 
guiGridListGetItemText 
triggerServerEvent 

server:

addEvent 
addEventHandler 
createVehicle 
warpPedIntoVehicle 
takePlayerMoney 

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