Jump to content

My frist script


Recommended Posts

Posted

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

Posted
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!

If you need an Intermediate scripter feel free to PM me as I will accept "almost" any job, STATUS: UNAVAILABLE

SCOTLAND, my hometown, and the Home of GTA!

Posted
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 
  

Posted
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)

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

Posted (edited)

hmm maybe...

addEventHandler ("onClientPedDamage",thepedname, 
function () 
cancelEvent() 
end 
  

Edited by Guest
Posted
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 
  

Please do not PM me with scripting related question nor support, use the forums instead.

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

Posted
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 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted

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) 

Sometimes I dream about cheese

Posted

Client:

addEventHandler 
"onClientGUIClick" 
guiGridListGetSelectedItem 
guiGridListGetItemText 
triggerServerEvent 

server:

addEvent 
addEventHandler 
createVehicle 
warpPedIntoVehicle 
takePlayerMoney 

Please do not PM me with scripting related question nor support, use the forums instead.

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