R34Lw0rd Posted October 8, 2009 Share Posted October 8, 2009 Hello everyone. I started to write mode using the Wiki, but I have a black screen when you connect. Show where the error, please? test.lua: -- sets colors when player join function onJoin () g_Red, g_Green, g_Blue = math.random (50, 255), math.random (50, 255), math.random (50, 255) end -- checks if player has sent a message function onChat ( message, messageType ) if messageType == 0 then local root = getRootElement() outputChatBox ( getPlayerName ( source ) .. ": #E0D0B0" .. message, getRootElement(), g_Red, g_Green, g_Blue, true ) cancelEvent() end end addEventHandler ( "onPlayerJoin", getRootElement(), onJoin) addEventHandler ( "onPlayerChat", getRootElement(), onChat ) -- Get a table of all the players players = getElementsByType ( "player" ) -- Go through every player -- when a player spawns, function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) -- Spawn them at the desired coordinates spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) giveWeapon ( source, 31, 200 ) --M4 giveWeapon ( source, 36, 200 ) --Heat Seeker end addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) -- we register quitPlayer as a handler for the event function quitPlayer ( quitType ) -- we store the player's name local quittingPlayerName = getPlayerName ( source ) -- and send the message to the server outputChatBox ( quittingPlayerName .. " has left the server (" .. quitType .. ")" ) end addEventHandler ( "onPlayerQuit", getRootElement(), quitPlayer ) function playerDied(totalAmmo, killer, killerWeapon, bodypart) outputChatBox(getPlayerName(source).." died!") end addEventHandler("onPlayerWasted",getRootElement(),playerDied) function respawnVehicle( vehicle ) spawnVehicle ( vehicle, getElementData( vehicle, "posX" ), getElementData( vehicle, "posY" ), getElementData( vehicle, "posZ" ), getElementData( vehicle, "rotX" ), getElementData( vehicle, "rotY" ), getElementData( vehicle, "rotZ" ) ) end test_client.lua: function remotePlayerJoin() outputChatBox("* " .. getPlayerName(source) .. " has joined the server") end addEventHandler("onClientPlayerJoin", getRootElement(), remotePlayerJoin) function onQuitGame( reason ) outputChatBox ( getPlayerName( source ).." has left the server ("..reason..")" ) end addEventHandler( "onClientPlayerQuit", getRootElement(), onQuitGame ) function explosionOnSpawn ( ) -- get the spawned player's position local pX, pY, pZ = getElementPosition ( source ) -- and create an explosion there createExplosion ( pX, pY, pZ, 6 ) fadeCamera( true ) end -- add this function as a handler for any player that spawns addEventHandler ( "onClientPlayerSpawn", getLocalPlayer(), explosionOnSpawn ) function addRednessOnDamage ( ) fadeCamera ( source, false, 1.0, 255, 0, 0 ) -- fade the player's camera to red over a period of 1 second setTimer ( fadeCamera, 500, 1, source, true, 0.5 ) -- don't let it go to opaque red, interrupt it after half a second and fade back to normal end addEventHandler ( "onPlayerDamage", getRootElement(), addRednessOnDamage ) function showClientImage() guiCreateStaticImage( 20, 200, 100, 100, "image\logo.png", false ) end addEventHandler( "onClientResourceStart", getResourceRootElement( getThisResource() ), showClientImage ) P.S. Sorry for my bad english.. Link to comment
R34Lw0rd Posted October 9, 2009 Author Share Posted October 9, 2009 Up Help me, please! Link to comment
Gamesnert Posted October 9, 2009 Share Posted October 9, 2009 test.lua -- Get a table of all the players players = getElementsByType ( "player" ) -- Go through every player -- when a player spawns, function player_Spawn ( posX, posY, posZ, spawnRotation, theTeam, theSkin, theInterior, theDimension ) -- Spawn them at the desired coordinates spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) giveWeapon ( source, 31, 200 ) --M4 giveWeapon ( source, 36, 200 ) --Heat Seeker end addEventHandler ( "onPlayerSpawn", getRootElement(), player_Spawn ) Basically, you wrote this: When the player spawns -> Spawn the player If the function actually triggers, you encounter variable "playerValue", which doesn't appear to exist. Here's what you should do: Remove the "onPlayerSpawn" handler. Remove all of those parameters from the function at line 20, and add one called "playerValue" Fix giveWeapon to use the new "playerValue" var you just made. Add setCameraTarget and fadeCamera after spawnPlayer to make the camera act properly. (target the camera to himself and fade the camera in) In function "onJoin", add a line: "player_Spawn ( source )" Fix that, and it should work I guess. Link to comment
R34Lw0rd Posted October 9, 2009 Author Share Posted October 9, 2009 And you can not give the already bug-fix code? I just started and therefore nothing in this do not understand. Link to comment
Gamesnert Posted October 9, 2009 Share Posted October 9, 2009 And you can not give the already bug-fix code? Who's the scripter for your server here? You are. Just try, and if you don't get something or stuck at 1 of the points, ask how to do it. But you're not going to learn much from a simple copy+paste either. That's the simple reason why I didn't fix your code from the start, but tried to give some advice. Well, which points don't you understand? Link to comment
R34Lw0rd Posted October 9, 2009 Author Share Posted October 9, 2009 Ok.With your help, will try to do it: function player_Spawn ( playerValue ) spawnPlayer ( playerValue, 0.0, 0.0, 5.0, 90.0, 0 ) giveWeapon ( playerValue, 31, 200 ) --M4 giveWeapon ( playerValue, 36, 200 ) --Heat Seeker end and? function onJoin () g_Red, g_Green, g_Blue = math.random (50, 255), math.random (50, 255), math.random (50, 255) player_Spawn ( source ) end This part of the code is correct? Add setCameraTarget and fadeCamera after spawnPlayer to make the camera act properly. (target the camera to himself and fade the camera in) I can not understand how to use it properly and where to write.. P.S. But what to write in test_client.lua? Link to comment
Gamesnert Posted October 9, 2009 Share Posted October 9, 2009 Add setCameraTarget and fadeCamera after spawnPlayer to make the camera act properly. (target the camera to himself and fade the camera in) I can not understand how to use it properly and where to write.. Ah, that. I'll try to explain. You'll need to add these functions to the player_Spawn function. You'll need to do these 2 functions for these reasons: fadeCamera is required because the screen is black by default, which you defined as an issue. Actually, though, the issue is MTA doesn't know what to show you. So it waits for the script to tell MTA to fade before it does Fading it in still leaves the issue; what to show? If faded in, but no specific camera position/target set, it'll just show Mount Chilliad. To solve this, you can use setCameraTarget to aim the camera to the local player, or a remote one. That's why we need these functions. Now let's look at their function pages on the wiki. It says: Required Arguments * thePlayer: The player whose camera you wish to fade. * fadeIn: Should the camera be faded in our out? Pass true to fade the camera in, false to fade it out to a color. Optional Arguments * timeToFade: The number of seconds it should take to fade. Any number less than 1 makes the fade instant. * red: The amount of red in the color that the camera fades out to (0 - 255). Not required for fading in. * green: The amount of green in the color that the camera fades out to (0 - 255). Not required for fading in. * blue: The amount of blue in the color that the camera fades out to (0 - 255). Not required for fading in. As you can see, there are a lot of arguments here. (arguments == values between the "(" and ")", seprerated by a ",") There are 2 required ones (without which the function won't work) and a lot of optional ones. (which we can just skip) For the very basic, that would mean: fadeCamera ( playerValue, true ) It's possible though to make the fading take longer: fadeCamera ( playerValue, true, 2 ) That would make it take 2 seconds long, instead of 1. Required Arguments * thePlayer: The player whose camera you wish to modify. Optional Arguments * target: The element that you want the camera to follow. If none is specified, the camera will target the player. This means you need to provide at least 1 argument. Now we just need to fill in the arguments. From the meaning of the arguments, it seems we need to do something like this: setCameraTarget ( playerValue, playerValue) P.S. But what to write in test_client.lua? Fading etc is usually done in the same function as spawn. spawnPlayer though is server-side only, so all you really have to do to fix the blackness issue, is fixing the server-side script. If you've got any other questions, or still don't get something, feel free to ask. P.S. Sorry for the long post, I just seem to like submitting huge pills to swallow Link to comment
R34Lw0rd Posted October 9, 2009 Author Share Posted October 9, 2009 Gamesnert, big thanks! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now