Forum

> > CS2D > Scripts > Save Image
Forums overviewCS2D overview Scripts overviewLog in to reply

English Save Image

5 replies
To the start Previous 1 Next To the start

old Save Image

_Vava_
User Off Offline

Quote
Hello, everyone
I'm making a new RolePlay Script, and now i'm at Car system i want to save Car's in a file.
1
2
3
Car ID = 0 for player "X"
Car ID = 1 for "Name of the player or USGN who buy the car"
Car ID = 2 for "Name of the player or USGN who buy the car

so my question is ,How to create an image and give it a specific ID, which will be saved in a file at the same time with the name of the person.

I wont also to set the Image like a Wall so that other player and other Car's can't go through it.

I tried but unfortunately I am a beginner in LUA, can some one give me a key how to do it, or simply give me the code to advance in my script?
edited 1×, last 23.07.18 10:18:42 pm

old Re: Save Image

Bowlinghead
User Off Offline

Quote
You gotta start to think in arrays.
1
2
3
4
5
6
7
8
9
playerCars = {}

function addCar(carid, playerid)
	playerCars[playerid] = carid
end

function getCar(playerid)
	return playerCars[playerid]
end
There are good save/load scripts in the archive, you better take a look how they handle the player data.

The name of a person is not a good idea though, cuz the playerid/ usgnid is unique and easier to save.

old Re: Save Image

_Vava_
User Off Offline

Quote
I managed to save each ID of a car with the USGN of a player

1
2
3
local file = io.open ("sys/lua/test/"..playerCars[id]..".txt", "w+")
file:write (x.. " "..y.." " .. player (id, "usgn"))
file:close ()

(X and Y is player(id,"x") and player(id,"y").... i saved them for another idea)


I have another idea is that it is possible to save the cars spawn even if the player disconnected

or if i reboot server, or something like that
edited 4×, last 24.07.18 12:11:32 pm

old Re: Save Image

Devil-Thanh
GAME BANNED Off Offline

Quote
Firstly, remove the car remove function when a player disconnected.
Then you need a car autoupdate function per minute and add load function when the server starts.


Remember to make cars separate to players. I mean cars will contain owner usgnid, not players hold car id

old Re: Save Image

_Vava_
User Off Offline

Quote
@user Devil-Thanh:
I didn't understand you when you said Remove the car remove function
And for the car load function i done it, but witch hook do i need to use?

old Re: Save Image

Devil-Thanh
GAME BANNED Off Offline

Quote
Here is the machenics:
• Create Cars array to hold car object
• Create cars contains: owner usgnid, x, y, img id, fuel, bla bla..
• Create cars load function and trigger it when server start.
• Create cars save function which will save cars stats and trigger it every minute for auto save and trigger it right before you CLOSE the server.
• Spawn or teleport the car when players call it. Dont remove it!
> So when a player disconnects his car will still there.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview