Attempting to create a very simple teleportation script for fun


#1

I’m trying to use the code from this because of the command activating something.
I figured because this activated the message in the chat, I could modify it to also teleport the player, but I can’t seem to get it working.

Here are some images of scrapped code that I swapped out for the original stuff from the linked post:
server.lua : https://gyazo.com/451be108d55c3106918d04f5da3119c0
client.lua : https://gyazo.com/913635f37cfdec95b6d469b871612b79

Also sorry if this isn’t the right place to post this, still trying to figure out the forums!
(Also i know in the client.lua picture the teleport code is a comment, just wanted to try get the text to work)


#2

You do not need a server.lua for this. Only client.lua:

RegisterCommand('hospital', function()
    TriggerEvent('Hospital')
end)

#3

What Scott_UK told you is correct, also you are calling the native SetPedCoordsKeepVehicle(...) wrong.

Natives don’t have to be called with TriggerEvent(...).

You just call them how they are.

Example:

Clientsided Script

RegisterCommand('hospital', function(Source, Arguments, RawCommand)
	if #Arguments == 3 then
		if IsPedInAnyVehicle(PlayerPedId(), 0) and (GetPedInVehicleSeat(GetVehiclePedIsIn(PlayerPedId(), 0), -1) == PlayerPedId()) then
			SetPedCoordsKeepVehicle(PlayerPedId(), Arguments[1], Arguments[2], Arguments[3])
		else
			SetEntityCoords(PlayerPedId(), Arguments[1], Arguments[2], Arguments[3])
		end
		TriggerEvent('chatMessage', '', {0, 255, 0}, 'Teleported successfully!')
	else
		TriggerEvent('chatMessage', '', {255, 0, 0}, 'Argument count mismatch! Expected 3, got ' .. #Arguments .. '!')
	end
end)

#5

Forgive me for not understanding this, but I don’t understand the arguments within the code, how do those work? I tried entering the xyz’s into them accordingly but that didn’t work, and how would I define the action(‘Hospital’) within Scott’s code? I get the main idea, its just how to fill in the information for the command and how to execute it is what’s tying me up right now.


#6

I dont know lua but c# but from my understanding you have to call the hospital command thru ingame chat like: /hospital

and pass the coordinates as arguments.


#7

I got the /hospital part down, that part is working.


#8

Then what is it you don’t understand


#9

Client.lua:

Server.lua


I’ll type in the game chat /showid and then it proceeds to spew out a long error message in the chat.
give me a moment and ill grab a screenshot