Raised This Month: $ Target: $400
 0% 

Key Values File Not Created!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sharpie_LaBeouf
Member
Join Date: Apr 2016
Old 04-22-2016 , 22:48   Key Values File Not Created!
Reply With Quote #1

For some reason when writing my plugin in Source Pawn, the KeyValues file is not being created! This is my code:

Code:
static String:cpPath[PLATFORM_MAX_PATH];

public OnPluginStart()
{
	CreateDirectory("addons/sourcemod/data/playerinfo", 511);
	BuildPath(Path_SM, cpPath, sizeof(cpPath), "data/playerinfo/checkPoints.txt");
}

public cpMenuCallBack(Handle:menu3,MenuAction:action, Client, Position)
{
	if(action == MenuAction_Select)
	{
		PrintToChat(Client, cpPath);
		new String:Item[20];
		GetMenuItem(menu3, Position, Item, sizeof(Item));
		DisplayMenu(cpMenu,Client,MENU_TIME_FOREVER);
		
		new Handle:cpDB = CreateKeyValues("CheckPoints");
		
		decl String:steamID[30];
		GetClientAuthString(Client, steamID, sizeof(steamID));
		
		if(StrEqual(Item,"saveCP"))
		{
			new Float:tempMapLoc[3];
			new Float:tempMapAng[3];
			new String:tl1[20], String:tl2[20], String:tl3[20], String:ta1[20], String:ta2[20], String:ta3[20];
		
			GetClientAbsOrigin(Client, tempMapLoc);
			GetClientAbsAngles(Client, tempMapAng);
			
			FloatToString(tempMapLoc[0], tl1, sizeof(tl1));
			FloatToString(tempMapLoc[1], tl2, sizeof(tl2));
			FloatToString(tempMapLoc[2], tl3, sizeof(tl3));
			FloatToString(tempMapAng[0], ta1, sizeof(ta1));
			FloatToString(tempMapAng[1], ta2, sizeof(ta2));
			FloatToString(tempMapAng[2], ta3, sizeof(ta3));
			
			FileToKeyValues(cpDB, cpPath);
			
			if(KvJumpToKey(cpDB, steamID, true)){
				KvSetString(cpDB, "lx", tl1);
				KvSetString(cpDB, "lz", tl2);
				KvSetString(cpDB, "ly", tl3);
				KvSetString(cpDB, "ax", ta1);
				KvSetString(cpDB, "az", ta2);
				KvSetString(cpDB, "ay", ta3);
				PrintToChat(Client, "[GetRightMate] You Saved Your Checkpoint!");
			}else{
				PrintToChat(Client, "[GetRightMate] Saving Your Checkpoint Failed!");
			}
		}else if(StrEqual(Item,"loadCP")){
		
			FileToKeyValues(cpDB, cpPath);
			
			if(KvJumpToKey(cpDB, steamID, true))
			{
				new String:l1[MAX_NAME_LENGTH], String:l2[MAX_NAME_LENGTH], String:l3[MAX_NAME_LENGTH];
				new String:a1[MAX_NAME_LENGTH], String:a2[MAX_NAME_LENGTH], String:a3[MAX_NAME_LENGTH];
				
				KvGetString(cpDB, "lx", l1, sizeof(l1), "NULL");
				KvGetString(cpDB, "lz", l2, sizeof(l2), "NULL");
				KvGetString(cpDB, "ly", l3, sizeof(l3), "NULL");
				KvGetString(cpDB, "ax", a1, sizeof(a1), "NULL");
				KvGetString(cpDB, "az", a2, sizeof(a2), "NULL");
				KvGetString(cpDB, "ay", a3, sizeof(a3), "NULL");
				
				if(StrEqual(l1, "NULL",false) && StrEqual(l2, "NULL",false) && StrEqual(l3, "NULL",false))
				{
					PrintToChat(Client, "[GetRightMate] No Location Saved! Save a Location To Use This Feature!");
				} else{
					new Float:location[3];
					new Float:angle[3];
					new Float:vel[3];
					location[0] = StringToFloat(l1);
					location[1] = StringToFloat(l2);
					location[2] = StringToFloat(l3);
					vel[0] = 0.00;
					vel[1] = 0.00;
					vel[2] = 0.00;
					angle[0] = StringToFloat(a1);
					angle[1] = StringToFloat(a2);
					angle[2] = StringToFloat(a3);
					
					TeleportEntity(Client, location, angle, vel);
					PrintToChat(Client, "[GetRightMate] Loaded CheckPoint!");
					
					location[0] = 0.00;
					location[1] = 0.00;
					location[2] = 0.00;
					vel[0] = 0.00;
					vel[1] = 0.00;
					vel[2] = 0.00;
					angle[0] = 0.00;
					angle[1] = 0.00;
					angle[2] = 0.00;
				}
				
			}
		
		}
		CloseHandle(cpDB);
	}
}
There is no Key Values file being created which is really poo Can someone please help me find out why my file is not being created?
Sharpie_LaBeouf is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 04-23-2016 , 01:17   Re: Key Values File Not Created!
Reply With Quote #2

Are you saving it?

https://sm.alliedmods.net/new-api/ke...eyValuesToFile
__________________

Last edited by ddhoward; 04-23-2016 at 01:17.
ddhoward is offline
Sharpie_LaBeouf
Member
Join Date: Apr 2016
Old 04-23-2016 , 01:45   Re: Key Values File Not Created!
Reply With Quote #3

Quote:
Originally Posted by ddhoward View Post
Ok so after I have done everything I do

Code:
KeyValuesToFile(cpDB,cpPath);
Sharpie_LaBeouf is offline
Grey83
Veteran Member
Join Date: Dec 2014
Location: Ukraine
Old 04-23-2016 , 06:46   Re: Key Values File Not Created!
Reply With Quote #4

Quote:
Originally Posted by Sharpie_LaBeouf View Post
Ok so after I have done everything I do
PHP Code:
KeyValuesToFile(cpDB,cpPath); 
but You must do it before
PHP Code:
CloseHandle(cpDB); 
__________________
Grey83 is offline
Sharpie_LaBeouf
Member
Join Date: Apr 2016
Old 04-23-2016 , 06:57   Re: Key Values File Not Created!
Reply With Quote #5

Also when I go to retrieve this information from the file, I receive nothing from it. Do I have to use a different method such as FileToKeyValues()?
Sharpie_LaBeouf is offline
Sharpie_LaBeouf
Member
Join Date: Apr 2016
Old 04-23-2016 , 09:56   Re: Key Values File Not Created!
Reply With Quote #6

When one client makes a Key Value and Saves their position it creates it fine and they can successfully teleport to it. But when someone else on the server saves a checkpoint, it overwrites the first players and saves the second players whilst deleting the first players save. Its not creating a new key value, it is simply overwriting the first one. How can I fix this? this is my code now:

Code:
public saveOrigin(client)
{
	new Handle:cpDB = CreateKeyValues("CheckPoints");
	new String:steamID[30];
	GetClientAuthId(client, AuthId_Steam3,steamID, sizeof(steamID));
	
	new Float:tempMapLoc[3];
	new Float:tempMapAng[3];
	new String:tl1[20], String:tl2[20], String:tl3[20], String:ta1[20], String:ta2[20], String:ta3[20];

	GetClientAbsOrigin(client, tempMapLoc);
	GetClientAbsAngles(client, tempMapAng);
	
	FloatToString(tempMapLoc[0], tl1, sizeof(tl1));
	FloatToString(tempMapLoc[1], tl2, sizeof(tl2));
	FloatToString(tempMapLoc[2], tl3, sizeof(tl3));
	FloatToString(tempMapAng[0], ta1, sizeof(ta1));
	FloatToString(tempMapAng[1], ta2, sizeof(ta2));
	FloatToString(tempMapAng[2], ta3, sizeof(ta3));
	
	if(KvJumpToKey(cpDB, steamID, true)){
		KvSetString(cpDB, "lx", tl1);
		KvSetString(cpDB, "lz", tl2);
		KvSetString(cpDB, "ly", tl3);
		KvSetString(cpDB, "ax", ta1);
		KvSetString(cpDB, "az", ta2);
		KvSetString(cpDB, "ay", ta3);
		PrintToChat(client, "[GetRightMate] You Saved Your Checkpoint!");
		
		KvRewind(cpDB);
		KeyValuesToFile(cpDB, cpPath);
		CloseHandle(cpDB);
	}else{
		PrintToChat(client, "[GetRightMate] Saving Your Checkpoint Failed!");
	}
}

public loadOrigin(client)
{
	new Handle:cpDB = CreateKeyValues("CheckPoints");
	new String:steamID[30];
	GetClientAuthId(client, AuthId_Steam3,steamID, sizeof(steamID));
	FileToKeyValues(cpDB, cpPath);
	
	new String:l1[MAX_NAME_LENGTH], String:l2[MAX_NAME_LENGTH], String:l3[MAX_NAME_LENGTH];
	new String:a1[MAX_NAME_LENGTH], String:a2[MAX_NAME_LENGTH], String:a3[MAX_NAME_LENGTH];
	
	if(KvJumpToKey(cpDB, steamID, true))
	{
		KvGetString(cpDB, "lx", l1, sizeof(l1), "NULL");
		KvGetString(cpDB, "lz", l2, sizeof(l2), "NULL");
		KvGetString(cpDB, "ly", l3, sizeof(l3), "NULL");
		KvGetString(cpDB, "ax", a1, sizeof(a1), "NULL");
		KvGetString(cpDB, "az", a2, sizeof(a2), "NULL");
		KvGetString(cpDB, "ay", a3, sizeof(a3), "NULL");
		
		if(StrEqual(l1, "NULL",false) && StrEqual(l2, "NULL",false) && StrEqual(l3, "NULL",false))
		{
			PrintToChat(client, "[GetRightMate] No Location Saved!");
		} else{
			new Float:location[3];
			new Float:angle[3];
			new Float:vel[3];
			location[0] = StringToFloat(l1);
			location[1] = StringToFloat(l2);
			location[2] = StringToFloat(l3);
			vel[0] = 0.00;
			vel[1] = 0.00;
			vel[2] = 0.00;
			angle[0] = StringToFloat(a1);
			angle[1] = StringToFloat(a2);
			angle[2] = StringToFloat(a3);
			
			PrintToChat(client, l1);
			PrintToChat(client, l2);
			PrintToChat(client, l3);
			
			TeleportEntity(client, location, angle, vel);
			PrintToChat(client, "[GetRightMate] Loaded CheckPoint!");
			
			location[0] = 0.00;
			location[1] = 0.00;
			location[2] = 0.00;
			vel[0] = 0.00;
			vel[1] = 0.00;
			vel[2] = 0.00;
			angle[0] = 0.00;
			angle[1] = 0.00;
			angle[2] = 0.00;
		}
		
		KvRewind(cpDB);
		CloseHandle(cpDB);
	}
}
Sharpie_LaBeouf is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:55.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode