What did I do wrong?
[lua]
PointMod.Items = { }
PointMod.Items[1] = { "SMG1", "Spawn with an SMG1 Weapon!", "models/weapons/w_smg1.mdl", "smg1", 60, "PlayerLoadout", function( ply )
ply:Give( "weapon_smg1" )
end }
PointMod.Items[2] = { "HL2 Pistol", "Spawn with a Half-Life 2 Pistol!", "models/weapons/W_pistol.mdl", "pistol", 30, "PlayerLoadout", function( ply )
ply:Give( "weapon_pistol" )
end }
require("datastream")
function CheckPlayerPoints(pl, handler, id, encoded, decoded)
print( "Received data on server" );
if tonumber(pl:GetPData( "Points" )) > 100 then
PointMod.Items[3] = { "Crowbar", "Spawn with a Crowbar!", "models/weapons/w_crowbar.mdl", "crowbar", 40, "PlayerLoadout", function( ply )ply:Give( "weapon_crowbar" )
end }
PointMod.Items[4] = { "Less Damage", "Other people do less damage to you!", "models/props_c17/streetsign004f.mdl", "lessdamage", 250, "ScalePlayerDamage", function( ply, _, dmg ) dmg:ScaleDamage( 0.5 )
end }
PointMod.Items[5] = { "150 HP", "Start off with 150 HP!", "models/props_combine/health_charger001.mdl", "150hp", 100, "PlayerSpawn", function( ply )ply:SetHealth( 150 )
end }
end
end
datastream.Hook( "RecievePoints", CheckPlayerPoints )
if ( SERVER ) then
for k, v in ipairs( PointMod.Items ) do
print( "Adding Hook: " .. v[6] .. " (" .. v[4] .. ")" )
hook.Add( v[6], "PointMod_" .. v[6] .. "_" .. v[4], function( ply, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )
if ply:HasItem( v[4] ) then
return v[7]( ply, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 )
end
return v[8]
end )
end
end
[/lua]
There is something up with the CheckPlayerPoints function. It checks if I have more than 100 points and then it should add those to the table. Had it print it to console and it picks up the correct number of points, way more than 100 yet it still doesn't add the entries.
Halp!
Thanks
Anybody? c'mon guys, please
Mind editing your post and using the [ lua] and [ /lua] tags.
It makes it easier to read.
My bad. I thought the code tags would do the job. All done now :D
Is this the full code?
Nope, this is just the sh.lua from CombineGuru's PointMod. I'll post the full code when I get back from college.
If you want you can get the fullcode over here :
[url]http://www.garrysmod.org/downloads/?a=view&id=97699[/url]
Thanks for the replies guys.
Try adding in some debugging stuff to check where it's going wrong.
Ok screw this! new tactic!
I decided to do this client side, and it's sorta working better. But how do I get a part of a usermessage out into a variable outside of the function?
What it looks like :
[lua]
function RecievedPoints( um )
PlyPoints=um:ReadLong()
return PlyPoints
end
usermessage.Hook("ClientPoints", RecievedPoints)
print(TotalPlyPoints)
[/lua]
Server-side
[lua]
function CheckPlayerPoints(pl, handler, id, encoded, decoded)
print( "Received data on server" );
umsg.Start("ClientPoints",pl)
umsg.Long(pl:GetPData( "Points" ))
umsg.End()
end
[/lua]
It works fine when I print the points within the function but I got to get the points outside into TotalPlyPoints.
Sorry, you need to Log In to post a reply to this thread.