Forum

> > CS2D > Scripts > Super Hero Load System
Forums overviewCS2D overview Scripts overviewLog in to reply

English Super Hero Load System

7 replies
To the start Previous 1 Next To the start

old Super Hero Load System

_Yank
User Off Offline

Quote
Grettings folks. Im here to ask your help for a script which im not able to do. I know the way, but dont know how to do it.
I made a script which saves the heroes in super hero script. What it exactly does is write the player heroes in a file with his USGN. Something Like this :
1
2
3
4
5
6
7
8
9
10
11
12
13
function initArray(m)
	local initArray = {}
	for i = 1, m do
		initArray[i] = 0
	end
	return initArray
end

heroes_name = {"Hulk","Flash","Spiderman"}
heroes = initArray(32*3) -- 32 is the max players and 3 is the number of heroes which exists.
Then when the player with usgn 94235 sellects the Flash hero it will write the following in 94235.cfg :
heroes[3 * id + 2 ]=1 
3 is number of heroes, id is the id of player and 2 is the hero which player select. The 2nd one, flash.

Then what i want to do is a type of dofile which loads the id.
1
2
3
4
5
6
7
Imagine that i join. My usgn is 94235.
addhook("join","loadheroes")
function loadheroes(id)
dofile("sys/lua/superhero/saves/"..player(id,"usgn")..".cfg")
end
It will do the file called 94235.cfg which actually contains this :
heroes[3 * id + 2]=1
It will load the heroes in a simple way
But the problem is that the id parameter in the file will not work. Then my question is if there's a way to read something and execute it but with id parameter. In this case the id must be the id of who join.

Anyway thanks for reading.

old Re: Super Hero Load System

VADemon
User Off Offline

Quote
Ok dude, I tried to answer twice, but your f* table in the save file is so disappointing that I don't even understand how you thought that could work. If you want to save player's current hero then save just /one/ number (hero's ID), read the first line and execute a loading function with that value. In case I understood you wrong (once again) ... well idk.

old Re: Super Hero Load System

VaiN
User Off Offline

Quote
right idea, but the wrong approach. If you want to load table data you should be using the loadfile() function instead of dofile()

data should be something like:
1
2
3
return {
	-- data here
}

then to load it you use the Lua loadfile() function like:
1
2
3
4
5
6
7
8
function load(usgn)
    local data, err = loadfile("path/to/data/" .. usgn .. ".cfg")
    if err then
        return nil,err
    else
        return data()
    end
end

the loadfile() function returns a function, so you have to call it or return it's result. this will give you a table (or nil), then you can just use a table for all in-game players' data
1
playerdata[id] = load(usgn)

if all you need is a single integer per player, then you could just store all player data in a single Lua table, but might as well store rank and other stuff with it in a separate file anyway, such as permissions or ranks..

old Re: Super Hero Load System

_Yank
User Off Offline

Quote
I didnt understand you at all. Sorry, i know that is quite annoying but my lua knowledge didnt hit that point yet. I dont know how the loadfile function works, is there a way that you can explain exactly what it does?

old Re: Super Hero Load System

TopNotch
User Off Offline

Quote
user _Yank has written
I didnt understand you at all. Sorry, i know that is quite annoying but my lua knowledge didnt hit that point yet. I dont know how the loadfile function works, is there a way that you can explain exactly what it does?

It's just loadfile ([filename]), as user VaiN has shown.

old Re: Super Hero Load System

DannY-PhantoM
User Off Offline

Quote
and if you add your forum for this and it no work for you why you dont say for user the trying for ur script?
like the file hc admin script ? and im so good for trying script i tryed hc and them no work and me no say this forum are good, and them is no working
edited 1×, last 19.08.13 10:27:34 pm
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview