Problem in the code..

What the problem in this code? its not working,its not priniting the date

[editline]14th July 2011[/editline]



AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )


function GM:Initialize()
require("tmysql");

if (tmysql) then
Msg("done!
");
else
Msg("failed!
");
end

--if isDedicatedServer() then
tmysql.initialize("db4free.net", "mydatabase", "1111111", "mydatabase", 3306, 2, 2) 
--else
--tmysql.initialize("127.0.0.1", "game", "game", "pd", 3306, 2, 2) // CHANGE THIS LINE
--end
end 

function LoadPlayerProfile ( Player )

tmysql.query("SELECT `steamid`, `cash`, `kills` ,`ammo_pistol`, `ammo_rifle`, `ammo_shotgun` , `xp` , `power` FROM `users` WHERE `id`='" .. Player:SteamID() .. "'", function ( PlayerStats )
if (!PlayerInfo || !PlayerInfo[1]) then
tmysql.query("INSERT INTO `users` (`steamid`, `cash`, `kills` ,`ammo_pistol`, `ammo_rifle`, `ammo_shotgun` , `xp` , `power`) VALUES ('" .. Player:SteamID() .. "', '500', '0', '10' , '10' , '10' , '0' , '0')", function ( )
--GAMEMODE.LoadPlayerProfile(Player);
end);
return;
end

Player:GiveAmmo(tonumber(PlayerStats[1][4]), 'pistol');
Player:GiveAmmo(tonumber(PlayerStats[1][5]), 'smg1');
Player:GiveAmmo(tonumber(PlayerStats[1][6]), 'buckshot');


umsg.Start("playerstats", Player)
umsg.Long(tostring(PlayerStats[1][3])); // Kills
umsg.Long(tonumber(PlayerStats[1][2])); // Cash
umsg.Long(tonumber(PlayerStats[1][7])); // Player XP
umsg.Long(tonumber(PlayerStats[1][8])); // Player Power/Ab
umsg.End();

end);
end
concommand.Add('lp', LoadPlayerProfile);

ClientSide

usermessage.Hook("playerstats", function(msg)
Stats = msg:ReadLong()
print(Stats)
end)


Please wrap lua code in [lua] tags instead of


, it makes it easier to read. Also, did the console print any errors? If so, paste them here.

The clientside code should be:
[lua]usermessage.Hook("playerstats", function(msg)
   local stats = {
      kills = msg:ReadLong(),
      cash = msg:ReadLong(),
      plyxp = msg:ReadLong(),
      plypower = msg:ReadLong()
   }
   PrintTable(stats)
end)[/lua]

ok i will try this code.

edit:

when i run the command “lp” it didnt do anything.
no errors.

by the way its didnt insert the data to the sql server.

help please?

someone please help?

someone please help?

bump

4 Bumps Within 48 Hours.

Be patient.

Your args for concommand.add are wrong

Edit:

my bad though player was last

are you sure LoadPlayerProfile is even being called?

yes, i dont understand why this code still not working…

Why are you trying to call everything inside the function GM:Initialize() lol.

why not?

When using usermessages, i dont think you can ignore any of them. say if you send a number and a string, you need to read them both, even if you dont use them.

can you give me example? , by the way its didnt insert the data to the sql server.
tnx

bump

bump :smiley: please guys help me!

guys help??


(User was banned for this post ("Stop bumping. Seriously. Be patient." - mahalis))

First thing you need to do is to check your tmysql functions. Test them in another script or something, see if they are actually writing to/reading from the database.

Just A Useful Tip Here.
For The Ammo Do This, Dont Use 3 Columns:
[lua]function LayoutAmmo(pistol, shotgun, rifle)
pistol = pistol or 0
shotgun = shotgun or 0
rifle = rifle or 0
return tostring(pistol)…";"…tostring(shotgun)…";"…tostring(rifle)
end

function ReturnAmmo(string)
local tab = string.Explode(";", string)
return tab[1],tab[2],tab[3],tab
end[/lua]

Yes i gave him a basic script cause he wont know how to make it himself.

You’re sending a string as a long

ok, but the data still don’t insert to the database you have some idea?