Jump to content

Script help


jkub

Recommended Posts

  • Replies 109
  • Created
  • Last Reply

Top Posters In This Topic

getRootElement is in clientside too. You only make them server and client side in the meta, before you start the resource. By default, there serverside.

onMarketHit, if you use getRoot it will trigger everytime someone hits a marker. However if you use the name of a marker, then it will only trigger when an element hits that specific marker. Thats what getRoot is for. Sort of all, or everything ( getRoot ) or specific ( a name ).

onMarketHit, getRootElement(), onMarkerHit - will trigger for all markers

marker = createMarker (0, 5, 1, "cylinder", 3, 255, 0, 0, 175)

onMarkerHit, marker, onMarkerHit2 - will trigger only when something comes in contact with your marker.

Link to comment
I got it to trigger outputchatbox succesfully but how would I make it to where it would fixvehicle, ive already tried the line and it keeps giving me a bad arguement line @ fixvehcile

what am i doing wrong.

Ok, so what you exactly wanted to do? For as far as I can see in the last few posts, you want to fix a vehicle on marker hit. Is that right?

If so, you need to remember that onMarkerHit will be triggered 2 times:

1. When the vehicle enters the marker

2. When you enter the marker

To stop this, I'd recommend to use "if getElementType(source)=="vehicle" then..." or by replacing the event with onPlayerMarkerHit and adding parts like checking if the correct marker was hit etc.

Do remember that with onPlayerMarkerHit it's the PLAYER that activates the event! And you still need to check if he is in a vehicle by for example getPlayerOccupiedVehicle! That's why I recommend the getElementType way. It's much easier.

I think that should be able to fix your problem, or what is the problem? What did you enter in fixVehicle? I may hope the vehicle element?

Link to comment

hmm seems like a big step for me right now. maybe I should start smaller, instead if on marker hit it just teleports (spawnsplayer) in a posistion on the map that i specify.

i have put toghether a script which has ran no debug errors on the luaeditor but probably will on the actual game and not work. I havent got to test it yet but here it is, ive pulled examples from the wiki and tryed altering them to my suit, youl probably find multiple errors lol

  
createMarker ( 0, 0, 0, "cylinder", 3, 0, 255, 0, 175 ) visibleTo = getRootElement() 
function MarkerHit ( hitPlayer, matchingDimensio ) 
  
    addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 
        players = getElementsByType ( "player" ) 
            for playerKey, playerValue in ipairs(players) do 
            spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) 
            end 
end 

Link to comment
hmm seems like a big step for me right now. maybe I should start smaller, instead if on marker hit it just teleports (spawnsplayer) in a posistion on the map that i specify.

i have put toghether a script which has ran no debug errors on the luaeditor but probably will on the actual game and not work. I havent got to test it yet but here it is, ive pulled examples from the wiki and tryed altering them to my suit, youl probably find multiple errors lol

  
createMarker ( 0, 0, 0, "cylinder", 3, 0, 255, 0, 175 ) visibleTo = getRootElement() 
function MarkerHit ( hitPlayer, matchingDimensio ) 
  
    addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 
        players = getElementsByType ( "player" ) 
            for playerKey, playerValue in ipairs(players) do 
            spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) 
            end 
end 

I... Ehm... Am not sure what you were planning to be honest...

You are:

-Creating a marker

-MarkerHit needs to be activated with the addEventHandler inside MarkerHit... Doesn't really work...

-Your idea was when someone (or someTHING) hits the marker, EVERY player must spawn..?

I don't know, but I don't think your code makes that much sense looking at it that way... Good try though!

I suppose you want to teleport the player that hit the marker? Then let me help you. ;)

createMarker ( 0, 0, 0, "cylinder", 3, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimensio ) 
        if getElementType(hitPlayer)=="player" then 
            setElementPosition(hitPlayer,0,0,5) 
            setPlayerRotation(hitPlayer,90) 
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

Later you can make the code more and more advanced. But for now, it'll do. ;)

Link to comment
I got the bank script from the resources page and I want to make it to where you can login to your own player account on my server and you can keep track of your bank account. like you can save your money to your account and when you come back the next day youl still be able to have the money you had the day b4... sort of like an rpg>> how would i do that?

What is wrong with bank resource? Doesn't that save money for you? It uses SQL database so it's not editable using simple Notepad. Test it and see if your money gets saved (you first need to register and login to save your money in bank).

Link to comment

ok I changed the marker posistion and teleport location and here is the current script wich works perfectly.

createMarker ( 2417.1013183594, 1130.9943847656, 10.8203125, "cylinder", 2.5, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimensio ) 
        if getElementType(hitPlayer)=="player" then 
            setElementPosition(hitPlayer,1827.4294433594,594.36029052734,51.134124755859) 
            setPlayerRotation(hitPlayer,90) 
            outputChatBox ( "Welcome to Dr.Philly Blunt's Projectz Island" ) 
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 
  

Since i got that I wanted to create another marker near the teleport location so i can return back to spawn wich is where my first marker is, here is the script for that wich doesent work, It does not show the marker but it is there and also when i go into it just teleports me back to the first telport location.

and here is that script

createMarker ( 1821.7373046875, 604.20440673828, 49.398349761963, "cylinder", 2.5, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimensio ) 
        if getElementType(hitPlayer)=="player" then 
            setElementPosition(hitPlayer,2417.1013183594,1125.9943847656,10.8203125) 
            setPlayerRotation(hitPlayer,90) 
            outputChatBox ( "You have returned to the spawn" ) 
        end 
end 

hmmm

Link to comment

You have to check if the marker you hit is teleport marker and which teleport marker. Something like this:

local teleport = createMarker ( 2417.1013183594, 1130.9943847656, 10.8203125, "cylinder", 2.5, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimensio ) 
        if getElementType(hitPlayer)=="player" and source == teleport then 
            setElementPosition(hitPlayer,1827.4294433594,594.36029052734,51.134124755859) 
            setPlayerRotation(hitPlayer,90) 
            outputChatBox ( "Welcome to Dr.Philly Blunt's Projectz Island" ) 
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

Link to comment
You have to check if the marker you hit is teleport marker and which teleport marker. Something like this:
local teleport = createMarker ( 2417.1013183594, 1130.9943847656, 10.8203125, "cylinder", 2.5, 0, 255, 0, 175 ) 
function MarkerHit ( hitPlayer, matchingDimensio ) 
        if getElementType(hitPlayer)=="player" and source == teleport then 
            setElementPosition(hitPlayer,1827.4294433594,594.36029052734,51.134124755859) 
            setPlayerRotation(hitPlayer,90) 
            outputChatBox ( "Welcome to Dr.Philly Blunt's Projectz Island" ) 
        end 
end 
addEventHandler("onMarkerHit", getRootElement (), MarkerHit) 

Later you can make the code more and more advanced. But for now, it'll do. ;)

I just gave him a basic function so he could improve it as he build up experience. ;)

EDIT: Nvm, didn't see his post... :S

Edited by Guest
Link to comment

ive got a set team script that is supposed to set the players team to an already created team when a player spawns, i have pulled some examples from the wiki and of course i dont feel accomplished for that but until i get it right even with the examples I feel it would be time to rely less on them. my luaeditor didnt spit out any error messages but im feeling it will not function properly when i use it in my server. i havent tested it yet but here it is

function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) 
    setPlayerTeam ( source, NWA ) 
        outputchatbox ("Your team has been set to nwa", myPlayer ) 
    end 
addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) 

Link to comment
ive got a set team script that is supposed to set the players team to an already created team when a player spawns, i have pulled some examples from the wiki and of course i dont feel accomplished for that but until i get it right even with the examples I feel it would be time to rely less on them. my luaeditor didnt spit out any error messages but im feeling it will not function properly when i use it in my server. i havent tested it yet but here it is

function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) 
    setPlayerTeam ( source, NWA ) 
        outputchatbox ("Your team has been set to nwa", myPlayer ) 
    end 
addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) 

If the variable NWA exists (for example NWA=createTeam...) then it might work.

Otherwise, you have another command available: getTeamFromName. Just in case it doesn't work, switch to this one. ;)

Link to comment

this one is supposed to kill the player when they walk into the marker but nothing happens, shouldent i define the source player then do one of those if source >> then things

theMarker = createMarker ( 0, 0, 4, "cylinder", 2.5, 255, 0, 0, 175 ) visibleTo = getRootElement() 
    function markerKill ( sourcePlayer ) 
    onPlayerMarkerHit = theMarker, matchingDimension 
        killPlayer(sourcePlayer, sourcePlayer) 
    end 
     

Link to comment
this one is supposed to kill the player when they walk into the marker but nothing happens, shouldent i define the source player then do one of those if source >> then things

theMarker = createMarker ( 0, 0, 4, "cylinder", 2.5, 255, 0, 0, 175 ) visibleTo = getRootElement() 
    function markerKill ( sourcePlayer ) 
    onPlayerMarkerHit = theMarker, matchingDimension 
        killPlayer(sourcePlayer, sourcePlayer) 
    end 
     

You must first read Lua manual and then read MTA wiki about how the event system works...

  
theMarker = createMarker ( 0, 0, 4, "cylinder", 2.5, 255, 0, 0, 175 ) 
function markerKill ( sourcePlayer ) 
    if source == theMarker then -- check if marker you enter is theMarker you created, if so, kill the player 
        killPlayer(sourcePlayer) 
    end 
end 
addEventHandler( "onMarkerHit", getRootElement(), markerKill ) 
  

Link to comment

here is one, It creates a rhino at the san fierro airport at a specific location and when a player enters it, the script outputs a message to the chat saying that the rhino has been stolen, and a arrow type marker will be attached to the rhino and also a blip will be attachted to the rhino.

ive used destroy element and destroyed the marker where the rhino was sitting so you cant go back to where it was sitting and trigger the message again.

This works perfectly but later I decided to make it to where the driver who is in possesion of the rhino gets money constantly while he is in it, like 10 dollars every 5 seconds.

now the get money part dosent work. I assumed you would use the settimer function to make it to where getting the money is not just a one time thing by setting the last number on the settimer function to 0 makes it execute the function infinintly.

I can get the givemoney part to work just for one time without the use of the settimer function but once i put that in the picture it throws me off and I do understand it has to call a function.

car = createVehicle ( 432, -1276.3302001953, 35.553936004639, 14.0, 0, 0, 0 ) 
theMarker = createMarker ( -1276.3302001953, 35.553936004639, 13.758337974548, "cylinder", 2.5, 255, 0, 0, 0 ) 
function markerBlip ( sourcePlayer ) 
    if source == theMarker then -- check if marker you enter is theMarker you created, if so, blip the player 
        arrowMarker = createMarker ( 0, 0, 0, "arrow", 1.5, 255, 0, 0, 170 ) 
        attachElementToElement ( arrowMarker, car, 0, 0, 4 ) 
        createBlipAttachedTo ( car, 51, 4, 255, 0, 0, 255 ) visibleTo = getRootElement() 
        outputChatBox("The rhino has been stolen", getRootElement(), 255, 255, 0) 
        destroyElement ( theMarker ) 
    end 
end 
  
addEventHandler( "onMarkerHit", getRootElement(), markerBlip ) 
  
function consoleGivePlayerMoney ( sourcePlayer ) 
    setTimer ( theCar, 1000, 0 ) 
    givePlayerMoney ( sourcePlayer, 10 ) 
end 
  

Link to comment
here is one, It creates a rhino at the san fierro airport at a specific location and when a player enters it, the script outputs a message to the chat saying that the rhino has been stolen, and a arrow type marker will be attached to the rhino and also a blip will be attachted to the rhino.

ive used destroy element and destroyed the marker where the rhino was sitting so you cant go back to where it was sitting and trigger the message again.

This works perfectly but later I decided to make it to where the driver who is in possesion of the rhino gets money constantly while he is in it, like 10 dollars every 5 seconds.

now the get money part dosent work. I assumed you would use the settimer function to make it to where getting the money is not just a one time thing by setting the last number on the settimer function to 0 makes it execute the function infinintly.

I can get the givemoney part to work just for one time without the use of the settimer function but once i put that in the picture it throws me off and I do understand it has to call a function.

car = createVehicle ( 432, -1276.3302001953, 35.553936004639, 14.0, 0, 0, 0 ) 
theMarker = createMarker ( -1276.3302001953, 35.553936004639, 13.758337974548, "cylinder", 2.5, 255, 0, 0, 0 ) 
function markerBlip ( sourcePlayer ) 
    if source == theMarker then -- check if marker you enter is theMarker you created, if so, blip the player 
        arrowMarker = createMarker ( 0, 0, 0, "arrow", 1.5, 255, 0, 0, 170 ) 
        attachElementToElement ( arrowMarker, car, 0, 0, 4 ) 
        createBlipAttachedTo ( car, 51, 4, 255, 0, 0, 255 ) visibleTo = getRootElement() 
        outputChatBox("The rhino has been stolen", getRootElement(), 255, 255, 0) 
        destroyElement ( theMarker ) 
    end 
end 
  
addEventHandler( "onMarkerHit", getRootElement(), markerBlip ) 
  
function consoleGivePlayerMoney ( sourcePlayer ) 
    setTimer ( theCar, 1000, 0 ) 
    givePlayerMoney ( sourcePlayer, 10 ) 
end 
  

Ok, first: You need to trigger consoleGivePlayerMoney once first.

Second: Is theCar a function in your script?

Third: If it would loop consoleGivePlayerMoney all the time, and setTimer repeat amount is set to 0, you would get about 100 repeating timers after 100 seconds... =/

Fourth: You're not giving a parameter consoleGivePlayerMoney needs. Try changing it to: setTimer ( consoleGivePlayerMoney, 1000, 1, sourcePlayer )

Link to comment

I just figured out that this script interferes with my offedit script witch is a map editor. when i create the objects with it, it pops that rhino has been stolen message, I figured because it makes a arrow marker above the selected object, hmmm.

and btw does anyone know the id for the mounted minigun cause I wanna attach it to the back of a patriot

Link to comment
I just figured out that this script interferes with my offedit script witch is a map editor. when i create the objects with it, it pops that rhino has been stolen message, I figured because it makes a arrow marker above the selected object, hmmm.

and btw does anyone know the id for the mounted minigun cause I wanna attach it to the back of a patriot

Search for a resource called "object browser" or "objbrowser". You might find it usefull, but there are 2 disadvantages:

1. It's divided in categories, but you can't collapse some of the categories you don't need.

2. Sooooooooo sloooooooow load time... =/

But well, it's one of the best resources to find out some ID's.

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