Jump to content

Noki

Members
  • Posts

    851
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by Noki

  1. Noki

    Element Data

    Hahahaha. Read it well and you will see that i wasn't setting the marker position as data. If you don't use element data functions much that doesn't mean that others do the same. You just don't know how useful they are. I didn't read the code properly, you're right. My apologies. I do use element data, but I use it only when I need to. For example, I have a script that calculates a percentage that is required client side, but the calculations themselves are performed server-side for standardization purposes. I use element data so it gets synced client-side without having to use triggerClientEvent and keep client variable in check. I don't use it for markers as I find tables are much cleaner. I am aware of how useful element data is when used correctly. I was just saying I thought your usage of it in your example was poor. If you're going to write a tutorial, do it properly. Wow, TIL.
  2. viewtopic.php?f=91&t=45807
  3. Either one will produce the same result. Whenever the local player (meaning client-side, for only that one player) targets, the function tied to that event will be triggered. onClientPlayer* --> These only work for the local player onClient* --> These work for any element that is synced client-side (can also be local player, vehicles created server-side etc)
  4. function changeObjectDimension(dim) -- Set the object that is above the player's head to the player's new dimension -- source is the player whose dimension was changed setElementDimension(object, dim or getElementDimension(source)) end addEvent("onPlayerDimensionChange") addEventHandler("onPlayerDimensionChange", root, changeObjectDimension) function setPlayerDimension(plr, dim) -- do standard checks here setElementDimension(plr, dim) triggerEvent("onPlayerDimensionChange", plr, dim) -- Triggers the event with the player whose dimension was changed as the source, and their new dimension as the first parameter end Obviously untested. Just use setPlayerDimension as an exported function whenever you want to change a player's dimension.
  5. Make sure you also have mta-helper.fx. // // mta-helper.fx // // File version: 0.0.1 // Date updated: 2011-09-26 // // Big file of doom containg most of the stuff you need to get shaders working with MTA // // // This file has 4 sections: // 1. Variables // 2. Renders states (parital - includes only those that are used the most) // 3. Helper functions // 4. Normal generation // //#################################################################################################################### //#################################################################################################################### // // Section #1 : Variables // //#################################################################################################################### //#################################################################################################################### //--------------------------------------------------------------------- // These parameters are set by MTA whenever a shader is drawn //--------------------------------------------------------------------- // // Matrices // float4x4 gWorld : WORLD; float4x4 gView : VIEW; float4x4 gProjection : PROJECTION; float4x4 gWorldView : WORLDVIEW; float4x4 gWorldViewProjection : WORLDVIEWPROJECTION; float4x4 gViewProjection : VIEWPROJECTION; float4x4 gViewInverse : VIEWINVERSE; float4x4 gWorldInverseTranspose : WORLDINVERSETRANSPOSE; float4x4 gViewInverseTranspose : VIEWINVERSETRANSPOSE; // // Camera // float3 gCameraPosition : CAMERAPOSITION; float3 gCameraDirection : CAMERADIRECTION; // // Seconds counter // float gTime : TIME; // // Strongest light influence // float4 gLightAmbient : LIGHTAMBIENT; float4 gLightDiffuse : LIGHTDIFFUSE; float4 gLightSpecular : LIGHTSPECULAR; float3 gLightDirection : LIGHTDIRECTION; //#################################################################################################################### //#################################################################################################################### // // Section #2 : Renders states // //#################################################################################################################### //#################################################################################################################### //--------------------------------------------------------------------- // The parameters below mirror the contents of the D3D registers. // They are only relevant when using engineApplyShaderToWorldTexture. //--------------------------------------------------------------------- //------------------------------------------------------------------------------------------ // renderState (partial) - String value should be one of D3DRENDERSTATETYPE without the D3DRS_ http://msdn.microsoft.com/en-us/library/bb172599%28v=vs.85%29.aspx //------------------------------------------------------------------------------------------ int gLighting < string renderState="LIGHTING"; >; // = 137, float4 gGlobalAmbient < string renderState="AMBIENT"; >; // = 139, int gDiffuseMaterialSource < string renderState="DIFFUSEMATERIALSOURCE"; >; // = 145, int gSpecularMaterialSource < string renderState="SPECULARMATERIALSOURCE"; >; // = 146, int gAmbientMaterialSource < string renderState="AMBIENTMATERIALSOURCE"; >; // = 147, int gEmissiveMaterialSource < string renderState="EMISSIVEMATERIALSOURCE"; >; // = 148, //------------------------------------------------------------------------------------------ // materialState - String value should be one of the members from D3DMATERIAL9 http://msdn.microsoft.com/en-us/library/bb172571%28v=VS.85%29.aspx //------------------------------------------------------------------------------------------ float4 gMaterialAmbient < string materialState="Ambient"; >; float4 gMaterialDiffuse < string materialState="Diffuse"; >; float4 gMaterialSpecular < string materialState="Specular"; >; float4 gMaterialEmissive < string materialState="Emissive"; >; float gMaterialSpecPower < string materialState="Power"; >; //------------------------------------------------------------------------------------------ // textureState (partial) - String value should be a texture number followed by 'Texture' //------------------------------------------------------------------------------------------ texture gTexture0 < string textureState="0,Texture"; >; texture gTexture1 < string textureState="1,Texture"; >; texture gTexture2 < string textureState="2,Texture"; >; texture gTexture3 < string textureState="3,Texture"; >; //------------------------------------------------------------------------------------------ // vertexDeclState (partial) //------------------------------------------------------------------------------------------ int gDeclNormal < string vertexDeclState="Normal"; >; // Set to 1 if vertex stream includes normals //#################################################################################################################### //#################################################################################################################### // // Section #3 : Helper functions // //#################################################################################################################### //#################################################################################################################### //------------------------------------------------------------------------------------------ // MTAUnlerp // - Find a the relative position between 2 values //------------------------------------------------------------------------------------------ float MTAUnlerp( float from, float to, float pos ) { if ( from == to ) return 1.0; else return ( pos - from ) / ( to - from ); } //------------------------------------------------------------------------------------------ // MTACalcScreenPosition // - Transform vertex position for the camera //------------------------------------------------------------------------------------------ float4 MTACalcScreenPosition( float3 InPosition ) { float4 posWorld = mul(float4(InPosition,1), gWorld); float4 posWorldView = mul(posWorld, gView); return mul(posWorldView, gProjection); } //------------------------------------------------------------------------------------------ // MTACalcWorldPosition // - Transform position by current world matix //------------------------------------------------------------------------------------------ float3 MTACalcWorldPosition( float3 InPosition ) { return mul(float4(InPosition,1), gWorld).xyz; } //------------------------------------------------------------------------------------------ // MTACalcWorldNormal // - Rotate normal by current world matix //------------------------------------------------------------------------------------------ float3 MTACalcWorldNormal( float3 InNormal ) { return mul(InNormal, (float3x3)gWorld); } //------------------------------------------------------------------------------------------ // MTACalcGTABuildingDiffuse // - Calculate GTA lighting for buildings //------------------------------------------------------------------------------------------ float4 MTACalcGTABuildingDiffuse( float4 InDiffuse ) { float4 OutDiffuse; if ( !gLighting ) { // If lighting render state is off, pass through the vertex color OutDiffuse = InDiffuse; } else { // If lighting render state is on, calculate diffuse color by doing what D3D usually does float4 ambient = gAmbientMaterialSource == 0 ? gMaterialAmbient : InDiffuse; float4 diffuse = gDiffuseMaterialSource == 0 ? gMaterialDiffuse : InDiffuse; float4 emissive = gEmissiveMaterialSource == 0 ? gMaterialEmissive : InDiffuse; OutDiffuse = gGlobalAmbient * saturate( ambient + emissive ); OutDiffuse.a *= diffuse.a; } return OutDiffuse; } //------------------------------------------------------------------------------------------ // MTACalcGTAVehicleDiffuse // - Calculate GTA lighting for vehicles //------------------------------------------------------------------------------------------ float4 MTACalcGTAVehicleDiffuse( float3 WorldNormal, float4 InDiffuse) { // Calculate diffuse color by doing what D3D usually does float4 ambient = gAmbientMaterialSource == 0 ? gMaterialAmbient : InDiffuse; float4 diffuse = gDiffuseMaterialSource == 0 ? gMaterialDiffuse : InDiffuse; float4 emissive = gEmissiveMaterialSource == 0 ? gMaterialEmissive : InDiffuse; float4 TotalAmbient = ambient * ( gGlobalAmbient + gLightAmbient ); // Add the strongest light float DirectionFactor = max(0.2, dot(WorldNormal, -gLightDirection )); float4 TotalDiffuse = (diffuse * DirectionFactor ); float4 OutDiffuse = saturate(TotalDiffuse + TotalAmbient + emissive); OutDiffuse.a *= diffuse.a; return OutDiffuse; } float4 MTACalcGTAVehicleDiffuse2( float3 WorldNormal, float4 InDiffuse, float3 LightDirection ) { // Calculate diffuse color by doing what D3D usually does float4 ambient = gAmbientMaterialSource == 0 ? gMaterialAmbient : InDiffuse; float4 diffuse = gDiffuseMaterialSource == 0 ? gMaterialDiffuse : InDiffuse; float4 emissive = gEmissiveMaterialSource == 0 ? gMaterialEmissive : InDiffuse; float4 TotalAmbient = ambient * ( gGlobalAmbient + gLightAmbient ); // Add the strongest light float3 lightDirection = LightDirection; float DirectionFactor = max(0.2, dot(WorldNormal, -lightDirection )); float4 TotalDiffuse = (diffuse * DirectionFactor ); float4 OutDiffuse = saturate(TotalDiffuse + TotalAmbient + emissive); OutDiffuse.a *= diffuse.a; return OutDiffuse; } float4 MTACalcGTADynamicDiffuse( float3 WorldNormal, float4 InDiffuse, float3 LightDirection ) { // Calculate diffuse color by doing what D3D usually does float4 ambient = gAmbientMaterialSource == 0 ? gMaterialAmbient : InDiffuse; float4 diffuse = gDiffuseMaterialSource == 0 ? gMaterialDiffuse : InDiffuse; float4 emissive = gEmissiveMaterialSource == 0 ? gMaterialEmissive : InDiffuse; float4 TotalAmbient = ambient * ( gGlobalAmbient + gLightAmbient ); // Add the strongest light float DirectionFactor = max(0,dot(WorldNormal, -LightDirection )); float4 TotalDiffuse =
  6. Noki

    Few questions.

    What i don't understand is why there are dbFree and dbPoll don't SELECT return it already? Example: m = dbQuery(connection,"SELECT x,y,z.....) can i do now: setElementPosition(element,m[1],m[2],m[3]) dbQuery returns a query handler element, which is useless unless used with dbPoll, which returns a table, or dbFree, which returns a boolean and clears the query from memory. So, something like... qh = dbQuery("SELECT x, y, z FROM coords") result = dbPoll(qh, -1) if (result and #result > 0) then setElementPosition(element, result[1].x, result[1].y, result[1].z) end
  7. You can make an event like onPlayerDimensionChange/onPlayerInteriorChange which triggers every time a player's dimension is set. I would recommend making a centralized function for this with one triggerEvent in that function for ease. In that event, you can include the code which would change the dimension/interior of the object over a player's head. Or you can use an infinite timer that checks if a player's dimension/interior are different to that of his attached object, which may give you a slight performance hit. The second option is much easier to make. Though the first option would be considered more "proper" I guess.
  8. You may have to edit the code if you want it to work with just one object. Lua code local texName = "" local r, g, b, a = 255, 0, 0, 255 shader = dxCreateShader("shader.fx", 0, 0, false) engineApplyShaderToWorldTexture(shader, texName) dxSetShaderValue(shader, "gColor", r, g, b, a) Shader float4 gColor = float4(1,1,1,1); bool bIsGTADiffuse = true; //--------------------------------------------------------------------- // Include some common stuff //--------------------------------------------------------------------- #include "mta-helper.fx" //--------------------------------------------------------------------- // Sampler for the main texture //--------------------------------------------------------------------- sampler Sampler0 = sampler_state { Texture = (gTexture0); }; //--------------------------------------------------------------------- // Structure of data sent to the vertex shader //--------------------------------------------------------------------- struct VSInput { float3 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //--------------------------------------------------------------------- // Structure of data sent to the pixel shader ( from the vertex shader ) //--------------------------------------------------------------------- struct PSInput { float4 Position : POSITION0; float4 Diffuse : COLOR0; float2 TexCoord : TEXCOORD0; }; //------------------------------------------------------------------------------------------ // VertexShaderFunction // 1. Read from VS structure // 2. Process // 3. Write to PS structure //------------------------------------------------------------------------------------------ PSInput VertexShaderFunction(VSInput VS) { PSInput PS = (PSInput)0; // Calculate screen pos of vertex PS.Position = MTACalcScreenPosition ( VS.Position ); // Pass through tex coord PS.TexCoord = VS.TexCoord; // Calculate GTA lighting for buildings float4 Diffuse = MTACalcGTABuildingDiffuse( VS.Diffuse ); PS.Diffuse = 0; if (bIsGTADiffuse) PS.Diffuse = Diffuse; else PS.Diffuse = float4(1,1,1,Diffuse.a); PS.Diffuse *= gColor; return PS; } //------------------------------------------------------------------------------------------ // PixelShaderFunction // 1. Read from PS structure // 2. Process // 3. Return pixel color //------------------------------------------------------------------------------------------ float4 PixelShaderFunction(PSInput PS) : COLOR0 { // Get texture pixel float4 texel = tex2D(Sampler0, PS.TexCoord); // Apply diffuse lighting float4 finalColor = texel * PS.Diffuse; return finalColor; } //------------------------------------------------------------------------------------------ // Techniques //------------------------------------------------------------------------------------------ technique colorize { pass P0 { VertexShader = compile vs_2_0 VertexShaderFunction(); PixelShader = compile ps_2_0 PixelShaderFunction(); } } // Fallback technique fallback { pass P0 { // Just draw normally } }
  9. Use the latest scoreboard resource from here. Are there any messages in /debugscript 3 relating to the scoreboard at all?
  10. Seems like 'getElementData(source, "playerCol")' is false. You can perform a check beforehand like: local pCol = getElementData(source, "playerCol")) if (pCol and isElement(pCol)) then destroyElement(pCol) end
  11. toJSON({}) --> "[ [ ] ]" fromJSON("[ [ ] ]") --> {} -- Empty Lua table local t = {} table.insert(t, "CIT") local j = toJSON(t) --> "[ [ 'CIT' ] ]" local t2 = fromJSON(j) --> {[1] = "CIT"} table.insert(t2, "FFS") --> {[1] = "CIT", [2] = "FFS"} toJSON(t2) --> "[ [ 'CIT', 'FFS' ] ]"
  12. Noki

    Element Data

    That script you provided in the last example is a good example of poor use of element data. You really don't need to set the coordinates of a marker as element data. You can easily get the position with getElementPosition coupled with a marker hit event. Element data syncs to every player. It is also insecure as it can be set client side then synced to all other players. Overuse of element data is a poor scripting practice. Try to only use element data for information that needs to be available to every player and use it sparingly.
  13. Noki

    Improve OOP

    http://lua-users.org/wiki/MetamethodsTutorial https://forum.multitheftauto.com/viewtopic.php?f ... ds#p779995 https://forum.multitheftauto.com/viewtopic.php?f ... ds#p774460 You can create your own class.
  14. Noki

    CPU Usage.

    If you even bothered to look at that page you would see it had been implemented long before 1.5.2. 'ipb' made by Arran comes in the default resource pack. And I believe the is a web resource called performancebrowser (I think) which has similar functionality.
  15. You're also checking for two states (parameters that were from the onClientGUIClick event). bindKey passes the key you hit (enter) and the state of that key (up or down). So, you will need to modify your original function to accommodate for this as well.
  16. Noki

    Relative angles?

    It's at times like these matrices are most useful.
  17. I would recommend against doing it for thousands of objects as you'll be creating approximately 2 times the amount you would otherwise. I've just found the way I used works good for objects (custom and default).
  18. local obj = createObject(...) local lod = createObject(...) setLowLODElement(obj, lod) -- Where obj is the object and lod is the LOD object (use the LOD model id) I don't know of any way to set LOD of map objects, so I would convert part of the .map into a .lua file and use the code above for any objects you want to set the lod of.
  19. I did my best to try to explain what I thought he meant. I'm sorry for trying to help.
  20. Get all players? Use getElementsByType("player") Freeze a player when they join, use addEventHandler("onPlayerJoin", root, function () setElementFrozen(source, true) end ) To freeze all players, loop through the all players (getElementsByType) and set them frozen using setElementFrozen.
  21. GTA SA can run on an Intel compute stick. I highly doubt GTA V would.
  22. If you don't want to rush, don't put a definitive deadline/release date on your server. Instead, set smaller goals you want to accomplish (eg finishing the account system in 3 days, creating a gang system in one week etc). From experience, that makes it easier to keep working as you're breaking down the problem into smaller bits. Isn't that what coding is anyway?
  23. I played ETS a few times. I didn't like how realistic the handling was probably because I didn't expect it. So I just stick to trucking in MTA on SAUR or CIT.
  24. Noki

    [HELP] CST server

    This has been pissing me off for a while. TamTam doesn't hack anything. They take credit for work that isn't theirs, post already leaked scripts, and sell free scripts. They then use that money to buy booters. It's a joke.
  25. Noki

    DUP Output

    https://github.com/multitheftauto/mtasa ... a1b4c9043f
×
×
  • Create New...