Jump to content

Client script not executing


R1ddl3

Recommended Posts

I am new in MTA scripting. Created first resource. It's meta:

<meta>
	<script src="vehicle.lua" type="server"/>
	<script src="myClient.lua" type="client"/>
</meta>

Vehicle.lua is working, it's content:

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer) -- get the position of the player
	x = x + 5 -- add 5 units to the x position
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
	-- check if the return value was ''false''
	if (createdVehicle == false) then
		-- if so, output a message to the chatbox, but only to this player.
		outputChatBox("Failed to create vehicle.",thePlayer)
	end
end
addCommandHandler("createvehicle", createVehicleForPlayer)

myClient.lua is not working at all, content:

function escapeMe ( commandName )
	local x, y, z = getElementPosition ( localPlayer ) --Get player's position
	setElementPosition ( localPlayer, x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.
end    
addCommandHandler ( "escape", escapeMe ) --When player types "/escape" in chatbox or "escape" in console

I took this code from example from here https://wiki.multitheftauto.com/wiki/AddCommandHandler

I have completely no idea why client side script is not working at all. I tried different this and nothing works.

MTASA v1.5.9 server

Link to comment
1 hour ago, R1ddl3 said:

I am new in MTA scripting. Created first resource. It's meta:

<meta>
	<script src="vehicle.lua" type="server"/>
	<script src="myClient.lua" type="client"/>
</meta>

Vehicle.lua is working, it's content:

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer) -- get the position of the player
	x = x + 5 -- add 5 units to the x position
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
	-- check if the return value was ''false''
	if (createdVehicle == false) then
		-- if so, output a message to the chatbox, but only to this player.
		outputChatBox("Failed to create vehicle.",thePlayer)
	end
end
addCommandHandler("createvehicle", createVehicleForPlayer)

myClient.lua is not working at all, content:

function escapeMe ( commandName )
	local x, y, z = getElementPosition ( localPlayer ) --Get player's position
	setElementPosition ( localPlayer, x+(math.random(-10,10)), y+(math.random(-10,10)), z+(math.random(1,15)) ) --Move a player randomly to a nearby location. X is current x + a number between -10, 10 and so on.
end    
addCommandHandler ( "escape", escapeMe ) --When player types "/escape" in chatbox or "escape" in console

I took this code from example from here https://wiki.multitheftauto.com/wiki/AddCommandHandler

I have completely no idea why client side script is not working at all. I tried different this and nothing works.

MTASA v1.5.9 server

hello welcome to the forum, i tested your code but there is no problem, can you tell me exactly what problem you are having

Link to comment
Just now, Shady1 said:

hello welcome to the forum, i tested your code but there is no problem, can you tell me exactly what problem you are having

Oh maybe something wrong outside the code. I run mta server, I join my local server and only server side script works. I will try to find a solution. Will post if I find.

Link to comment

Ok, solved. Maybe it is stupid what I did. I added such line in mtaserver.conf:

<resource src="hydra_script" startup="1" protected="0" />

Now it works. Maybe I am a person who didn't read all tutorials, sorry. But without this line server-side script was working and I was expecting client-side should also work. Anywany thanks for help!

Link to comment
6 minutes ago, R1ddl3 said:

Ok, solved. Maybe it is stupid what I did. I added such line in mtaserver.conf:

<resource src="hydra_script" startup="1" protected="0" />

Now it works. Maybe I am a person who didn't read all tutorials, sorry. But without this line server-side script was working and I was expecting client-side should also work. Anywany thanks for help!

I'm glad if your problem is fixed, if you liked my comment you can like my comment

have a nice day

  • Like 1
Link to comment
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...