-
Posts
6,069 -
Joined
-
Last visited
-
Days Won
210
Posts posted by IIYAMA
-
-
9 hours ago, Dzsozi (h03) said:
I mean I don't understand how should I implement it in this case.
You were almost there, you are doing great
The trick here is to split of the constructor. So that your new table will only inherit methods from the constructor.
local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor
local CREATED_HIGHLIGHTS = {} local Highlight = {} -- base, just for the 'new' method local HighlightConstructor = {} -- constructor function HighlightConstructor:destroy() iprint( self, 'destroy' ) end --[[ function HighlightConstructor:test() iprint( self ) end ]] function Highlight:new( element, style, color, flashSpeed, intensityOrThickness ) if not isElement( element ) then return false end if CREATED_HIGHLIGHTS[element] then return false end local data = { element = element, style = style, color = color, flashSpeed = flashSpeed, intensityOrThickness = intensityOrThickness } return setmetatable( data, { __index = HighlightConstructor } ) end newHightlight = Highlight:new() newHightlight:destroy()
Spoilerfunction isElement() return true end function iprint( ... ) return print( ... ) end
Some polyfill's for quick testing here:
https://www.lua.org/cgi-bin/demoNote keep in mind there is a difference in . and : calls, depending on the set-up. Just in case you didn't know, which you probably did know.
test = {} test.a = function (self) -- first parameter iprint(self) end test.a() function test:b () iprint(self) -- already available. end test:b()
-
1
-
-
1 hour ago, Swimer said:
I know this can be done using all sorts of sines, cosines, but unfortunately this is a problem for me.
See useful function:
https://wiki.multitheftauto.com/wiki/GetPointFromDistanceRotation
-
Locked: duplicate
-
10 hours ago, marcelluss said:
I rechecked the correctness of the name 100 times when registering the file and the path to the folder, but not to which one.
clientside or serverside?
Where did you transfer the file to clientside btw? If you are going to share things, for clientside and serverside, then make sure that both directories got the file.
-
2 hours ago, Swimer said:
Error on 3 line
Are you sure you do not have defined a function called 'getPlayerSerial' somewhere else in the code? (other file for example)
-
16 hours ago, Dzsozi (h03) said:
However, I can still call .new function in the testing section with
Meta table = gets inherited
local Highlight = {test1 = true}
local newTable = setmetatable({test2 = true}, {__index = Highlight})
The normal table = is inheriting from meta table
local Highlight = {test1 = true}
local newTable = setmetatable({test2 = true}, {__index = Highlight})
print("newTable:", newTable.test1, newTable.test2 ) -- newTable: true true print("Highlight:", Highlight.test1, Highlight.test2 ) -- Highlight: true nil
This means that the 'new' method should only be applied on newTable.
local Highlight = {test1 = true} function newChild (self) print("self", self) return setmetatable({}, {__index = Highlight}) end local newTable = setmetatable({test2 = true, new = newChild}, {__index = Highlight}) print(newTable:new()) print(newTable:new().test1) -- true print(newTable:new():new()) -- attempt to call a nil value (method 'new')
-
10 hours ago, Dzsozi (h03) said:
UPDATE: I changed Class.lua type from 'shared' to 'server' to match testscript.lua type, made Class a local table again, and I got the error again, so I don't understand really why it should be a global variable.
Do you remember that after loading a string, you have to call it again?
It basically means that there is a function around it. And every time you call that function, you run the code inside it.
-- https://www.lua.org/pil/8.html f = loadstring("i = i + 1") i = 0 f(); print(i) --> 1 f(); print(i) --> 2
See docs: https://www.lua.org/pil/8.html
So this is how it more or less looks like when loaded:
function () Class = {} Class.__index = Class setmetatable(Class, {__call = function( _,... ) return Class.new(...) end }) function Class.new() local self = setmetatable({}, Class) return self end end
So what you want to do:
[[ local Class = {} Class.__index = Class setmetatable(Class, {__call = function( _,... ) return Class.new(...) end }) function Class.new() local self = setmetatable({}, Class) return self end return Class]]
local Class = loadstring(createClass())()
-
11 minutes ago, Cronoss said:
what's wrong with this??
You named your own function the same as the MTA function.
function fadeCamera()
fadeCamera(source, true, 0.5, 0, 0, 0)
end
-
1
-
-
14 minutes ago, Huba221 said:
<meta>
<script src="c.lua type"="client" cache="false"/>
<script src="s.lua"/>
<file src="font.ttf"/>
</meta>Some typo's.
<meta>
<script src="c.lua" type"="client" cache="false"/>
<script src="s.lua"/>
<file src="font.ttf"/>
</meta>Green = added
Red = removed<meta> <script src="c.lua" type="client" cache="false" /> <script src="s.lua" /> <file src="font.ttf" /> </meta>
-
32 minutes ago, SinaAmp said:
sorry i wasted your time @IIYAMAthank you for help
No worries. BTW, you can only send the hunger value when you know which account this player has logged in to. There is a chance that the player hasn't logged in yet when the resource has been loaded.
On closer inspection it might be better to try it on onPlayerLogin and using a login panel to delay the user-interaction.
addEventHandler ("onPlayerLogin",root, afterlogin)
-
sx+2, sy+2, sx+2, sy+2,
Lets not move the right-side of the text boundingbox beyond the left-side of the boundingbox.
-
14 minutes ago, SinaAmp said:
what i will do now to solve this problem?
Doing it at the right moment. For example on the event "onPlayerResourceStart" and sending it only to this player.
https://wiki.multitheftauto.com/wiki/OnPlayerResourceStart
Read the wiki of that event carefully, since there is info in it that most people forget to read...
-
1
-
-
20 minutes ago, SinaAmp said:
server triggered client side event but event is not added
20 minutes ago, SinaAmp said:triggerClientEvent("onGetData", root,PHunger)
You are sending a message to all clients/players directly when the server is executing the script. The clients/players haven't loaded their scripts yet, to receive the message.
-
48 minutes ago, SinaAmp said:
i got this error repeatly
Database result uncollected after 5 minutes. [Query: SELECT Hunger,Thirst FROM stats WHERE Account IN ( NULL, )]
That happens when you fire a query (with a callback) and restart/stop the resource directly after that.
-
6 hours ago, stscripter said:
It didn't work with the playSound3D function.
In that case, try to make a bug report.
And cache the audio files for now on the server. (For clients to dowload from)
-
10 hours ago, SinaAmp said:
why i need to get hunger and thirst in 'checkhunger' function when i got them from 'afterlogin' function?
Because you didn't save it there. You have not written a (memory) cache for your database.
-
28 minutes ago, SinaAmp said:
when i use your library
First of all, you do not need to use my library. Only if you are going to make use of callbacks.
29 minutes ago, SinaAmp said:i dont know how to get my processed hunger and thirst from server side
You do not get the hunger, you send it using triggerClientEvent.
for _,row in ipairs(result) doHunger = row["Hunger"]
Thirst = row["Thirst"]
breakendlocal row = result[1] Hunger = row["Hunger"] Thirst = row["Thirst"]
32 minutes ago, SinaAmp said:function checkHunger(player, PHunger) if Hunger and Hunger >= 0 then PHunger = Hunger - 1 end if PHunger <= 20 then outputChatBox("You need to feed as fast as possible.", 255, 0, 0) end if PHunger == 0 then if not isPedDead(Player) then local hp = getElementHealth(Player) setElementHealth(Player, hp - 30) end end end setTimer(checkHunger, 30000, 0)
You should get here the current hunger values from the database.
https://wiki.multitheftauto.com/wiki/DbPrepareString
Finish the code yourself.
local players = getElementsByType("player") local queryString = dbPrepareString( db, "SELECT Hunger,Thirst FROM stats WHERE Account IN ( " -- loop with player account names queryString = queryString .. dbPrepareString( db, "?, ", AccName) -- loop end queryString = queryString .. " )" local handle = dbQuery( db, queryString ) -- Receive data here and combine the correct database data with the player.
-
14 minutes ago, Cronoss said:
This is what it says
client is only available when you call hms with a triggerServerEvent.
-
50 minutes ago, Cronoss said:
I don't know really how to make it work
Like the code below.
I have put the bandwidth limit very low so that you can see the transfer status in action. Just make sure you are the only player in the server.
local playerLatentHandles = {} local bandwidthLimit = 100 -- 104857600 function hms(x,y,z) triggerLatentClientEvent("mirarA", bandwidthLimit, false, client, x,y,z) -- Get the current handle local handles = getLatentEventHandles(client) local currentHandle = handles[#handles] playerLatentHandles[client] = currentHandle end addEvent('mirarPS', true) addEventHandler('mirarPS', root, hmc) -- Testing: setTimer(function () local player = getRandomPlayer() local currentHandle = playerLatentHandles[player] if currentHandle then local status = getLatentEventStatus( player, currentHandle) iprint(player, status) end end, 500, 0)
I did fixed a bug just a sec ago.
-
35 minutes ago, SinaAmp said:
local Thirst = triggerServerEvent("onSendData", resourceRoot, Thirst) -- ***this***
triggerServerEvent is unable to receive data.
If you take a look at the syntax of that function, you will see that it only returns a boolean(true/false):
https://wiki.multitheftauto.com/wiki/TriggerServerEvent
You can make it possible using this library, but that wouldn't create a solid system. The server should be in charge of the hunger and Thirst values.
What you want is the following:
Server
- A timer (or multiple timers)
- This one gets the Hunger and Thirst
- Updates the Hunger and Thirst (-1) according to your needs.
- Sets the health or kills the player.
- triggerClientEvent (or elementdata with https://wiki.multitheftauto.com/wiki/AddElementDataSubscriber + setElementData [syncMode is "subscribe"])
Client
- Just updates the UI to show the player his hunger and thirst values.
-
1
-
1 hour ago, stscripter said:
I've been trying to use setSoundPosition for a long time, this happens when I use remote links in playSound3D.
And if you use this event?
https://wiki.multitheftauto.com/wiki/OnClientSoundFinishedDownload
-
53 minutes ago, Cronoss said:
Do you mean using that in Client-side or something else?
At the side the triggerClient/ServerEvent is locaties.
53 minutes ago, Cronoss said:debug-script doesn't send me anything but I'm not sure if this works
The debug console only shows you errors, warnings by default.
If you want more information than that. You will have to add debug lines. (iprint) Those lines will show up as soon as the code execute them. If they are not shown up while they should, that means that there is a mistake before them. If you keep moving them forwards/backwards, you will eventually find the location of the problem. Between showing up and not showing up, is the problem.
iprint("A") if false then --[[ <<<< B not is showing up? And A is? Then here is the problem ]] iprint("B") end
They are also handy to debug variables, which are often containing incorrect values when there is a bug.
-
9 hours ago, Cronoss said:
, is it gonna be laggy for other players or something like that if I increase the bandwidth?
Wiki:
except the transmission rate of the data contained in the arguments can be limited and other network traffic is not blocked while the data is being transferred.
It does 2 things:
- It can be limited
- It does not block while transferring.
If you increase the bandwidth to max 100 MB: 100*1024*1024
You basically undo the first thing. That is fine if you only send a little bit of data.
What might lag for some players is the head movement. Which is caused by the non-block transfer thing.
- If the player his download is not fast enough, there will be a delay. But there will be no/little lag created for other things, like remote-player movement. (Remote-players = other player elements than yourself in your game)
- And if the player download is not fast enough and can't keep up. It will stack all those latent events in a queue, which only gets longer.
If you are going to use this function, then I recommend to use getLatentEventStatus for each player to check if the player receives the data. If yes, then send the next update.
-
1
-
-
2 hours ago, SinaAmp said:
setTimer(checkThirst, 60000, 0)
This update rate is fine, unless you have about/more than ~40 players in your server.
Fix for that:
Client (set Thirst with sync disabled)
Thirst = Thirst - 1 setElementData(localPlayer, "Thirst", Thirst, false)
+
https://wiki.multitheftauto.com/wiki/TriggerServerEvent
(https://wiki.multitheftauto.com/wiki/TriggerLatentServerEvent)
+
Server (set Thirst with sync disabled)setElementData(client, "Thirst", Thirst, false)
-
1
-
Getting an error even after using loadstring()
in Scripting
Posted
Yup, you can.