Jump to content

Few questions.


PLEP

Recommended Posts

Hello, I'm Alexander_Rudin for those who knows me or saw in game earlier.

I started to script recently and have in possession very little knowledge in this area. I read some tutorial in wiki (Introduction in Scripting) and decided not to go reading further, before I make sure how every simple function working. However it's all seems to be too complicated for me. :shock:

Here is few questions...

1. I took simple script from the tutorial and tried to modify it a little. According to my idea, when player joins, he and the camera has to face west. But every server restart causes camera to change it's position. Although ped keeps facing west.

Modify the script please, so I can see what was wrong. Don't attempt to explain in words - anyway won't work with me, lol.

function joinHandler()
local x = -1951.37
local y =  148.78
local z =  26.28
local r =  90
spawnPlayer(source, x, y, z, r)
fadeCamera(source, true)
setCameraTarget(source, rotation)
outputChatBox("Test.", source)
end
 
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

2. What does "local" and in which cases should I use it?

3. Is there any objects/markers/pickups/vehicles limit?

4. How do I place static Brownstreak (Train engine) on the rails? Than when I restart server it's will be on certain place and noone could use it.

5. How to make gas station pumps "un-blow-able"?

6. Map Editor. How to delete objects ( Not these which I created )? I mean in cases when there is a skyscraper, but I want to delete it and place few other small buildings on this place.

7. How to toggle lights on/off, add new lights on vehicles and change color of each light?

8. How could I lower top speed of all/some vehicles in game? So that when I start gamemode everyone has same handling.

That's all for now. Would add some more later.

Please, don't tell me to google or use wiki. All this :~ is too complicated for me. I want to hear simple and clear explanation.

Edited by Guest
Link to comment
1. I took simple script from the tutorial and tried to modify it a little. According to my idea, when player joins, he and the camera has to face west. But every server restart causes camera to change it's position. Although ped keeps facing west.

Modify the script please, so I can see what was wrong. Don't attempt to explain in words - anyway won't work with me, lol.

Nope, if I just modify the script, you will not learn/understand anything and I'll have to come back tomorrow to modify even more of your scripts.

function joinHandler()
local x = -1951.37
local y =  148.78
local z =  26.28
local r =  90
spawnPlayer(source, x, y, z, r)
fadeCamera(source, true)
setCameraTarget(source, rotation)
outputChatBox("Test.", source)
end
addEventHandler("onPlayerJoin", getRootElement(), joinHandler)

setCameraTarget in wiki tells that you need to use a player as a second argument. If you want the camera to face west, you might want to use setCameraMatrix first and then toggle the fixed mode out.

2. What does "local" and in which cases should I use it?

When declaring variables, by default all variables are declared globally. If you use local, it is defined only in that chunk of code. You should use it whereever you don't need a global variable.

function omg()
variable = "yay" -- global variable
local localvar = "yat" -- local to the function
end
omg()
-- and now if you try, variable is still "yay", but localvar is a nil value, as it's outside the chunk.

Those chunks are basically everything starting from file to end of file, function declaration to end, do - end, then - end (or elseif)

3. Is there any objects/markers/pickups/vehicles limit?

Vehicle limit should be about 65535, Coronas: 64, Checkpoints, Rings, Cylinders and Arrows combined: 32. There are more limits too like projectiles but I guess you shouldn't worry about them.

4. How do I place static Brownstreak (Train engine) on the rails? Than when I restart server it's will be on certain place and noone could use it.

Well you can put it into world with createVehicle, it will spawn to the nearest rail. Then I guess you could freeze it or lock or something. Or create it for all clients clientside (clientside vehicles can't be entered)

5. How to make gas station pumps "un-blow-able"?

I believe there was a function like setObjectStatic or something like that. Look for that in wiki

6. Map Editor. How to delete objects ( Not these which I created )? I mean in cases when there is a skyscraper, but I want to delete it and place few other small buildings on this place.

You can't

7. How to toggle lights on/off, add new lights on vehicles and change color of each light?

setVehicleOverrideLights,setVehicleHeadLightColor, I don't know about adding more lights.

8. How could I lower top speed of all/some vehicles in game? So that when I start gamemode everyone has same handling.

Handling is not about top speed, but anyway, to limit top speed you could onClientRender check for vehicle velocity and if it's bigger than limit, tone it down.

That's all for now. Would add some more later.

Please, don't tell me to google or use wiki. All this :~ is too complicated for me. I want to hear simple and clear explanation.

Wiki IS the best explanation. It was made just for that we would not have to teach every and every person who wants to start scripting. All our explanations are based on wiki. If you can't understand it, you can't start scripting.

Link to comment

Thank you for your answers.

Here's some more questions...

9. How do I set ID for every player on player join? So then I could use commands on players using theirs ID instead of typing a full name. Either how to force script to recognize players by parts of theirs name.

10. I have added two commands to my gamemode, /w and /v. /w [Weapon ID] [Ammo] gives weapon to player who wrote the command. Same with /v, but it's for vehicles, /v [Vehicle ID] . At the moment they are recognizing only Weapons or Vehicles ID, but not names or part of name. How to make make them recognize names too? For example /w ak 100, /w min 500 or /v monster , /v greenwo .

11. When car damaged really bad first it starts smoking, then flaming, then finnaly blows up. When car begins flaming, how to force it NOT to blow? I just need a way to keep it flaming without blowing.

12. Anybody have an example of fuel system script? I need that cars could refill on certain petrol stations, for certain price and each vehicle has it's own fuel consumption speed.

Wiki IS the best explanation. It was made just for that we would not have to teach every and every person who wants to start scripting. All our explanations are based on wiki. If you can't understand it, you can't start scripting.

As I said, explanations in wiki are TOO complicated and I don't understand anything in it. Althought it's waaaay easier for me if someone explains it to me, like here. Yes, I will post more scripts to modify. If you don't want to modify them, don't do it. I won't bother you anymore. This way it's easier for me to see what was wrong. This is the way I am learning. In any way, Thank you for trying to help me. :)

Link to comment
9. How do I set ID for every player on player join? So then I could use commands on players using theirs ID instead of typing a full name. Either how to force script to recognize players by parts of theirs name.

Well, you kind of need to make your own system for it, since there is no real pre-made one yet. Best way to use this is using setElementData and a table next to that. (table[iD]=player) Then you need to make commands use this method.

10. I have added two commands to my gamemode, /w and /v. /w [Weapon ID] [Ammo] gives weapon to player who wrote the command. Same with /v, but it's for vehicles, /v [Vehicle ID] . At the moment they are recognizing only Weapons or Vehicles ID, but not names or part of name. How to make make them recognize names too? For example /w ak 100, /w min 500 or /v monster , /v greenwo .

getWeaponIDFromName and getVehicleIDFromName are the best ways of doing it. (ignore the deprecated thing on the getVehicleIDFromName page, as that applies to 1.0 +)

12. Anybody have an example of fuel system script? I need that cars could refill on certain petrol stations, for certain price and each vehicle has it's own fuel consumption speed.

There are several released ones. Use the community resources page's search function to find them. Might you find yourself looking for resources, that's the place to go. It's full of useful, neat and quite interesting resources. (Just "fuel" in the name field will do)

Link to comment

5. How to make gas station pumps "un-blow-able"?

I believe there was a function like setObjectStatic or something like that. Look for that in wiki

It doesn't work. I also need to make wooden fences unbreakable.

9. How do I set ID for every player on player join? So then I could use commands on players using theirs ID instead of typing a full name. Either how to force script to recognize players by parts of theirs name.

Well, you kind of need to make your own system for it, since there is no real pre-made one yet. Best way to use this is using setElementData and a table next to that. (table[iD]=player) Then you need to make commands use this method.

Could you explain more in depth how to make it please? I need to gets IDs as fast as possible so it will be easier to use some commands during test.

Link to comment

If you use command handlers' it automagically passes the player's argument to the function so you know who triggered it. I know of no server which needs to identify their players by assigning them IDs. Maybe you can be more specific what you want to do and we can give you a neater solution.

Link to comment
If you use command handlers' it automagically passes the player's argument to the function so you know who triggered it. I know of no server which needs to identify their players by assigning them IDs. Maybe you can be more specific what you want to do and we can give you a neater solution.

*cough* Valhalla *cough*

Link to comment

Umm what does Valhalla use them for? :P I can understand there already is a nice player identifying thing - the accounts. Also the serials etc. I wanted to say before that I can't think of a server which uses some third method of identifying people :D

Link to comment

My server used numerical IDs that were assigned to people when they joined. These were mostly used for admin stuff, but also for other things like my own private messages function. (MTA's regular one sux since you have to type the entire player name every time.)

Link to comment

Well, yeah. I need the way to assign unique ID number to each player when he joins. That's going to be used mainly for personal messages, commands in run code during test and in game commands which starting with slash ( /giveweapon [iD/PlayerName] [Weapon ID] [Ammo] for example ). IDs should be different so there won't be any mix, when player disconnects his ID could be used by another player who joins the server. And IDs should be automaticaly sorted from first one to last in scoreboard. It's actualy the same thing like in SAMP, those are dynamic.

Also I thought of static IDs. So every player gets his unique static ID number that attaches to his account forever. If player joins back on the server, then he will have the same ID like before disconnecting.

13. Hence I would need a system to save accounts data, which would save: static IDs, amount of money, cars and stuff player owns, weapons, houses, business, etcetera.

Here's another question:

14.

function [u]funcname[/u](args)
   -- Code
end

I could give any name I want to funcname or not?

15. How do I set up an arrow near some door and when I steo on it, and actualy press F, then I will get teleported to

<interior id="96" name="OG Loc's House" posX="516.8890" posY="-18.4120" posZ="1001.5650" rot="0" world="3" />

and vice versa? If I make 2 or more arrows in different places with same interior id like above, then all players who enters it would teleport to same place? If so, How to avoid this?

Edited by Guest
Link to comment

Got a problem here with camera...

According to my idea, after player dies and 4 seconds delay passes he will respawn at the certain place (-1951.37, 148.78, 26.28) and facing west (, 90). It works, but camera wouldn't look at west as the ped does. I tried fix this with setCameraMatrix. It actualy looks where I need to, but then I couldn't get back to Ped camera. I tried few variations with setCameraTarget and tried to cancel setCameraMatrix after it's true. Either way, it won't work. Maybe I did something wrong, I dunno.

function setCameraOnPlayerSpawn()
   setTimer( spawnPlayer, 4000, 1, source, -1951.37, 148.78, 26.28, 90 )
   deathCam = setCameraMatrix(source, -1984, 210, 37.95, -2024.27, 148.62,28.835)
    if (deathCam == true) then
        cancelEvent()
    end
end
addEventHandler( "onPlayerWasted", getRootElement(),setCameraOnPlayerSpawn)

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